Selenium Webdriver: WebDriver is a tool for automating testing web applications, and in particular to verify that they work as expected.
TestNG: TestNG is a testing framework inspired from JUnit and NUnit but introducing some new functionalities that make it more powerful and easier to use.
TestNG is designed to cover all categories of tests: unit, functional, end-to-end, integration, etc.
Software Required: Eclipse Juno, Java 32/64 bit depends on your PC configuration, Selenium Java APIs, Selenium Browsers Drivers, Selenium Server Standalone API, JXL APIs, Java Mail APIs, Apache Ant, Saxon Parser, Test NG APIs.
Installation of Eclipse with Selenium Web driver Test NG
1.First Install Java with respect your OS configuration. For 64 Bit OS install 64 bit latest JDK , and for 32 bit OS install latest 32 bit JDK.
2.After Installing JDK set “JAVA_HOME” environment variable and set value in “path” variable also.
JAVA_HOME= C:\Program Files\Java\jdk1.7.0
Path=C:\Program Files\Java\jdk1.7.0\bin
3.Now install latest eclipse Juno with respect OS configuration and Java Configuration.
4.Now create shortcut of eclipse on desktop and open the eclipse , Now while opening eclipse it ask for workspace. So create your workspace in Work folder as “SeleniumWorkspace”.
5.Now after giving workspace your eclipse will open. Now you are set with eclipse.
6.Now create one java project, File- > New- > Java Project. Give some appropriate name for project , for sample project I am giving “TestProject”. Now your java project is created.
7.Now create one package, Right click on project then New- > Package. Here also give some appropriate package name, for sample , I am giving “Testpackage”.
8.Now right click on package and New- > Class. Give appropriate name for class as well. I am giving “Testclass”.
9.Now you are set with Project -> Package – > Class
10.Now right click on Project folder and Build Path -> Configure Build Path – > Libraries .
11.Now click on Add External Jars to add selenium webdriver jars or libraries. And select each and every jars from respective jar folder.
12.Now selenium jars are configured with project. Now go to project to write code.
13.Now selenium jars are configured with project. Now go to project to write code.
To check selenium is working fine just place below code in Main function and run it.
WebDriver seldriver;
seldriver = new FirefoxDriver();
seldriver.get(“http://google.com“);
After placing this code you will see some errors as libraries are not imported. Just mouse over where errors are showing and include those libraries which eclipse is suggesting.Those libraries are below:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;)
Now just run the project and check whether google is opening. Now write your project automation code on Selenium Web driver with Java TesNG.
Installation of TestNG in Selenium Webdriver project:
1.After successful execution of sample script mentioned in above steps now we can add Test NG plugin.
2.Go to Help-> Install New Software and paste http://beust.com/eclipse this url in “Work with” textbox.
3.Check the checkbox of TestNG and click on link “Next” now TestNG plugin installation starts.
4.After complete installation, your TestNG jar by default will store in lib folder where all other selenium jars are stored.
5.To check whether Test NG jar is added in external jar , Right click on project then Build Path- > Configure Build Path – > Check whether testng jar is added in Libraries.
6.Now you are configured test ng with eclipse now whenever you create any new project just add all jars through Add External jars button from where selenium jars presents and with those jars only testng jar also added.
Creating Standard Folder Structure for Selenium Scripts:
<Project Root Directory>
1.After Creating Java project from eclipse , one project folder is created in your workspace directory.
2.In that project folder now structure should be
lib – create one lib folder in the project folder and place all your required jars here so that while configuring selenium jars you can directly take all jars from this folder.
build.xml- Keep this file at the project root folder.
testng.xml- Keep this file at the project root folder. This also provided to you.
– This is the file where you can specify which package.class are to be run by TestNG. This file can changes with respect to your project. Open this file and give your test case name(Test case name can be anything but should be appropriate with respect to your scenario) and class name should be as given in eclipse . i.e. PackageName.ClassName
xslt – Create one xslt folder in src folder .
testng-results.xsl – This is a standard file from TestNG which specifies the format of the Better TestNG report.Keep this file at <project root directory>/src/xslt
Saxon Parser
This is a set of jar files that provides a facility to create HTML Report based on
- a) .xml file that contains data (in our case this would be testng-results.xml)
- b) .xls file that specifies the format of the HTML to be created (in our case this would be testng-results.xsl)
The HTML report generated in our case is in the directory
<project root directory>/testng-xslt
This folder actually would contain a set of HTML files, the summary report file to open is index.html and this folder is created automatically after running our project.
Saxson parser is basically the jar files (SaxonLiaison.jar, saxon-8.7.jar) add these jars in ourlib folder.