Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute Selenium 2 Tests Against Remote Browser

I'd like to have a configuration where my build server runs a NUnit test that opens and drives a browser on a remote machine. What would be the best way to accomplish this?

It was easy to do in Selenium 1, because the java proxy server sat between your tests and the browser. In Selenium 2, your tests communicate directly with the browser (at least in IE and Firefox).

Is there a good way to do this? Possibly with a WCF service or something?

like image 241
Nathan Roe Avatar asked Oct 07 '10 23:10

Nathan Roe


2 Answers

You need to get the Standalone Selenium Server (current is selenium-server-standalone-2.0a6.jar) from http://code.google.com/p/selenium/. Then start is with the command line on the remote machine (you need Java installed there):

java -jar selenium-server-standalone-2.0a6.jar

Also there's a .NET implementation of the server, but its version is behind the Java one

Then you should use the RemoteWebDriver:

IWebDriver driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4444/wd/hub"),DesiredCapabilities.InternetExplorer());

And then use the driver as you do in your "local" tests

More info:

http://code.google.com/p/selenium/wiki/RemoteWebDriver

http://www.google.com/codesearch/p?hl=en#CJyJMZi8hYc/trunk/remote/client/src/csharp/webdriver-remote/RemoteWebDriver.cs

http://code.google.com/p/selenium/wiki/RemoteWebDriverServer

like image 158
Sergii Pozharov Avatar answered Oct 14 '22 18:10

Sergii Pozharov


C# example of doing this is listed in below link. The driver files for firefox comes inbuilt with selenium server jar thats required to be running on remote machine. But chrome driver and internet explorer driver location needs to be passed to server with options -Dwebdriver.ie.driver and -DWebdriver.chrome.driver on the start-up

For more details refer this link How to invoke/run different type of web driver browser using remote webdriver in C#

The basic code is shown below

        [Test]
    public void Test_OpeningHomePageUsingIE()
    {
        // Step b - Initiating webdriver
        IWebDriver driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4444/wd/hub"), DesiredCapabilities.InternetExplorer());
        //Step c : Making driver to navigate
        driver.Navigate().GoToUrl("http://docs.seleniumhq.org/");       
        //Step d 
        IWebElement myLink = driver.FindElement(By.LinkText("Download"));
        myLink.Click();
        //Step e
        driver.Quit();
    }
like image 35
Shambu Avatar answered Oct 14 '22 16:10

Shambu