watir throws JavascriptError when using parent method to locate element - watir

Take Github for example, code like these:
require 'rubygems'
require 'watir'
require 'watir-webdriver'
b = Watir::Browser.new :firefox
b.goto "https://github.com/about"
puts b.div(:class => "column one-half").present?
puts b.div(:class => "column one-half").parent.text
Got these output:
[remote server] https://github.com/about line 68 > Function:17:in `H': a is undefined (Selenium::WebDriver::Error::JavascriptError)
from [remote server] https://github.com/about line 68 > Function:17:in `anonymous/</<'
from [remote server] https://github.com/about line 68 > Function:14:in `anonymous/<'
from [remote server] https://github.com/about line 68 > Function:14:in `anonymous'
from [remote server] https://github.com/about:68:in `handleEvaluateEvent'
from my_path/gems/ruby-2.1.5/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok'
from my_path/gems/ruby-2.1.5/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/response.rb:15:in `initialize'
from my_path/gems/ruby-2.1.5/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/http/common.rb:59:in `new'
from my_path/gems/ruby-2.1.5/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/http/common.rb:59:in `create_response'
from my_path/gems/ruby-2.1.5/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/http/default.rb:66:in `request'
from my_path/gems/ruby-2.1.5/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
from my_path/gems/ruby-2.1.5/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/bridge.rb:640:in `raw_execute'
from my_path/gems/ruby-2.1.5/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/bridge.rb:618:in `execute'
from my_path/gems/ruby-2.1.5/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/bridge.rb:339:in `executeScript'
from my_path/gems/ruby-2.1.5/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/common/driver.rb:193:in `execute_script'
from my_path/gems/ruby-2.1.5/gems/watir-webdriver-0.6.11/lib/watir-webdriver/atoms.rb:20:in `execute_atom'
from my_path/gems/ruby-2.1.5/gems/watir-webdriver-0.6.11/lib/watir-webdriver/elements/element.rb:373:in `parent'
from t.rb:9:in `<main>'
true
Try other sites, got the same result, anyone know why? Thanks

Related

facing ERROR: ArgumentError: wrong number of arguments (given 3, expected 2) ruby 3 aruba

after upgrading ruby from 2.7 to 3.0 to 3.1 I am facing fowling issue while running the cucumber test
Given a local mode chef repo with nodes 'one,two,three' # features/step_definitions/chef-repo.rb:2
Expected `knife client create admin -c config.rb -f admin.pem` to succeed but got non-zero exit status and the following output:
ERROR: ArgumentError: wrong number of arguments (given 3, expected 2)
(RSpec::Expectations::ExpectationNotMetError)
./features/step_definitions/chef-repo.rb:66:in `create_client'
./features/step_definitions/chef-repo.rb:58:in `create_admin'
./features/step_definitions/chef-repo.rb:20:in `block (2 levels) in <top (required)>'
./features/step_definitions/chef-repo.rb:19:in `each'
./features/step_definitions/chef-repo.rb:19:in `/^a local mode chef repo with nodes '(.+?)'(?: with admins '(.+?)')?$/'
features/clean.feature:11:in `a local mode chef repo with nodes 'one,two,three''
And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two' # features/step_definitions/chef-vault.rb:4
Then the vault item 'test/item' should be encrypted for 'one,two' # features/step_definitions/chef-vault.rb:48
And I update the vault item 'test/item' to be encrypted for 'two,three' # features/step_definitions/chef-vault.rb:14
Then the vault item 'test/item' should be encrypted for 'one,two,three'
It's failing under Auba SpawnProcess start command. Tried upgrading and downgrading arbua version 'aruba', '~> 2.0' & gem 'aruba', '0.5.4' nothing working can someone please help me with this?
in chef-repo.rb its failing on run_command_and_stop
def create_client(name, args = nil)
command = "knife client create #{name} -c config.rb -f #{name}.pem"
run_command_and_stop(command, fail_on_error: true)
write_file("#{name}.pem", last_command_started.stdout)
end
here if we step in run_command_and_stop its fails on command.start following code in aruba
def start_command(command)
259: aruba.config.run_before_hook(:command, self, command)
260:
261: in_current_directory do
262: command.start
263: end
264:
=> 265: stop_signal = command.stop_signal
266: aruba.announcer.announce(:stop_signal, command.pid, stop_signal) if stop_signal
267:
268: aruba.config.run_after_hook(:command, self, command)
269: end

file_field().set crashing watir

When using file_field().set, my watir script crahes with a huge stack trace. I'm running on Windows 7 64, using Watir through cucumber. I am using IE10 as my browser.
Here is the beginning of it:
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rautomation-0.13.0/lib/rautomation/adapter/win_32/functions.rb:294:
ruby 1.9.3p545 (2014-02-24) [i386-mingw32]
And here is the end:
c:/Code/trunk/source/cucumber/webapp/lib/cucumber/lcpic/features/step_definition/newbusiness.rb:465:in `block in <top (required)>'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.0.1/lib/watir-classic/element_extensions.rb:19:in `method_missing'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.0.1/lib/watir-classic/dialogs/file_field.rb:34:in `set'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-4.0.1/lib/watir-classic/dialogs/file_field.rb:48:in `set_file_name'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rautomation-0.13.0/lib/rautomation/window.rb:214:in `text_field'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rautomation-0.13.0/lib/rautomation/window.rb:224:in `wait_until_present'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rautomation-0.13.0/lib/rautomation/wait_helper.rb:15:in `wait_until'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rautomation-0.13.0/lib/rautomation/window.rb:224:in `block in wait_until_present'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rautomation-0.13.0/lib/rautomation/window.rb:155:in `present?'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rautomation-0.13.0/lib/rautomation/window.rb:138:in `exists?'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rautomation-0.13.0/lib/rautomation/adapter/win_32/window.rb:90:in `exists?'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rautomation-0.13.0/lib/rautomation/adapter/win_32/window.rb:48:in `hwnd'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rautomation-0.13.0/lib/rautomation/adapter/win_3127.0.0.1 - - [18/Jul/2014 10:11:33] "GET /status?_=1405692621800 HTTP/1.1" 200 15 0.0020
2/functions.rb:140:in `window_hwnd'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rautomation-0.13.0/lib/rautomation/adapter/win_32/functions.rb:294:in `find_hwnd'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rautomation-0.13.0/lib/rautomation/adapter/win_32/functions.rb:294:in `enum_windows'

Poltergeist current_url command is returning page_info hash instead of a URL

Problem
I have an rspec feature test that is using capybara/poltergeist with :js => true and is doing something really simple:
visit borrow_path
click_on "Get Started"
page.should have_content "Create Your Account"
Clicking Get Started takes the user to our sign up page and then poltergeist raises a Timeout Error on the page.should have_content assertion, despite the screenshot of the page confirming that the content is, in fact, on the page.
The error is:
Failure/Error: page.should have_content "Create Your Account"
Capybara::Poltergeist::TimeoutError:
Timed out waiting for response to {"name":"find","args":["xpath","/html"]}. It's possible that this happened because something took a very long time (for example a page load was slow). If so, setting the Poltergeist :timeout option to a higher value will help (see the docs for details). If increasing the timeout does not help, this is probably a bug in Poltergeist - please report it to the issue tracker.
# ./spec/features/borrower/signup_spec
We've tried upping the timeout to 5 minutes, still the same error.
This doesn't happen consistently, every few runs the test will pass.
Details
With that in mind, I turned :debug on in our setup as follows:
Capybara.register_driver :poltergeist do |app|
# use 'page.driver.debug' as a js debugger
# see https://github.com/jonleighton/poltergeist/tree/v1.5.0#remote-debugging-experimental
Capybara::Poltergeist::Driver.new(app, :timeout => 300, :inspector => true, :debug => false, :window_size => [1280, 1400], :js_errors => true)
end
and re-ran the tests. The failed spec's output looks as follows:
{"name"=>"current_url", "args"=>[]}
{"response"=>{"page_id"=>126, "ids"=>[0]}}
An error occurred in an after hook
URI::InvalidURIError: bad URI(is not URI?): {"page_id"=>126, "ids"=>[0]}
occurred at /home/rof/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/uri/common.rb:176:in `split'
{"name"=>"current_url", "args"=>[]}
{"response"=>"http://127.0.0.1:49891/users/sign_up?m=borrower"}
{"name"=>"current_url", "args"=>[]}
{"response"=>"http://127.0.0.1:49891/users/sign_up?m=borrower"}
{"name"=>"body", "args"=>[]}
{"response"=>"http://127.0.0.1:49891/users/sign_up?m=borrower"}
I can't find any hints as to why a call to current_url is returning the page_id hash instead of a URL, but this actually breaks all subsequent feature tests and causes find to always return true:
{"name"=>"find", "args"=>["xpath","/html"]}
{"response"=>"true"}
Which causes this exception on all subsequent tests (whether they're tagged :js => true or not):
Failure/Error: Unable to find matching line from backtrace
NoMethodError:
undefined method `[]' for true:TrueClass
# /home/rof/cache/bundler/ruby/1.9.1/gems/poltergeist-1.5.0/lib/capybara/poltergeist/browser.rb:54:in `find'
# /home/rof/cache/bundler/ruby/1.9.1/gems/poltergeist-1.5.0/lib/capybara/poltergeist/driver.rb:114:in `find'
# /home/rof/cache/bundler/ruby/1.9.1/gems/poltergeist-1.5.0/lib/capybara/poltergeist/driver.rb:118:in `find_xpath'
# /home/rof/cache/bundler/ruby/1.9.1/gems/capybara-2.2.1/lib/capybara/node/finders.rb:154:in `block in resolve_query'
# /home/rof/cache/bundler/ruby/1.9.1/gems/capybara-2.2.1/lib/capybara/node/base.rb:77:in `synchronize'
# /home/rof/cache/bundler/ruby/1.9.1/gems/capybara-2.2.1/lib/capybara/node/finders.rb:150:in `resolve_query'
# /home/rof/cache/bundler/ruby/1.9.1/gems/capybara-2.2.1/lib/capybara/node/finders.rb:129:in `all'
# /home/rof/cache/bundler/ruby/1.9.1/gems/capybara-2.2.1/lib/capybara/node/matchers.rb:107:in `block in assert_no_selector'
# /home/rof/cache/bundler/ruby/1.9.1/gems/capybara-2.2.1/lib/capybara/node/base.rb:81:in `synchronize'
# /home/rof/cache/bundler/ruby/1.9.1/gems/capybara-2.2.1/lib/capybara/node/matchers.rb:106:in `assert_no_selector'
# /home/rof/cache/bundler/ruby/1.9.1/gems/capybara-2.2.1/lib/capybara/session.rb:396:in `block (2 levels) in <class:Session>'
# /home/rof/cache/bundler/ruby/1.9.1/gems/capybara-2.2.1/lib/capybara/session.rb:81:in `reset!'
# /home/rof/cache/bundler/ruby/1.9.1/gems/capybara-2.2.1/lib/capybara.rb:253:in `block in reset_sessions!'
# /home/rof/cache/bundler/ruby/1.9.1/gems/capybara-2.2.1/lib/capybara.rb:253:in `each'
# /home/rof/cache/bundler/ruby/1.9.1/gems/capybara-2.2.1/lib/capybara.rb:253:in `reset_sessions!'
# /home/rof/cache/bundler/ruby/1.9.1/gems/capybara-2.2.1/lib/capybara/rspec.rb:20:in `block (2 levels) in <top (required)>'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:471:in `instance_eval'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:471:in `instance_eval_with_rescue'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:242:in `instance_eval_with_rescue'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/hooks.rb:31:in `run'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/hooks.rb:85:in `block in run'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/hooks.rb:85:in `each'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/hooks.rb:85:in `run'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/hooks.rb:446:in `run_hook'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:350:in `run_after_each_hooks'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:298:in `run_after_each'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:120:in `block in run'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-rails-2.14.0/lib/rspec/rails/example/controller_example_group.rb:158:in `call'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-rails-2.14.0/lib/rspec/rails/example/controller_example_group.rb:158:in `block (2 levels) in <module:ControllerExampleGroup>'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_exec'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_eval_with_args'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:247:in `instance_eval_with_args'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/hooks.rb:106:in `block (2 levels) in run'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/hooks.rb:104:in `call'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/hooks.rb:104:in `run'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/hooks.rb:446:in `run_hook'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:340:in `run_around_each_hooks'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:256:in `with_around_each_hooks'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:111:in `run'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:390:in `block in run_examples'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:386:in `map'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:386:in `run_examples'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:371:in `run'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:28:in `map'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:28:in `block in run'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/reporter.rb:58:in `report'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:25:in `run'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:80:in `run'
# /home/rof/cache/bundler/ruby/1.9.1/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:17:in `block in autorun'
Any idea what's going on?

Why does script run in Firefox, but not IE8?

I have a script that runs OK in Firefox.
The script does not run in Internet Explorer. I would be grateful for assistance.
Here are first few lines:
require 'rubygems'
require 'watir'
require 'watir-webdriver'
require 'test/unit'
URL = "http://google.com/"
class TestGoogle < Test::Unit::TestCase
def setup
##browser = Watir::Browser.new :firefox
#browser = Watir::Browser.new :ie
end
def testSignInLink
#browser.goto URL
Here are selected error messages:
C:\Ruby193\bin\ruby.exe -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:/RubymineProjects/ditto/Google_01_TU_03.rb
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.7.0/lib/watir-classic/version.rb:3: warning: already initialized constant VERSION
...
...
1) Error:
testSignInLink(TestGoogle):
TypeError: superclass mismatch for class UnknownObjectException
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.7.0/lib/watir- classic/exceptions.rb:12:in `<module:Exception>'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.7.0/lib/watir- classic/exceptions.rb:2:in `<module:Watir>'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.7.0/lib/watir-classic/exceptions.rb:1:in `<top (required)>'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.7.0/lib/watir-classic.rb:6:in `require'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.7.0/lib/watir-classic.rb:6:in `<top (required)>'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-4.0.2-x86-mingw32/lib/watir/loader.rb:48:in `require'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-4.0.2-x86-mingw32/lib/watir/loader.rb:48:in `load_driver'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-4.0.2-x86-mingw32/lib/watir/loader.rb:40:in `load_driver_for'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-4.0.2-x86-mingw32/lib/watir/loader.rb:8:in `new'
C:/RubymineProjects/ditto/Google_01_TU_03.rb:11:in `setup'
Line 11 is:
#browser = Watir::Browser.new :ie
Based on #abe comment, I did the following.
For IE only, I removed "require 'watir'". That worked fine.
Restore "require 'watir'". Remove "require 'watir-webdriver'". That worked fine.
That's the answer to my question. But I don't understand that. It sounds as if the two APIs are interchangeable :)

Watir-webdriver - can't access nested frame by id

The webpage has a nested frame structure. The frame FCCBMain is nested in frame Main. I can access it this way:
browser.frame(:id => "FCCBMain").frames[0]
=> #<Watir::Frame:0x504e155578d49f34 located=false selector={:index=>0}>
browser.frame(:id => "FCCBMain").frames[0].id
=> "MainLeft"
But not this way:
brwoser.frame(:id => "FCCBMain").frame(:id => "MainLeft").id
Selenium::WebDriver::Error::StaleElementReferenceError: Element belongs to a different frame than the current one - switch to its containing frame to use it
from [remote server] resource://fxdriver/modules/web_element_cache.js:5634:in `unknown'
from [remote server] file:///tmp/webdriver-profile20120816-21551-1a8xyvv/extensions/fxdriver#googlecode.com/components/driver_component.js:5329:in `unknown'
from [remote server] file:///tmp/webdriver-profile20120816-21551-1a8xyvv/extensions/fxdriver#googlecode.com/components/driver_component.js:6623:in `unknown'
from [remote server] file:///tmp/webdriver-profile20120816-21551-1a8xyvv/extensions/fxdriver#googlecode.com/components/command_processor.js:9924:in `unknown'
...
I thought these two ways are very similar. Why doesn't the later work?
(if it helps, here is the webpage I'm working on)
First I think you have a typo with "brwoser.frame"
Second if you are going to access the frames with the chain you have to include ALL frames and framesets in the path IE: browser.frame(:id => "FCCBMain").frameset.frameset.frame(:id => "MainLeft").id
The reason your second solution was not working is because it was looking for an immediate child of frame(FCCBMain) to have the id of "MainLeft". Frame(FCCBMain) only has a frameset child and the frameset does not have an ID. If the frameset had an ID of "MainLeft" AND was a frame(not a frameset) then the line, browser.frame(:id => "FCCBMain").frame(:id => "MainLeft").id, would work.

Resources