Headless Testing using selenium and testNG

Posted By : Dinesh Dhiman | 28-Apr-2015

Installation of phantomjs browser  :

  1. sudo apt-get update

  2. sudo apt-get install phantomjs -version 1.9.8  or sudo apt-get install phantomjs - latest

  3. sudo apt-get install build-essential chrpath libssl-dev libxft-dev

  4. sudo apt-get install libfreetype6 libfreetype6-dev

  5. sudo apt-get install libfontconfig1 libfontconfig1-dev

 

How we use phantomjs browser  for headless testing :

  1. Make a new java project .

  2. Add all selenium , testgn , phantomjs jar file .

  3. 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 :

 

 
Thanks
Related Tags

About Author

Author Image
Dinesh Dhiman

Dinesh is good in java and grails with having extra knowledge in AngularJS , HTML ,SQL , Selenium

Request for Proposal

Name is required

Comment is required

Sending message..