Tuesday, June 8, 2010

Selenium Webdriver running remotely

Recently i started developing my automation code using Selenium2 code .Most of my code is for firefox driver .I need to confess that i liked Selenium2 really there are some stability issues in comparison to Selenium1 but it is good .

Default usage of Selenium2 is that it will run server and client from same instance and that will control the browser elements,but Selenium2 provide a way to run server and client on remote location as you use to do in Selenium1.Remote Webdriver is the class which help you to run client and server separately .RemoteWebdriver provides a DriverServlet which if you add inside any servlet container you got your selenium server up.
There are few examples for this in Selenium2 wiki site .As i have never ran servlet application before so i got in to little bit of issues following that .But finally i got it running and i used jetty as servlet container .Two ways you can include that in jetty

1.Run jetty server on machine and put a war file on location pointed by jetty config file .
2.Start jetty server from your application and add you servlet class to it .(I followed this method)

I downloaded the selenium2 code and built remotewebdriver werver and client.
command to built server
./go clean selenium-java selenium-server-standalone which will result in build/remote/server/server-standalone.jar
command to built client
./go //remote/client:client:uber which will result in build/remote/client/client-standalone.jar
*go is script comes with selenium2 code and code below i got it from wiki just made few changes .

Server code
AppServer.java
=============================================
import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.webapp.WebAppContext;

import java.io.File;

import org.openqa.selenium.remote.server.DriverServlet;

public class AppServer {

public static void main(String s[]) throws Exception{
Server server = new Server();


WebAppContext context = new WebAppContext();
context.setContextPath("");
File st=new File(".");

context.setWar(st.getPath());
server.addHandler(context);

context.addServlet(DriverServlet.class, "/wd/*");

SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(3002);
server.addConnector(connector);

server.start();
}
}
================================
Add server-standalone.jar ,jetty-6.1.9.jar and jetty-util-5.1.9.jar(you can download from jetty site or selenium2 code also has in third_party folder) to classpath and run above code.
Your server will up with following message ---
2010-06-08 11:07:00.730::INFO: Started SelectChannelConnector@0.0.0.0:3002

Client example code
FirefoxClient.java
================================
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.WebDriver;

public class FirefoxClient {

public static void main(String s[]) throws Exception {

URL url=new URL("http://127.0.0.1:3002/wd");
DesiredCapabilities capabilities = new DesiredCapabilities();

// ... but only if it supports javascript
capabilities.setJavascriptEnabled(true);
capabilities.setBrowserName("firefox");

// Get a handle to the driver. This will throw an exception
// if a matching driver cannot be located
WebDriver driver = new RemoteWebDriver(url,capabilities);

// Query the driver to find out more information
//Capabilities actualCapabilities = ((RemoteWebDriver) driver).getCapabilities();

// And now use it
driver.get("http://www.google.com");
}

}
=====================================
Add client-standalone.jar to class path and run the above code .

Friday, June 4, 2010

motivation for Tester

I was thinking what use to be the biggest motivation for me to deliver good quality of software i test .Is it appreciation from my manger or from my peers or from fellow developers when they appreciate about the how good the bug i reported.

Yes these things motivate me too bu the thing which motivate me most is fixing of bug i reported .There how it goes whenever i file a bug(lets say critical) for any feature and if i try to find any other bug on that feature it is always difficult to find .Most of time i cannot go beyond my earlier bug i know it is not good for a tester but i guess it is psychological effect which does not allow me to see beyond .

So keep me motivated i need my earlier bugs to be fixed and that is the biggest motivation for any tester .Once you get your bugs fixed you will be interested in testing more, to get more issues .