0

I'm starting watir-rails fresh. I'm getting a Window not found exception.

Watir::Exception::NoMatchingWindowFoundException: browser window was closed
/Users/aaron/.rvm/gems/ruby-2.1.6/gems/watir-webdriver-0.9.1/lib/watir-webdriver/browser.rb:344:in `assert_exists'

I'm not sure if this is supposed to happen, but when I start a new driver, 14 windows belong to that driver, but none of them are present.

[2] pry(#<RSpec::ExampleGroups::PokitdokPDPC::Clinic>)> browser.windows
[
  [ 0] #<Watir::Window:0x242074a821d6075a located=true>,
  [ 1] #<Watir::Window:0x5521d3908d99909a located=true>,
  [ 2] #<Watir::Window:0x..fa544e5b1f07a764e located=true>,
  [ 3] #<Watir::Window:0x..feb72338121a19c86 located=true>,
  [ 4] #<Watir::Window:0x2cc412dc5e76463e located=true>,
  [ 5] #<Watir::Window:0x..f8644fa95ef4e22ac located=true>,
  [ 6] #<Watir::Window:0x..f8d8c0e47ffcfc502 located=true>,
  [ 7] #<Watir::Window:0x9a30ded69ef370e located=true>,
  [ 8] #<Watir::Window:0x..fe4f2d355d2301ebc located=true>,
  [ 9] #<Watir::Window:0x..fccfaa137adda58cc located=true>,
  [10] #<Watir::Window:0x6f6f80943b132490 located=true>,
  [11] #<Watir::Window:0x32677c64365802fc located=true>,
  [12] #<Watir::Window:0x..fed6bcc7b81d099ce located=true>,
  [13] #<Watir::Window:0x501561edeacf8b50 located=true>
]
[3] pry(#<RSpec::ExampleGroups::PokitdokPDPC::Clinic>)> windows = browser.windows.find_all{|w| w.present?}
[]

My code:

require "spec_helper"

describe "Registration", type: :feature do

  it 'allows a user to sign up' do
    Watir.driver = :webdriver
    browser = Watir::Browser.new :firefox

    browser.goto root_path #Navigates correctly to root_path
    browser.link(text: 'Register').click #Throws window not found
  end
end
TIMBERings
  • 688
  • 1
  • 8
  • 28
  • smells a little like a timing issue? try running the code inside the 'it' loop in IRB, see if it works. (require watir-webdriver, define root_path string, then paste in the 4 lines one at a time and see what happens. – Chuck van der Linden Mar 11 '16 at 18:01
  • also, which specific line of your code is triggering the error? – Chuck van der Linden Mar 11 '16 at 18:02
  • It runs fine in pry/irb. The error is happening on the `browser.link(text: 'Register').click`. – TIMBERings Mar 12 '16 at 01:12
  • if it works from IRB but not when run as a script that's almost always a sign of a timing issue. is the page doing re-directs after authentication or somesuch? it sounds a lot like it is opening a new tab and closing the old one.. have you tried other browsers? maybe just add a wait of a second or two between the goto and the click? Or perhaps try using the `.when_present' decorator `browser.link(text: 'Register').when_present.click` – Chuck van der Linden Mar 17 '16 at 16:56
  • I've added .when_present and have had no luck with that. I've thrown in binding.pry breaks and can clearly see it's loaded before it's being clicked. – TIMBERings Mar 25 '16 at 15:46
  • Lesson learned, don't user watir and capybara in the same project. I am trying to replace capybara, but didn't want to completely removed what we had. – TIMBERings Mar 25 '16 at 18:11

1 Answers1

0

I followed this and did only the step 1 -create the key in the register- and worked fine.

Community
  • 1
  • 1
hestellezg
  • 3,309
  • 3
  • 33
  • 37