Wednesday, February 16, 2011

See Remote Webdriver in action.

Lets think about from the continuous integration perspective. You have a CI server setup using hudson bamboo or whatever you like and you want to run all your tests on different OS browser combination. How would you achieve that? Webdriver comes to your rescue. It's basic architecture is so flexible that you can get most out of it.

Here is what you have to do

You can dedicate some boxes having different OS and browsers as a remotewebdriver. All you have to do is just download the latest standalone server from here http://code.google.com/p/selenium/downloads/list When I srite this the latest distribution is http://code.google.com/p/selenium/downloads/detail?name=selenium-server-standalone-2.0b2.jar&can=2 and run the server from youtr teerminal using this command java -jar selenium-server-standalone-2.0b2.jar


Your server is now ready to act as remotewebdriver server. Now what you need is to do some client side coding. Dont worry its just few lines and thats bread and butter for you. Here is what I wrote after digging through the blogs and group posts


import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class remote {
public static void main(String[] args) throws MalformedURLException {
DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
URL remoteAddress = new URL("http://rwd:4444/wd/hub");
WebDriver driver = new RemoteWebDriver(remoteAddress, desiredCapabilities);
driver.get("http://www.google.com/");
driver.quit();
}
}

And when you run this test, you see the firefox windows pops up on your remote server and load the google page.


That give me lot of freedom to work with. I wish I could explore all the potential that this great toll has! 



2 comments:

  1. Great post as always..

    Expecting lot of tips from you!!

    ReplyDelete
  2. Hi,

    Would you please give more information?
    What do you put in the URL?
    and how to start the server automatically?
    I'm using Maven and hudson so I wanna to make things automatic.

    Thanks,

    ReplyDelete