| || |
Executing test on multiple browsers with webdriver
I'm new to selenium & working on webdriver currently.I want to run my test parellely on (IE,FF & chrome) in same machine.
I tried doing that using the below code but im getting error at port number,tried with different port numbers but still the same.
IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), DesiredCapabilities.InternetExplorer(),DesiredCapa bilities.GoogleChrome());
Kindly let me know what i'm missing in this..
I'm assuming you have a basic Selenium Grid setup, or using a 3rd party grid. The best way to do the Webdriver initialization is using a Factory pattern. Instead of saying,
IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub")
do something like
IWebDriver driver = WebdriverFactory.createDriver(); // creates a diver using a config file or system property.
This will allow you to run the same tests with different config profiles. And keep the switching logic outside of the test itself.
Here's an example in Python how I implemented my webdriver factory.
Notice that it gets it's config file from an environment variable read it by a config manager (which I called WTF_CONFIG_READER).
It runs the test using a config file similar to this one, https://github.com/wiredrive/wtframe...s/default.yaml
So when I run them in parallel, I tell my build manager (I'm using Bamboo), to use a different browser config file for each process. So I'm running across all our tested browsers in parallel. When I run the tests on my dev machine, it uses a local browser config to allow the use of local browser for easier debugging.
Heyy david,thanks for your reply.
i dont have any grid set up till now.I'm using webdriver 2.20. I heard that grid is integrated in webdriver 2.20 & tests can be run parallely in multiple browsers.
I'm using VS2013 & C# as the coding language.
I coded a test & its working fine in indiviual browsers.But what i wanted to do is i want to run the same script in multiple browsers parallely.
Kindly let me know how do i achieve this.
You can't pass the 2 sets of desired capabilities into 1 webdriver, you'll need 2 separate webdrivers. Think of 1 webdriver as representing 1 browser process. I think it's best to use a Factory class to creating the webdrivers, then parallelize using a build script. Ask a build engineer for help building a build script that integrates well with your process. The factory method is very simple to create, you or a dev can easily build one. It's just reading a config setting, then serving up a corresponding browser.
Although the grid (jar) files are integrated into package. You are running it as a local node. This is fairly ok if you're running a small amount of concurrent tests locally for testing out a script. However, I still prefer using a grid, so I can parallelize more, and keep the browsers on separate machines to avoid issues like plugin and cookie contamination. For example, say Flash plugin crashes on 1 browser, you don't want that to affect your other tests on your other browsers.