Sunday, December 26, 2010

Configuring Hudson to run Selenium Test Suite

To configure Hudson, follow these steps:
1. Go to Hudson Home.
2. Go to “Manage Hudson”.
3. Click on “Configure System”.
4. Go down to “Selenium Remote Control”; in htmlSuiteRunner enter the location of Selenium Remote control.7. Click on “Save”.


Create the job that runs the HTML Suite

You need to create a job that includes a “SeleniumHQ htmlSuite Run” step.

1. Go to Hudson Home.
2. Click on “New Job”.
3. Enter a value for “Job Name”.
4. Select a Job type: “Build multi-configuration project (alpha)”.
5. Click on “Ok”.
6. In “Build”, click on “Add build step”.
7. Select “SeleniumHQ htmlSuite Run”.
8. Enter the variables :
Browser: the browser that will run the test suite. For example: *firefox
startURL: start URL . For example: “http://www.google.com”
suiteFile: suite file location. For example: [location]/TestSuite.html
resultFile: HTML result file location. For example: [location]/TestResults.html

Friday, December 24, 2010

Hudson Configuration Links

http://blog.infostretch.com/?p=328

http://stackoverflow.com/questions/3294386/hudson-step-by-step-guide-to-set-up-master-and-slave-machines

Monday, December 20, 2010

Stop selenium Server(java method and through browser)

There are two ways to stop selenium server,

java method:


public void tearDown() throws Exception {
selenium.stop();
if(seleniumServer != null)
{
try{
selenium.shutDownSeleniumServer();
seleniumServer .stop();
seleniumServer = null;
}
catch(Exception e)
{
e.printStackTrace();
}
}
}


Browser Method

http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer



Hope it helps!!!

Important Links to learn locating objects.

Learn css in locating objects

http://jsfiddle.net/Flack/G8QPB/

Learn XPath

http://zvon.org/comp/r/tut-XPath_1.html#Pages~All_elements%3A_*

Code to start and stop Selenium server with eclipse setup

This is the minimum code to start the server and shutdown.


package file;

import com.thoughtworks.selenium.*;
import org.openqa.selenium.server.SeleniumServer;

public class Reset extends SeleneseTestCase {

private SeleniumServer seleniumServer;
private Selenium selenium = new DefaultSelenium( "localhost",4444,
"*chrome","http://");

public void setUp() throws Exception
{
seleniumServer = new SeleniumServer();
seleniumServer.start();
selenium.start();
}


//Test methods shd go here

public void tearDown()throws Exception
{
selenium.stop();
seleniumServer.stop();
}

}
Eclipse Configuration

create new project->enter project name->next->libraries->add selenium server.jar and junit-4.8.2.jar and click finish.

Way to export the java program to eclipse IDE.

1)After recording test case,click on options->format->Junit 3
2)Copy the method and paste it in between setup and teardown method.
3)Run->run as Junit

You can see your test case running...Enjoy!!!

Sunday, December 19, 2010

Run selenium tests in IE 8 (windows 7)

In windows 7, it is not possible to run selenium tests in IE 8. However, there is a workaround. Go to IE 8, Tools->Compatibility view Settings and then check the Display all sites in compatibility view.

Now if you type *iexplore in your code, it will run perfectly in the browser.

Thursday, December 16, 2010

Creating Test Suite in TestNG

Create a Click class with 2 methods testClick1,testClick2 and Suite called ClickSuite.xml

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">


import com.thoughtworks.selenium.*;

import org.openqa.selenium.server.*;
import org.testng.annotations.*;


public class Click {
public Selenium selenium;
public SeleniumServer seleniumserver;

@BeforeClass
public void setUp() throws Exception {
RemoteControlConfiguration rc = new RemoteControlConfiguration();
seleniumserver = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.google.co.in/");
seleniumserver.start();
selenium.start();
}

@Test
public void testClick()throws Exception {
selenium.open("/");
selenium.windowMaximize();
selenium.click("link=regexp:Advanced [s|S]earch");
selenium.waitForPageToLoad("5000");
selenium.click("id=opt-icon");
System.out.println(selenium.getLocation());
selenium.click("link=Scholar");
Thread.sleep(10000);
}


@Test
public void testClick2() throws Exception {
selenium.open("/");
selenium.type("q", "selenium link locator");
selenium.click("btnG");
}

@AfterClass
public void tearDown()throws Exception {
selenium.stop();
seleniumserver.stop();


}
}







Now make ClickTestSuite.xml

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="ClickTestSuite" verbose="3">

<test name="testClick">
<classes>
<class name="Click"></class>
</classes>
</test>

<test name="testClick2">
<classes>
<class name="Click"></class>
</classes>
</test>


</suite>




Hope it helps...