Popular Posts

Wednesday, 2 March 2011

Selenium Grid Example - Part3

 Selenium Grid example with Junit:

Pre-requisites:
a. Proper set up of Ant on your box
b. Selenium Grid
c. Proper setup of Jdk on your box
d. Some jar files what I will mention during example setup



Project Setup:
1. Create a project workspace, you need to maintain folder structure like below:
gridprojectwithJunit
- build
- bin
- src, this folder should have two sub folders ‘tests’ and ‘testsuites’
- lib
See the below screen to see above workspace:


2. Put following jar files into your lib folder:
a. selenium-java-client-driver.jar
b. ant-junit.jar
c. parallel-junit.jar
d. junit-4.7.jar
See the following screen just for reference:

3. Into the src\tests folder, create at least 4-5 tests what you want to execute in parallel.
4. Create a testsuite into src\testsuites folder, see the following codes only you need to change the test cases name from what you have created:

package testsuites;import org.kohsuke.junit.ParallelTestSuite;import junit.framework.Test;import junit.framework.TestSuite;import tests.test1;import tests.test2;import tests.test3;import tests.test4;//test1, test2, test3, test4 should be test names created by you.public class Workflow1 {//workflow1 is the test suite namepublic static Test suite() {TestSuite suite = new ParallelTestSuite();suite.addTestSuite(test1.class);suite.addTestSuite(test2.class);suite.addTestSuite(test3.class);suite.addTestSuite(test4.class);//in above four lines, test1, test2, test3 and test4 should be the tests name created by youreturn suite;}public static void main(String[] args) {junit.textui.TestRunner.run(suite());}}



5. Create a build.xml file, to execute the junit tests, see the below contents which you need to put in build.xml file from your side,
Starting point:
<project name="test" basedir="."><property name="RELEASE_ROOT" value=".."/><property name="SRC" value="${RELEASE_ROOT}/src"/><property name="LIB" value="${RELEASE_ROOT}/lib"/><property name="BIN" value="${RELEASE_ROOT}/bin"/><property name="BUILD" value="${RELEASE_ROOT}/build"/><path id="test.classpath"><pathelement location="${BIN}"/><fileset dir="${LIB}"><include name="**/*.jar"/></fileset></path><target name="init"><delete dir="${BIN}"/><mkdir dir="${BIN}"/></target><target name="compile" depends="init"><javac source="1.5" srcdir="${SRC}" fork="true" destdir="${BIN}" debug="true" optimize="true" includeAntRuntime="No" deprecation="false" verbose="${javac.verbose}"><classpath><pathelement path="${BIN}"></pathelement><fileset dir="${LIB}"><include name="**/*.jar"/></fileset></classpath></javac></target><target name="run-tests-in-parallel" depends="compile"><junit printsummary="yes" haltonfailure="yes"><classpath><pathelement location="${BIN}"/><fileset dir="${LIB}"><include name="**/*.jar"/></fileset></classpath><test name="testsuites.Workflow1" haltonfailure="no" outfile="result"><formatter type="xml"/></test></junit><junitreport todir="."><fileset dir="."><include name="result.xml"/></fileset><report format="frames" todir="./report/html"/></junitreport></target><target name="run-batch-test" depends="compile"><junit printsummary="yes" haltonfailure="yes"><classpath><pathelement location="${BIN}"/><pathelement location="${SRC}"/><fileset dir="${LIB}"><include name="**/*.jar"/></fileset></classpath><formatter type="xml" usefile="true"/><batchtest fork="yes" todir="."><fileset dir="${SRC}"><include name="**/OrangeHrm.java"/></fileset></batchtest></junit><junitreport todir="."><fileset dir="."><include name="TEST*.xml"/></fileset><report format="frames" todir="./report/html"/></junitreport></target><import file="D:\SeleniumTool\junitpdfreport_1_1_prerelease_20080220/build-junitpdfreport.xml"/><target name="testreport-pdf"><junitpdfreport todir="." styledir="default"><fileset dir="C:\Documents and Settings\360logica\workspace\TestProjectGenerateReport\build"><include name="TEST-TestSuites.xml"/></fileset></junitpdfreport></target> </project>

Ending point

6. It’s time to execute our example, follow the below execution steps:
a. Launch selenium grid hub like in above example
b. Create 4 instances of firefox RC server instances through grid
c. Open a new command terminal and go with your build.xml file, see the below screen:



d. Execute our ant target to run all four tests in parallel, run the command
Ant run-tests-in-parallel
See the below screen:


e. After execution of command, you would see that all your tests will be running in parallel on four launched firefox RC instances.

f. You also can see the execution result by opening the index.html file from your project path \\gridprojectwithJunit\build\report\html
See the result as below in your default browser:


Here is the updated embedded video file:

SeleniumGrid_Example_Part3-updated
Uploaded by vipingupta. - Videos of the latest science discoveries and tech.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...