Headless Testing using selenium and testNG
Posted By : Dinesh Dhiman | 28-Apr-2015
Installation of phantomjs browser :
-
sudo apt-get update
-
sudo apt-get install phantomjs -version 1.9.8 or sudo apt-get install phantomjs - latest
-
sudo apt-get install build-essential chrpath libssl-dev libxft-dev
-
sudo apt-get install libfreetype6 libfreetype6-dev
- sudo apt-get install libfontconfig1 libfontconfig1-dev
How we use phantomjs browser for headless testing :
-
Make a new java project .
-
Add all selenium , testgn , phantomjs jar file .
-
After then make a testNG class.
package com.app; import java.io.FileInputStream; import java.io.InputStream; import java.util.List; import java.util.Properties; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.phantomjs.PhantomJSDriver; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; public class Login { WebDriver driver = new PhantomJSDriver(); String url = “any url” @BeforeTest public void operBrowser() { driver.get(url); } @Test(priority=0) public void login() { driver.findElement(By.linkText("Login")).click(); driver.findElement(By.name("email")).sendKeys("your Id ”); driver.findElement(By.id("login_password")).sendKeys("your password"); driver.findElement(By.name("login-form")).submit(); } @AfterTest public void closeBrowser() { driver.close(); } }
4. Make an xml file to run the test cases.
5. Run xml as testNG .
After execution of test suite you can see the eclipse console like this -
This is the result report of running suite :
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Dinesh Dhiman
Dinesh is good in java and grails with having extra knowledge in AngularJS , HTML ,SQL , Selenium