Selenium framework for two different systems integrating with eachother - selenium-webdriver

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 :)

Related

How does DesiredCapabilities in Selenium WebDriver works internally

I want to know How does Desired Capabilities in Selenium WebDriver works internally??
For e.g. Suppose i have 2 different version of Chromedriver.exe on my machine. While executing code with Desired Capabilities, which exe it would pick and why?
How does Desired Capabilities internally decides from which path exe should be picked??
The DesiredCapabilities Class is used by the WebDriver instance (i.e. driver) to open the browser session with specified attributes. For example, the below code will:
Always use the "chromedriver.exe" from "C:\your_path\" directory.
Through DesiredCapabilities Class we can specify the location of the Chrome Executable.
Finally you need to pass the instance of DesiredCapabilities for driver to open the Chrome Application with those capabilities.
System.setProperty("webdriver.chrome.driver", "C:\\your_path\\chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.binary", "C:\\Program Files\\Google\\Chrome\\Application");
WebDriver driver = new ChromeDriver(capabilities);
driver.get("http:\\gmail.com");
It is always recommended to use the latest version of the drivers. The latest versions/releases of the drivers addresses the the bugs/defects of the previous build & also introduces new features. So, the idea of using another older version of drivers are not a part of good programming practice.
Let me know if this answers your question.

Using Selenium Commands on HTML content stored in a local varialble

This may sound odd BUT Is it possible to use WebDriver commands on a static variable that holds the html source? (eg: findElementbyId)
This is what i want to do:
set firefox webDriver
open website url
save the HTML pageSource to a "static local variable"
quit webDriver
Now - i want to be able to findElements and texts within this locally stored PageSource. (preferably using the selenium commands)
Any help and/or suggestion is greatly appreciated.
Thanks.
Basically no, it falls down at (5). The FirefoxDriver needs to communicate with an actual Firefox browser using the WebDriver protocol. Selenium can't work with just a String.
It's not clear what your use case is, but you could do things like copy the HTML to a temporary file, generate a file: URL for it, load it with the HtmlUnit or PhantomJS drivers and re-run your tests in-memory.
Surely plain old regular expressions, or an HTML parser like JSoup, are better options for post-processing HTML?

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.

Selenium get last browser window

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

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