-
Notifications
You must be signed in to change notification settings - Fork 38
FAQ
Either instantiate the Browser with
browser = Celerity::Browser.new(:log_level => :off)
or set it later
browser.log_level = :off
See also the full list of supported options.
To stay compatible with Watir, locating elements by :index or fetching elements from ElementCollection subclasses is 1-indexed.
To change this to zero-index, versions >= 0.0.6.10 lets you set
Celerity.index_offset = 0
Celerity encodes all strings as UTF-8, so if you save your test scripts as UTF-8 everything should work fine.
To make Watir use UTF-8, add this line to your test suite (WTR-219):
WIN32OLE.codepage = WIN32OLE::CP_UTF8
See Viewers.
See Ajax.
Use ClickableElement#click_and_attach. This method returns a new browser instance with the page returned when clicking the element.
Example:
popup_browser = browser.link(:id, 'popup').click_and_attach
# do something with popup_browser
popup_browser.close
# continue working with browser
HtmlUnit provides a listener interface for alert() and confirm() calls.
To access this with Celerity, you can use:
browser.add_listener(:alert) { |page, message| ... }
browser.add_listener(:confirm) { |page, message| ... }
If the value returned from the :confirm block is false, the “Cancel” button will be clicked.
You can also use Browser#confirm for easier interaction:
browser.confirm(false) do
# trigger confirm() call
end
If you have a link or button that returns a document you normally wouldn’t view in a browser, you can use ClickableElement#download to get an IO object instead.
browser.link(:id, 'pdf').download #=> #<IO:0x11ce78c>
This is a common mistake made when visiting a list of links:
links = browser.links.select { |link| link.href =~ /some_string/ }
links.each do |link|
link.click
# do some work
end
The «links» variable contains a list of Link objects, and each link was located on the page when Link#href was called. When the page is changed, the Link object might be in an invalid state.
Even though the above code might work fine in some situations, the safest way of iterating over links is storing a way of locating the link rather than the Link object itself, and call Browser#back before clicking the next link in the list:
hrefs = browser.links.map { |link| link.href if link.href =~ /some_string/ }.compact
hrefs.each do |href|
browser.link(:url, href).click
# do some work
browser.back
end
Celerity::Browser.new(:secure_ssl => false)
This is caused by a JRuby bug in versions pre-1.2.
Update to JRuby >= 1.2 to get rid of this problem.
This is caused by a JRuby bug, and only appears when running off jruby-complete.jar on Celerity version <= 0.0.6.15. Until the bug is fixed, you can solve the problem by doing a proper install of JRuby, updating Celerity or adding this:
require "thread.rb"