Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FireWatir and jQuery

after using this excellent peace of software called FireWatir, I wonder if there is a way to integrate jQuery-selector-magic to my test.

My first attempt is to use firewatir's js_eval() method like this

require 'rubygems'
require 'firewatir'
f = FireWatir::Firefox.new
f.js_eval("alert(42);")

The only thing I get is a

JsshSocket::JSReferenceError: alert is not defined

which is kind of strange because other expressions like

f.js_eval("document.location.toString();")

Work like a charm!

Anyone with a hint?

Thanks and greets,

Joe

like image 685
xijo Avatar asked Dec 20 '25 04:12

xijo


2 Answers

If you want to use it like you would normally with a $ you need to wrap it in a function which will run it on the context of the widows document.

var win = new getWindows()[0].content;
var doc = browser.contentDocument;

$ = function(selector) {

  win.content.jQuery(selector, doc);

}

chicago web design

like image 177
brad Avatar answered Dec 22 '25 18:12

brad


Okay folks,

i got jQuery working with a lot of researching and I hope this will be help you out if you have similar problems:

firefox.js_eval("var target = getWindows()[0]; target.content.jQuery('#selector').toggle()")

What i had to do was to select the window I am working in explicitly and within its content jQuery is available and one is able to use all of its awesomeness! ;)

Greetings Joe

like image 43
xijo Avatar answered Dec 22 '25 19:12

xijo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!