I'm using Capybara with the Selenium webdriver in my testing suite. I've noticed that when all tests are complete, Selenium closes the browser by binding to at_exit. However, this causes an issue for my web application displays a "Are you sure you want to navigate away" dialog onunload (Please don't judge. This is an intranet application and the users specifically requested it.). So when the tests are done my Cucumber scenario fails (even though all my steps pass) because there was an unhandled Javascript confirm dialog. Is there any way to bind after Selenium tries to close the browser and accept the dialog?
Update
I believe I have found the issue with this. It appears that after each test, Capybara resets the browser by clearing all cookies and navigating to about:blank. This is what is causing the onbeforeunload dialog to open (not browser.quit()). I'm cross posting on the Capybara mailing list to try to get help on this and will post anything I find here.
Is it possible for you to switch context at_exit and accept or dismiss the alert. Something like this
at_exit do
page.driver.browser.switch_to.alert.accept
#or
page.driver.browser.switch_to.alert.dismiss
end
If you are using a unit test framework like JUnit or TestNG, then what I do is use Configuration annoations like #AfterTest or #AfterClass to quit the browser. This way, while the test is running the browser is always up. It's not until the #Test block is finished that the test case will close the browser instance.
If you are using Ruby, I assume there is something similar to this.
As I mentioned in the OP update it appears that Capybara navigates to about:blank as the end of each Cucumber scenario. After talking with jnicklas from the Capybara team it appears that the best way to handle this is to implement a Cucumber after handler which navigates away before Capybara tries to and handle the alert there.
After do
# after each test navigate away before Capybara tries to so that we can appropriately handle the onbeforeunload dialog
if #browser
begin
#browser.navigate.to("about:blank")
#browser.switch_to.alert.accept
rescue Selenium::WebDriver::Error::NoAlertPresentError
# No alert was present. Don't need to do anything
end
end
end
Like it was mentioned, calling driver.Quit() should solve the problem, but if the pop-up window is causing an issue that prevents the browser from closing, then eliminate the instance. A simple solution is to wrap your test inside of a using clause.
using (IWebDriver driver = new FirefoxDriver())
{
//Perform your test
driver.Quit();
}
Related
I'm not sure if there is a term for what I'm trying to do. I currently have a test suite using codeception for a php application. What I would like to do is be able to either of the following:
watch the browser automation in an actual browser
take over the browser at a specific point ( Sort of like a hand over from the script to the browser to allow me to continue to run a session )
Is this possible? If so what is it called in the selenium documentation
a) Selenium runs the actual browser and you can see what it is doing unless you configured Selenium to run some headless browser (but I don't know anything about headless browsers supported by Selenium);
b) Use Codeception's pauseExecution method to stop execution at specific point.
Documentation:
Pauses test execution in debug mode. To proceed test press “ENTER” in
console.
This method is useful while writing tests, since it allows you to
inspect the current page in the middle of a test case.
There are many selenium webdriver binding package of Golang.
However, I don't want to control browser throught server.
How can I control browser with Golang and selenium without selenium server?
You can try github.com/fedesog/webdriver which says in its documentation:
This is a pure go library and doesn't require a running Selenium driver.
I would characterize the Selenium webdriver as a client rather than a server. Caveat: I have used the Selenium webdriver (Chrome version) from .Net and I am assuming it is similar for Go.
The way Selenium works is that you will launch an instance of it from within code, and it creates a live version of the selected browser (i.e. Chrome) and your program retains control over it. Then you write code to tell the browser to navigate to a page, inspect the response, and interact with the browser by filling out form data, clicking on buttons, etc. You can see what is happening on the browser as the code runs, so it is easy to troubleshoot when the interaction doesn't go as planned.
I have used Selenium to upload tens of thousands of records to a website that has no API and only a graphical user interface. Give it a chance.
My web app uses IndexedDB and I'm testing on SauceLabs. Some months back my tests ran but now they block on a browser dialog that says "http://gbserver3.cs.unc.edu/" wants to: store files on this device", with an Allow button.
This is Win7 and Chrome or Firefox. Likely others too.
How can I dismiss or prevent this dialog?
Update: I have discovered that if I don't ask for quota I don't get the popup and my tests succeed. I'd still like to learn how to get rid of that dialog.
we are using Nightwatch.js in our project and we were facing the same issue.
What actually did the trick was using --unlimited-storage switch when launching the browser.
(List of other command line switches for Chromium can be found here)
I am getting a warning like this when testing with selenium rc on IE Browser. Is there a command I can use to wait for it and click yes? Changing the Trusted Sites is not an option.
http://windowsxp.mvps.org/images/elevdialog.JPG
What we do is leverage a freely available tool called autoit which can interact with the windows component object model. If you are expecting the dialog you can invoke it with an exec and then proceed with selenium commands. If you want to catch unexpected ones, what we do is execute our selenium commands in a thread and if they time out we then run autoit having it return 0 or 1 depending if it finds a dialog and take things from there.
You are going to have to go into the IE Options and tweak the trusted sites so that it has those 2 sites. Once that has been done then you should be fine.
I just added ExceptionHub (a javascript error tracking service) to our website, but all my selenium tests are failing now. When I look at the selenium output, it says it timed out in waitForPageToLoad command. If I run the test locally, I see that the page loads up fine, so I'm not really sure why selenium keeps waiting. Has anyone else managed to get ExceptionHub working with selenium?
I've seen similar problems with UserVoice. Often the rest of the page is loaded but still waiting for UserVoice and the test will time out.
It might help if you don't start loading ExceptionHub until the rest of the page is loaded. Of course that would mean you can't catch any javascript errors during page load...