This page is obsolete. It is being retained for archival purposes. It may document extensions or features that are obsolete and/or no longer supported. Do not rely on the information here being up-to-date.
See Selenium instead.
Watir in particular (even before Selenium existed) was always intended to be used interactively as well as batch-wise. Use irb, the interactive Ruby shell:
$ irb 2.0.0p247 :001 > require 'watir-webdriver' => true 2.0.0p247 :002 > browser = Watir::Browser.new :firefox => #<Watir::Browser:0x..fac3245de232edb40 url="about:blank" title=""> 2.0.0p247 :003 > browser.goto('http://en.wikipedia.beta.wmflabs.org/wiki/Talk:Flow_QA') => "http://en.wikipedia.beta.wmflabs.org/wiki/Talk:Flow_QA"
If you get "Server not found" the first time you run browser.goto(), try repeating the command.
At this point your browser has the page open and you can zoom around in it in some really spectacular ways. A place to start looking is https://github.com/watir/watir/wiki/Using-IRB, but there is a lot more available.
Unfortunately you can't do this with the mediawiki_selenium gem that handles our MEDIAWIKI_XXX and Sauce Labs variables. marxarelli comments
- Some of the global cucumber hooks in mediawiki_selenium make it unfriendly to irb (or inclusion outside the context of cucumber). I'd recommend pry for now.
Breaking into a debugger
First, try using the _element suffix, rather than relying on the implicit action if you omit _element.
echo 'gem "pry-debugger"' >> Gemfile bundle install
(Replace "pry-debugger" with
pry-byebug if you're using Ruby 2.x)
At the top of the step definition file add:
At the line where you want to break add:
Then, run the tests form the command line as normal. It should put you into a pry shell at the point where you put binding.pry.
You may have to do s/step for a while, but eventually you can see how it actually tries to find the element, and there will be a located field showing whether it found it. To avoid stepping through on(MyPage) (if you're not using a page block), you can do:
page = on(MyPage) binding.pry page.some_element
Any valid Ruby expression can be evaluated directly in the shell, including intermediate assignment of local variables like the one just mentioned.
pry> page = on(MyPage) => ... pry> page.some_element.visible? => true
You can even define or redefine elements of the page-object class to test whether they can be located.
pry> MyPage.div("someother", id: "some-other") => ... pry> page = on(MyPage) => ... pry> page.someother_element.visible? => true
- How to get irb to load a PageObject from features/support/pages
- How to get irb to run the cucumber command line.
- Suggestions requiring ruby-debug such as http://www.agileforall.com/2011/12/cucumber-tip-irb-from-inside-a-step-definition/ failed with
ERROR: Error installing ruby-debug: ERROR: Failed to build gem native extension. /home/spage/.rvm/rubies/ruby-2.1.0/bin/ruby extconf.rb Can't handle 1.9.x yet