I am doing the automation in an application for some web pages in the vb.net using the chrome driver.
During the application operation here is a chance that chrome may close before completion of automation process (user may close or chrome may crash).
Now my requirement is that if the chrome is closed by the user while automation is running, the application needs to know that a close event in chrome is raised by the user and the application needs give a Yes/No message with the custom text to confirm the action of the user.
I searched this for some time on the internet and found nothing. Please provide the way to catch the closing event of the chrome browser in vb.net using the chrome driver.
Not sure I quite understand the question, but can you use the window.onbeforeunload approach?
e.g. See W3Schools
$(document).ready(function () {
window.onbeforeunload = function () {
//your code here
};
});
Related
Using ChromeDriver 2.14, selenium server 2.47.1 and Chrome 45. I am attempting to handle a basic authentication prompt. I have tried the following code to try and resolve this.
var wait = new OpenQA.Selenium.Support.UI.WebDriverWait(Driver.Value, new TimeSpan(0,0,60)).Until(OpenQA.Selenium.Support.UI.ExpectedConditions.AlertIsPresent());
Driver.Value.SwitchTo().Alert().Dismiss();
And this
Driver.Value.SwitchTo().Alert().SetAuthenticationCredentials("test", "test");
and this
while (true)
{
try
{
Driver.Value.SwitchTo().Alert().SetAuthenticationCredentials("test", "test");
break; //this is brute force I know
}
catch
{
Thread.Sleep(100);
}
}
No luck, they all throw a "no alert found" exception. We would switch to firefox, but it is an internal application and we only support IE or Chrome.
I didn't find a way to use the authentication options inside Selenium with the basic authtication prompt. Instead I found that if you run fiddler in the background, you can have it auto-authenticate for you when prompted based on a specific site. Then the popup never shows up and your Selenium scripts run just fine.
Auto http authenticate traffic for a specific site with fiddler
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'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();
}
I am working on client side. I have created around 150 test scripts. But during execution, after some script execution, Selenium throws below error and it close the browser. Time is not a fix for this error. It comes when I am executing all the test scripts together in parallel.
The error shows on Google Chrome and Firefox browsers. I am using selenium-server-standalone-2.26.0.jar file and doing execution on FF 13.0.1 version. I have also tried with FF version 14, but I get the same error. My client is not happy with this error because we dont have workaround for this issue.
**Error message:**
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Error communicating with the remote browser. It may have died
I think this will happen when you dealing with popup window.
Example
Working on main window clicking on something leads to open a new popup
switch the control to popup window & do your operations in pop-up
Most of the cases popup will be closed automatically after some action performed in it. (EX : Login with facebook option most of site now a days, after entering user credential no need to close that popup it will be closed automatically after submitting proper credentials)
After this you need to switch the control to main window again otherwise it will throws above exception.
I think your doing some operations without having the control over a window.
I have a test where I need to do a login, close browser and open it again then check something on the page.
How can I do this when running webdriver with remote hub setup? or do i have to run this without remote?
Test is something like this:
Open browser
Login
Close browser
Open browser again
Check login is remembered
The process to accomplish this is going to be very similar to that of a solution in a non-grid environment. Note that the following code is written for Java, but I can't imagine C# being much different.
WebDriver driver = new RemoteWebDriver("hubURL", desiredCapabilities);
driver.manage().deleteAllCookies();
driver.get("http://path/to/page");
//login to application
driver.quit(); //This will close the browser on the remote machine
//Now to try it again
driver = new RemoteWebDriver("hubURL", desiredCapabilities);
driver.get("http://path/to/page");
Assert.assertTrue(some element that is not on the login page but is on the page after is present);
driver.quit();
Presumably you're testing some cookie stuff. Unfortunately, there's no guarantee any particular node will execute any request, unless you constrain it properly. You need to have a node advertise a unique capability that the client then requests, ensuring the hub will route to that node every time. But, naturally, if that node goes down, you won't have any others that could service the request.