Selenium get last browser window - selenium-webdriver

Every time I run my test selenium opens another Firefox window. It's annoying to see so many windows after several runs of the test. Is it possible to utilize the previous opened one?

For Selenium 2 (WebDriver), try creating a new object for FF:
ffWebDriver = new FirefoxDriver();
This should create an object of the Firefox web-driver that you can control and won't be quit until you call:
ffWebDriver.Quit();

This is something NOT possible. Please look into https://code.google.com/p/selenium/issues/detail?id=18 to have an idea why is it so. If only multiple windows opened is a problem here, you can quit all the browser instances opened after each test by calling driver.quit(); method.
In case you are using Python bindings, you might want to have a look into this : http://webdriverplus.org/en/latest/browsers.html#reuse-browser

Related

appium with no reset does not close the simulator after execution

I have to run some test suite on two remote machines.
So, after one suite, i reset the app and for the next suite, app starts well.
But the problem is, after completing the total execution
driver.quit()
just close the app but it does not close the simulator as
no reset is true.
So, is there a way to close the xcode simulator using appium or selenium?
I do not want to use ssh and full reset option.
I also do not want to use
killall "Simulator" as it needs ssh connection.
try this
String closesim[] = {"killall","iOS Simulator"};
Runtime.getRuntime().exec(closesim);
You can try directly close simulator by passing below code in you AfterClass,Or AfterSuit method . which close all the simulator which is open in system.
For my case its working i am not sure in your cases its work because if you pass below command in terminal you can find its close your simulator.
runtime.exec("xcrun simctl shutdown all");

Selenium framework for two different systems integrating with eachother

I am using selenium webdriver with Testng framework. I have three different systems where the output of first system is the input to the second and output of second system is input to the third one.
first system has its own UI which can be only executed in Chrome and second and third has UI which can executed only in IE. Calls beteween systems are Asynchronous. Can some one help how to design this?
You will create 3 driver for each browser. You will keep your outputs as variable and passing to other system call.
You can create as many number of driver in a single script
Refer the below code. It's a just a example what you needed :-
System.setProperty("webdriver.chrome.driver","./src\\lib\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.google.co.in/");
String output1=driver.findElement(By.xpath("//input[#name='q']")).getText();
WebDriver driverIE=new InternetExplorerDriver();
driverIE.get("https://www.google.co.in/");
WebElement aa= driverIE.findElement(By.xpath("//input[#name='q']");
aa.sendKeys(output1);
WebDriver driverMFF= new FirefoxDriver();
driverMFF.get("https://www.google.co.in/");
String output3=driverMFF.findElement(By.xpath("//input[#name='q']")).getText();
In above demo script, I save the output of chromedriver and pass it to IE
Hope it will help :)

What is the most reliable .net selenium web driver?

In using .net selenium webdrivers, I have been stumbling in 2 main issues, each for a different specific webdriver.
The table below shows the issues Chrome and Firefox webdrivers have been falling short with me:
I am using RellYa's selenium jquery extensions.
Chrome webdriver randomly throws a jQuery not found exception. If I try a couple of times, I eventually succeed.
With Firefox's webdriver, this never happened.
On the other hand, firefox throws a
Unable to bind to locking port 7054 within 45000 ms
Research shows that the reason behind this is that I must have left another firefox webdriver not closed/not quit. But this defeats my using selenium to automate web tasks, in a multi threaded manner. I mean, after a couple of threads are opened, seems it reaches some limit and waits for one of the opened webdrivers to close.
Actually, from this firefox webdriver's documentation, they make it clear that only one instance is supposed to be running. What one is supposed to do then if he had in mind multi threading ?
Does any one have working solutions for the problems singled out in the table, for each specific webdriver implementations ?
No, you can run multiple instances of firefox, chrome, or whatever from your machine at any one time. If you research "Selenium Grid", you will see that it is designed to do that.
So:
The unable to bind message on firefox is not caused by another driver locking a port. Each driver instance starts on its own open port.
If you are not using Selenium Grid, or not using the grid, and are trying to handle the multi-threading yourself, just be careful of how you open and close your browsers in your #Configuration phases in your test runner.
As a educated guess, if you have instability, its more likely because you are trying to control a newer browser with a too-old version of Selenium? We need more info on your question, such as an example project to look at.

How to handle Windows authentication dialogue using selenium webdriver?

I have requirement of opening share point URL and it looks for credential through windows authentication. So I read some where to use AutoIt with seleniun webdriver but how we can call this AutoIt script because my web driver script will wait until window dialogue is get off. So cursor will not go to next line to execute AutoIT script and finally we will not be able run our script.
Not sure if you are using Java or C#. In C#, I would go with MSUIA. Write a method to deal with the Windows dialogues and run it on a separate thread. This method should act as a listener to the Desktop tree and whenever encounters a control that it needs to work on, does its job. Have the method scan the Desktop tree once every 5 seconds or so and put it to sleep if no object is found.
In Java, using AutoIt should do the trick, not that it won't in C#
http://www.toolsqa.com/selenium-webdriver/autoit-selenium-webdriver/

Selenium Grid: Error communicating with the remote browser. It may have died

I have two machines, one with all the stuff I need (Eclipse + TestNG +scripts) and the other one with just browsers installed.
I use Selenium Grid 2.35.0.
Everything seems to be fine except the problem that very often I get this error:
Error communicating with the remote browser. It may have died.
Scripts are not complicated at all, I run them one-by-one, so it just happens randomly. I don't think it's because of the browser.
Any idea/fix?
If you need more info I'm here.
The only time I get that error is when I manually close the browser myself. I would verify that the machine withe the browsers is stable.
It could also be due to calling driver.quit() and not instantiating another driver (I haven't ever done this, so I don't know what error this throws)
I notice this error as well but ONLY when using Selenium grid (using 2.35 but 2.38 exists now)
When I run locally I don't get error communicating with the browse but typically it can happen when there is a bug with your setup and teardown code (maybe one of your classes creates an instance of your browser before your setup function gets called)
See How to close child browser window in Selenium WebDriver using Java
ensure to call driver.close(); on every popup / new windows / new tab you open during the test (after switching to it using driver.switchTo())
and to call driver.quit(); at the end of the session (generally in #AfterClass annotated method)

Resources