“Watir::Exception::NoMatchingWindowFoundException:

2019-05-24 08:05发布

问题:

I'm running tests in Ruby Mine 2.7.1 using Page-Object + Rspec.

Environment: Windows 7 x64, Ruby 1.9.3 p551, IE 11.

Gems: watir, rspec, bundler, page-object

When i run tests in Chrome or Firefox everything is ok.

But when i try to run them in IE, the IE window with correct page gets opened and after that i get an error specified in Subject: "Watir::Exception::NoMatchingWindowFoundException: browser window was closed"

The point is that the browser is actually open at that moment and shows a correct page. (See the screencast showing what happens: http://screencast.com/t/06prRy3OMLM)

Test gets finished with an error and the config.after do section doesn't get executed because the browser window remains opened.

That error happens when the following code is executed:

before(:each) do

visit <ClassName>

end

Seems like the IEDriverServer loses connection with IE right after the page is opened.

The most confusing this is that in very rare cases, everything is working good, and in even more rare cases everything is working with significant slowdowns with timeout error at the end.

sleep <n> delays don't help.

I tried different versions of selenium-webdriver gem (it is required by watir gem), different versions of IEDriverServer for both x86 and x64 platforms - result is the same.

Exception description in lib/watir-classic/exceptions.rb says the following:

# This exception is raised if the window cannot be found class NoMatchingWindowFoundException < WatirException; end

What do i do to set IEDriverServer not to lose the IE browser?

回答1:

UPD: I found a solution. It consists of two steps.

Step 1.

Fisrt of all, an answer to the above question is explicitly described here, "Required Configuration" section, paragraph 5 "For IE 11 only, ...": (https://code.google.com/p/selenium/wiki/InternetExplorerDriver)

`For IE 11 only, you will need to set a registry entry on the target computer so that the driver can maintain a connection to the instance of Internet Explorer it creates.

For 32-bit Windows installations, the key you must examine in the registry editor is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE.

For 64-bit Windows installations, the key is HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE.

Please note that the FEATURE_BFCACHE subkey may or may not be present, and should be created if it is not present. Important: Inside this key, create a DWORD value named iexplore.exe with the value of 0.`

If this value contains somethings except of 0, the IEDriverServer will lose connection to IE browser as described in my case.

So, RTFM! (c) See Step 2 in the next comment.



回答2:

If you require 'watir' and you specify IE, the implementation defaults to watir-classic behavior.

Try:

require "watir" Watir.driver = :webdriver browser = Watir::Browser.new :ie