Migrating from xmpp4r to blather - some basic questions

166 views
Skip to first unread message

dara

unread,
Apr 23, 2013, 9:07:37 PM4/23/13
to xmpp-b...@googlegroups.com
I currently use xmpp4r (via xmpp4r-simple) to read IM's in a Selenium test suite. The IM's are generated by browser activity (things I do in my Selenium code). So, my test code roughly looks like:

initialize browser 
initialize xmpp4r-simple object
...
do some browser stuff
...
do something in the browser that I expect to generate an IM:
read received messages from the im object -> verify they are as expected.
[note: a sequential set of steps with a specific point where I want to read the IM]

I'm in the process of upgrading ruby (from Ruby 1.9.1) and I find xmpp4r is broken for me in Ruby 1.9.2 and Ruby 1.9.3 (on Windows). Since xmpp4r appears to be a dead project, I figure I'll upgrade to something still alive. blather seems to be what I should be using.

I have gotten blather working via the example here and I'm able to connect to it and bounce messages back and forth. I'm finding the Event Machine stuff a little confusing. It works in my example code, but I don't quite grok it.

Anyway, what I'd really like to do is be able to initialize a blather client object, have it sitting there in my code, and be able to query it at a specific point in my code to see what IM's it has received. Is that something I can do? I've been trying to do that but with the EventMachine code, but I can't seem to get control of the sequence of events.

I realize a major feature of blather is its ability to do all this stuff asynchronously, and I can see that is really useful in many (probably most) scenarios. My problem is I'm trying to do something in a very specific sequence, and I can't figure out how to control the sequence of events. I have a feeling I'm missing something obvious, but I'm not sure what that is.

Sorry for this very wordy post. I think I mostly just need to be pointed in the right direction.

Thanks!

Ben Langfeld

unread,
Apr 24, 2013, 10:44:18 AM4/24/13
to xmpp-b...@googlegroups.com
You most certainly can do that kind of event inspection:

messages = []
setup 'f...@bar.com', 'baz'
message { |m| messages << m }
EM.run { client.run }

In order to help you any more we're going to have to get a bit more specific.

Regards,
Ben Langfeld


--
You received this message because you are subscribed to the Google Groups "Blather" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xmpp-blather...@googlegroups.com.
To post to this group, send email to xmpp-b...@googlegroups.com.
Visit this group at http://groups.google.com/group/xmpp-blather?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

dara

unread,
Apr 24, 2013, 12:40:39 PM4/24/13
to xmpp-b...@googlegroups.com, b...@langfeld.me
Thank you, Ben. I will start from there and will provide specifics (and actual code) if I have any problems or follow-up questions.

dara

unread,
May 1, 2013, 7:38:13 PM5/1/13
to xmpp-b...@googlegroups.com, b...@langfeld.me
Ok, I do have a follow-up question. Your help got me most of the way to where I wanted to be.

Please see this snippet of my work in progress.

As written, this code will run an IM client and keep it running until the client receives a message whose body matches the specified text (in this case "stop").

I would like to use this code to check IM's for text content, but also to have a timeout. I.e. I would like my code to time out after, say, 20 seconds if the matching IM text doesn't show up.

It seems to me this might be more of an EventMachine question than a Blather question but I figured I'd ask here first. I'm wondering if there's something built into blather that would allow me to do this, though I have looked around and haven't found anything yet.

Thanks,
-Dara

Ben Langfeld

unread,
May 1, 2013, 7:50:43 PM5/1/13
to dara, xmpp-b...@googlegroups.com
You can do this:

when_ready
do
EM::Timer.new(20) { client.close }
end

Regards,
Ben Langfeld

dara

unread,
May 1, 2013, 8:02:54 PM5/1/13
to xmpp-b...@googlegroups.com, dara, b...@langfeld.me
Thank you, Ben! Thanks for being so responsive to my questions. EventMachine seems like a powerful tool, but, at the same time, it's a bit of a challenge to wrap your mind around it when you first encounter it.

For the benefit of anyone in the future looking at this and trying to use my code snippet, to complete it, you want something like this.

dara

unread,
May 8, 2013, 4:59:15 PM5/8/13
to xmpp-b...@googlegroups.com, b...@langfeld.me
I'm having trouble figuring out how to get this to work with non-blather code.

I want to start a blather client, and then trigger IM's (via Selenium code that generates IM's from browser activity) and read those IM's. See my example code here: http://pastie.org/7819776

In my example I put some placeholder "puts" calls where I want to put the code that generates IM's. I can't figure out how to get that code to wait until the blather client is connected before making those calls.

Perhaps I'm doing it wrong or misunderstand something.

Ben Langfeld

unread,
May 8, 2013, 5:32:33 PM5/8/13
to xmpp-b...@googlegroups.com
@client.register_handler :ready do
      puts "#{Time.new}: Ready to receive IM's."

Regards,
Ben Langfeld
Reply all
Reply to author
Forward
0 new messages