gpt4 book ai didi

java - 具有多个类别的范围报告

转载 作者:行者123 更新时间:2023-12-02 12:38:02 26 4
gpt4 key购买 nike

来自不同类别的所有测试用例均未使用范围报告运行。范围报告中的一类第二类是忘记密码第三类是登录我想同时运行两个类的登录名和密码,并希望为两者创建单个报告

       package Pedagogy;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.testng.annotations.Test;
import com.relevantcodes.extentreports.LogStatus;
import common.generalmail2;




public class forgotPassword extends generalmail2{

ArrayList<String> pathlist=new ArrayList<String>();
String btn = "";
String path= "";
generalmail2 generalMail = new generalmail2();



@Test
public void Regestration_test() throws Exception {
Thread.sleep(2000);
logger = report.startTest("ForgotPassword");
getDriver().findElement(By.id("forgotpassword")).click();
getLogger().log(LogStatus.PASS ,"got the forgot password id");
getLogger().log(LogStatus.INFO , "forgotpassword page is open");
validationTest("Sheet3");

}

public void validationTest(String sheet) throws Exception {

Selenium_read obj = new Selenium_read();
ArrayList<ArrayList> tablelist=obj.readExcel(sheet);
System.out.println(tablelist);
for (ArrayList<String> row : tablelist){
Forgotpassword_method(row.get(0),row.get(1));
}

Forgotpassword_method1();
Forgotpassword_method2();
}

public void Forgotpassword_method(String email, String snapshot)throws Exception {


WebElement email_id= getDriver().findElement(By.xpath(".//*[@id='forgotPasswordForm']/div[1]/div/input"));
email_id.clear();
String myWindowHandle = getDriver().getWindowHandle();
getDriver().switchTo().window(myWindowHandle);
WebElement email_id1= getDriver().findElement(By.xpath(".//*[@id='forgotPasswordForm']/div[1]/div/input"));
email_id1.sendKeys(email);
getDriver().findElement(By.xpath(".//*[@id='forgotPasswordForm']/div[2]/div/button[2]")).click();

}

public void Forgotpassword_method1()throws Exception {

getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
getDriver().manage().window().maximize();
getDriver().get("https://mail.google.com/");
getDriver().findElement(By.id("identifierId")).sendKeys("kunal@pedagogy.study");
getDriver().findElement(By.xpath(".//*[@id='identifierNext']/content/span")).click();
Thread.sleep(4000);
getDriver().findElement(By.xpath(".//*[@id='password']/div[1]/div/div[1]/input")).sendKeys("pedagogy@123");
Thread.sleep(4000);
getDriver().findElement(By.id("passwordNext")).click();
Thread.sleep(4000);
getLogger().log(LogStatus.INFO , "successfully open email");
List<WebElement> email = getDriver().findElements(By.cssSelector("div.xT>div.y6>span>b"));
for(WebElement emailsub : email){
if(emailsub.getText().equals("Pedagogy : Password Reset") == true){

emailsub.click();
break;
}
}
Thread.sleep(4000);
String mytext = getDriver().findElement(By.partialLinkText("http://52.89.55.95:3000/changepassword?email=kunal@pedagogy.study&token=")).getText();
getDriver().get(mytext);
}

public void Forgotpassword_method2()throws Exception {

getDriver().manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
getDriver().findElement(By.xpath(".//*[@id='password']")).sendKeys("Pedagogy@123");
getDriver().findElement(By.xpath(".//*[@id='confirmPassword']")).sendKeys("Pedagogy@123");
getDriver().findElement(By.xpath("html/body/app-root/app-changepassword/div/div/div[2]/form/div[3]/button")).click();
getLogger().log(LogStatus.INFO , "Successfully change the password");


}


public void switchToTab() {
getDriver().findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"\t");
getDriver().switchTo().defaultContent();
}



public void setButton(String str){
btn=str;
}


public void setPath(String str){
path=str;
}

}



package Pedagogy;


import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.Test;
import common.generalmail2;




public class Registration extends generalmail2 {

ArrayList<String> pathlist=new ArrayList<String>();
String btn = "";
String path= "";
generalmail2 generalMail = new generalmail2();



@Test
public void Regestration_test() throws Exception {
logger = report.startTest("SignUp");
getDriver().findElement(By.xpath(".//*[@id='wrapper']/div/div/div/a")).click();
validationTest("Sheet1");

}


public void regNull() {
getDriver().findElement(By.id("firstname")).clear();
getDriver().findElement(By.id("lastname")).clear();
getDriver().findElement(By.xpath("html/body/app-root/app-register/div/div/div/div[2]/form/div[3]/ng2-datepicker/div/div/input")).clear();
getDriver().findElement(By.name("radio1")).isSelected();
Select dropdown = new Select(getDriver().findElement(By.id("countrycode")));dropdown.selectByVisibleText("India");
getDriver().findElement(By.id("contact")).clear();
getDriver().findElement(By.id("email")).clear();
getDriver().findElement(By.id("agree")).click();
getDriver().findElement(By.id("submitBtn")).click();

}

public void validationTest(String sheet) throws Exception{
// Null Validations
regNull();

Selenium_read obj = new Selenium_read();
ArrayList<ArrayList> tablelist=obj.readExcel(sheet);
System.out.println(tablelist);
for (ArrayList<String> row : tablelist){
regMethod(row.get(0),row.get(1),row.get(2),row.get(3),row.get(4),row.get(5));
}

registration_method();
Createpassword_method();
}


public void regMethod(String firstName ,String lastName ,String dob, String contact,String email , String snapshot ) throws Exception {
regNull();
Thread.sleep(4000);
getDriver().findElement(By.id("firstname")).sendKeys(firstName);
getDriver().findElement(By.id("lastname")).sendKeys(lastName);
getDriver().findElement(By.xpath("html/body/app-root/app-register/div/div/div/div[2]/form/div[3]/ng2-datepicker/div/div/input")).sendKeys(dob);
getDriver().findElement(By.id("one")).isEnabled();
getDriver().findElement(By.id("contact")).sendKeys(contact);
getDriver().findElement(By.id("email")).sendKeys(email);
getDriver().findElement(By.id("agree")).click();
getDriver().findElement(By.id("submitBtn")).click();
snapshot(snapshot);
regNull();
}
public void registration_method()throws Exception {

getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,Keys.RETURN);
getDriver().manage().window().maximize();
getDriver().get("https://mail.google.com/");
getDriver().findElement(By.id("identifierId")).sendKeys("kunal@pedagogy.study");
getDriver().findElement(By.xpath(".//*[@id='identifierNext']/content/span")).click();
Thread.sleep(4000);
getDriver().findElement(By.xpath(".//*[@id='password']/div[1]/div/div[1]/input")).sendKeys("pedagogy@123");

Thread.sleep(4000);
getDriver().findElement(By.id("passwordNext")).click();

Thread.sleep(4000);
List<WebElement> email = getDriver().findElements(By.cssSelector("div.xT>div.y6>span>b"));

for(WebElement emailsub : email){
if(emailsub.getText().equals("Pedagogy : Password Reset") == true){

emailsub.click();
break;
}
}

Thread.sleep(4000);

String mytext = getDriver().findElement(By.partialLinkText("http://52.89.55.95:3000/changepassword?email")).getText();
getDriver().get(mytext);
}


public void Createpassword_method()throws Exception {
getDriver().manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
getDriver().findElement(By.xpath(".//*[@id='password']")).sendKeys("Pedagogy@123");
getDriver().findElement(By.xpath(".//*[@id='confirmPassword']")).sendKeys("Pedagogy@123");
getDriver().findElement(By.xpath("html/body/app-root/app-changepassword/div/div/div[2]/form/div[3]/button")).click();


}


public void setButton(String str){
btn=str;
}

public void setPath(String str){
path=str;
}

public void snapshot(String name) throws IOException {
File screenshot = ((TakesScreenshot)getDriver()).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshot, new File("D:\\PEDAGOGY SELENIUM PROJECT\\selenium\\screenshot signup\\"+path+name));
pathlist.add("D:\\PEDAGOGY SELENIUM PROJECT\\selenium\\screenshot\\"+path+name);


}
}





<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">

<test name="Test2">
<classes>
<class name="Pedagogy.login"/>
<class name="Pedagogy.forgotPassword"/>
<class name="Pedagogy.Registration"/>
</classes>


</test>



</suite>


package common;

import static org.testng.Assert.assertTrue;


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.ITestResult;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;

public class generalmail2 {

public ExtentReports report=new ExtentReports("D:\\KETAN\\ProjectReport.html");;
public static ExtentTest logger;



public ExtentTest getLogger() {
return logger;
}


public void setLogger(ExtentTest logger) {
this.logger = logger;
}


WebDriver driver ;
public WebDriver getDriver() {
return driver;
}


public void setDriver(WebDriver driver) {
this.driver = driver;
}


@BeforeSuite
public void OpenBrowser()
{
System.setProperty("webdriver.chrome.driver", "D://KETAN//selenium//chromedriver_win32//chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
logger = report.startTest("Pedagogy");
driver.get("http://52.89.55.95:3000/");
logger.log(LogStatus.INFO , "Appliacation is up and running");


}


public ExtentReports getReport() {
return report;
}


public void setReport(ExtentReports report) {
this.report = report;
}


@AfterMethod
public void tearDown(ITestResult result)
{
if (result.getStatus()==ITestResult.FAILURE)
{
String screenshotpath = generalScreenshot.captureScreenshot(driver, result.getName());
String image = logger.addScreenCapture(screenshotpath);
logger.log(LogStatus.FAIL , "failed", image);
}

report.endTest(logger);
report.flush();


}


@AfterSuite
public void openReport(){
driver.get("D:\\KETAN\\ProjectReport.html");

}

}

最佳答案

您需要创建一个单独的类来声明范围报告相关的类,并且需要扩展该类以访问需要为测试方法生成报告的每个类中的这些类的对象。我已经创建了一个类(即 BaseTest)来声明范围报告相关类,现在我将创建另外 2 个类(即 ClassA 和 ClassB)来访问这些对象,并将从这两个类创建一个报告。

这是 BaseTest 类:-

import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.markuputils.ExtentColor;
import com.aventstack.extentreports.markuputils.MarkupHelper;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
import com.aventstack.extentreports.reporter.configuration.ChartLocation;
import com.aventstack.extentreports.reporter.configuration.Theme;

public class BaseTest{

public static ExtentHtmlReporter htmlReporter;
public static ExtentReports extent;
public static ExtentTest test;

@BeforeSuite
public void setUp()
{
htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir") +"/test-output/extentReport.html");
extent = new ExtentReports();
extent.attachReporter(htmlReporter);

extent.setSystemInfo("OS", "Mac Sierra");
extent.setSystemInfo("Host Name", "Test");
extent.setSystemInfo("Environment", "QA");
extent.setSystemInfo("User Name", "Napendra Singh");

htmlReporter.config().setChartVisibilityOnOpen(true);
htmlReporter.config().setDocumentTitle("Extent report");
htmlReporter.config().setReportName("Final Report");
}

@AfterMethod
public void getResult(ITestResult result)
{
if(result.getStatus() == ITestResult.FAILURE)
{
test.log(Status.FAIL, MarkupHelper.createLabel(result.getName()+" Test case FAILED due to below issues:", ExtentColor.RED));
test.fail(result.getThrowable());
}
else if(result.getStatus() == ITestResult.SUCCESS)
{
test.log(Status.PASS, MarkupHelper.createLabel(result.getName()+" Test Case PASSED", ExtentColor.GREEN));
}
else
{
test.log(Status.SKIP, MarkupHelper.createLabel(result.getName()+" Test Case SKIPPED", ExtentColor.ORANGE));
test.skip(result.getThrowable());
}
}

@AfterSuite
public void tearDown(){
extent.flush();
}
}

这是 ClassA 类:-

import org.testng.Assert;
import org.testng.annotations.Test;

public class ClassA extends BaseTest{

@Test
public void classA(){
//Add your implementation
}
}

这是 ClassB 类:-

import org.testng.Assert;
import org.testng.annotations.Test;

public class ClassB extends BaseTest{

@Test
public void classB(){
//Add your implementation
}
}

现在您可以使用 testng.xml 文件运行这两个类,并将获得这两个类的综合报告。

关于java - 具有多个类别的范围报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45074253/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com