Search This Blog

Thursday, February 4, 2016

Run TestNg with selenium for load testing and generate Reports from ATU framework

package testng;

import java.util.Date;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
import atu.testng.reports.ATUReports;
import atu.testng.reports.listeners.ATUReportsListener;
import atu.testng.reports.listeners.ConfigurationListener;
import atu.testng.reports.listeners.MethodListener;
import atu.testng.reports.logging.LogAs;
import atu.testng.reports.utils.Directory;
import atu.testng.reports.utils.Platform;

@Listeners({ ATUReportsListener.class, ConfigurationListener.class,
MethodListener.class })
public class Scale {


public Scale(){
System.setProperty("atu.reporter.config", "E:\\atu.properties");
}

// constructor for report parameters

public Scale(String reportName ){

ATUReports.indexPageDescription = reportName;
}
 

 
  @Test(invocationCount = 10 ,threadPoolSize =10)
public void loadTestThisWebsite() {

 HtmlUnitDriver unitDriver = new HtmlUnitDriver();
 unitDriver.setJavascriptEnabled(true);
 unitDriver.get("http://localhost/PT");
 WebElement button = unitDriver.findElement(By.name("submit"));
 button.click();
 String title = (String) unitDriver.executeScript("return document.title");
 System.out.println("Tittle  is " + title);
 if("Welcome".equals(unitDriver.getTitle()))
 {
 ATUReports.add("Load time", "PASS", true);
// Thread.sleep(2000);
 String currentDate = (new Date()).toString();
ATUReports.currentRunDescription= currentDate;
        System.out.println("Report Name "+Directory.RUNDir);
 }

 else
 Assert.fail("I have thrown Exception");

 unitDriver.quit();

}
  /*
  @AfterMethod
  public void getRunTime(ITestResult tr) {
      long time = tr.getEndMillis() - tr.getStartMillis();
      System.out.println("Time taken for the request "+ time+" millisec");
  }
 
  */

}

No comments:

Post a Comment