Selenium RemoteWebDriver release session but don't close browser - selenium

I am new to selenium automation testing, Is there a way to kill remotewebdriver session without closing the browser?
Also is it possible to wait for user intervention (say Click on certain element)
I googled my queries, but couldn't find any answer I was looking for.
EDIT 1:
I was doing a little POC on a customer relation service app, where csr will click a button and it will open an external application, and take him to a form, where some information will be populated automatically by selenium and some information will be populated by csr's manual input.
So far in the Project, I have a spring mvc 4 application. There is a REST controller. Upon posting a json to my controller, it call invokes a service method which opens selenium remote webdriver.
1.I want my browser to stay opened until user press submit button.
2.I want to take csr to the desired page and lose the control of selenium, afterwards csr will submit the page or close the browser depending on situation.

Related

How to handle external applications in a selenium-test?

I am writing a test that verifies that a warning to the user before the user opens a document. If the user says that they still would like to open the document, the document opens in an external application (pdf or word).
But now I have an external application over the browser window, and it messes up for other tests.
So, what are the best practices around this kind of issue? Rewrite of the appliction to allow for not opening documents in test?
Added description:
The problem is twofold.
1) It starts processes (word and acrobat) that fills the desctop and requires resources from the test-slave
2) The external process seems to interfer with other tests since (guessing here) it is located over the browser window.
what i understood from your post is, the document(word/pdf) is opening in the browser window hence you are not able to proceed with further steps. If so, you can verify the Title to make sure the document is opened in browser window and can navigate back using below snippet.
driver.navigate().back();
Hope this helps.
What I understand from the line
'But now I have an external application over the browser window, and it messes up for other tests.'
is that once user clicks on open button a new window opens up (Window based application) since you have mentioned PDF or Word.
You can use robot class in such cases, below code snippet will close the current active window:
Robot rbt = new Robot();
rbt.keyPress(KeyEvent.VK_ALT);
rbt.keyPress(KeyEvent.VK_F4);
rbt.keyRelease(KeyEvent.VK_ALT);
rbt.keyRelease(KeyEvent.VK_F4);
Make sure you deal with sync issues properly so that intended window is closed instead of AUT.

Identifying word documents opened by Selenium Webdriver

In my Selenium project word document is being opened as a report.
How can I identify whether the document is opened or not using Selenium webdriver.
In short, unless the document opens utilizing the browser, then you can't with Selenium WebDriver. Selenium only has access to what the browser itself has access to. If the browser is handing this off to the OS or MS Office to handle the specifics then you lose access to it.
You could try to intercept the communication and determine when the code to call the word document to open is executed, but that would be custom code and depend on the application itself.
Personally I think the best way would be to instantiate an OpenQA.Selenium.Interactions.Actions class instance and then specify the specific keystrokes to capture the screen and save it. Then switch back to the browser window driver.switchto().window() and continue. Then you can verify manually that the screen capture has the word document in it after the test is completed.

Modal dialog present (WARNING: The server did not provide any stacktrace information)

I currently using Selenium Web driver.(2.24.1)- Programming Language--JAVA
I want to save a web Page in HTML only Format, so i am using Robot class to save webpage.
I am using this Save functionality in a loop (for n times).
This is working good for for few cases in the loop but randomly( may be 1st time or 3rd times...nth times) it fails with an error message "Exception in thread "main" org.openqa.selenium.UnhandledAlertException: Modal dialog present (WARNING: The server did not provide any stacktrace information)"
Well it depends on what the Modal Dialog was, but there are three things I would check.
First Most likely you'll need to upgrade your Web Driver
I noticed you're using Webdriver 2.2.24, if you're also using FireFox as the browser you'll want to upgrade your WebDriver to 2.2.26 or higher. There was a change to "Prevent firefox from updating, checking and warning for extension and plugin updates" IF any of those things occur they also will raise a modal dialog.
Second It could be a dialog raised by the site you're testing
javascript alert() or a window.Prompt() are examples of modal dialogs the site be raising to do any number of things. You can use the WebDriver to interact with these dialogs.
Third If it's none of the above get a screen capture of the dialog
The dialog may not be something that you can access through the WebDriver API so you need to write code to get capture the entire screen (should be easy with some googling). Or you can record a video session when running the code.

Selenium Web Driver - login event not launching

I'm using Selenium Web driver for testing, but can't ecen get past login page. The code I'm using:
driver.Navigate().GoToUrl(baseURL + "URL");
driver.FindElement(By.Id("loginForm:username")).SendKeys("uName");
driver.FindElement(By.Id("loginForm:password")).SendKeys("pass");
driver.FindElement(By.Id("loginForm:login")).Click();
Element locators are correct and login click is happening, but after that I am not logged in, but page is just stuck there - no error or something. Same code worked in IDE.
I'm using IE9 and also there is changed settings:
var options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
driver = new InternetExplorerDriver(options);
Any advices how to overcome this problem?
This happens with me very often, but not sure if it is the same reason for you.
When you run the tests locally, all the actions (sendkeys, click etc) take place really quickly. The loginForm:login button could be kept disabled until the user enters text in fields loginForm:username and loginForm:password. So there is a possibility that the button loginForm:login could have not been active when it is being clicked.
So I would recommend using an explicit wait to check if the element id loginForm:login is displayed before clicking it.
This step is basically useless but all it does is simply waste some time between "sending keys" to the password text box field and clicking submit.
Also for a quick check you could also do something similar to sleep 2 (make the script sleep for 2 seconds) after entering the password and before clicking the login button.
IF you eventually plan to run this on a remote machine, you dont need to do any of the above two steps, the time delay due to communication between the machines will be sufficient for the whole process to work smoothly.
(The same problem occurs on the linkedin login page- Login button is disabled unless Username and password is entered, but the speed at which the webdriver performs each step, The login button is not active when being clicked on.)

Selenium: How to stop RemoteRunner.html from getting invoked

I am using selenium for one for my Java applications on linux. The application invokes a mozilla browser, fills login details (username and password), and then submits the form. I am able to achieve this using selenium, but every time a url is selected 2 instances of mozilla is getting invoked. One instance is that of the url selected and the other instance is a RemoteRunner.html which has selenium command history and other details.
I don't want this page to be invoked. Is there a way to stop this page from getting invoked?
Thanks and Regards,
Sunil.
The RemoteRunner window is required as it is controlling the application under test within the other window. You can run Selenium in a single window using the command line option multiWindow=false however this uses frames, which can sometimes cause issues with the application under test.