범위 보고서에서 메서드 이름 대신 테스트 이름을 표시하려고합니다. 해결책을 찾았으므로 @Test 주석에 테스트 이름 속성을 추가했습니다.메서드 이름 대신 범위 보고서에 테스트 이름을 표시하는 방법?
문제 1 : 보고서에서 getTestName 메소드에 대해 null이 반환되는 것을 확인합니다.
문제 2 : 테스트 이름으로 보고서의 '테스트'열에서 테스트를 만들 수 없습니다. 여기 않는 광고하다 :
테스트 = extent.createTest (..는 Thread.currentThread() getStackTrace()에() 1 .getMethodName의 toString()());
필자는 테스트 케이스와 범위 보고서 코드를 추가했습니다. 제발 제안 해주세요. 넓이 보고서에 대한
는/*============================================================================================================================
\t Test case : Verify if the save button is enabled on giving a comparison name in the save comparison form
======================================================================================*/
\t
\t
\t
@Test(testName ="Verify if the save button is enabled")
public void verifySaveButtonEnabled() {
\t
\t //test = extent.createTest(Thread.currentThread().getStackTrace()[1].getMethodName());
\t test = extent.createTest(Thread.currentThread().getStackTrace()[1].getMethodName().toString());
\t \t \t Base.getBrowser();
\t \t InvestmentsSearch.login(Base.driver);
\t \t InvestmentsSearch.InvestmentsLink(Base.driver).click();
\t \t JavascriptExecutor jse = (JavascriptExecutor)Base.driver;
\t \t jse.executeScript("window.scrollBy(0,750)", "");
\t \t InvestmentsSearch.ViewResults(Base.driver).click();
\t \t for(int i=0;i<=2;i++)
\t \t \t
\t \t {
\t \t
내 코드 :
package com.gale.precision.FundVisualizer.core;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.testng.ITestContext;
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;
import com.gale.precision.FundVisualizer.utility.SendEmail;
public class ExtentReport {
\t public static ExtentHtmlReporter htmlReporter;
\t public static ExtentReports extent;
\t public static ExtentTest test;
\t public static String suiteName;
\t @BeforeSuite
\t public static void setUp(ITestContext ctx) {
\t \t // String currentDate=getDateTime();
\t \t suiteName = ctx.getCurrentXmlTest().getSuite().getName();
\t \t htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir") + "/Reports/" + suiteName + ".html");
\t \t extent = new ExtentReports();
\t \t extent.attachReporter(htmlReporter);
\t \t extent.setSystemInfo("OS", "Windows");
\t \t extent.setSystemInfo("Host Name", "CI");
\t \t extent.setSystemInfo("Environment", "QA");
\t \t extent.setSystemInfo("User Name", "QA_User");
\t \t htmlReporter.config().setChartVisibilityOnOpen(true);
\t \t htmlReporter.config().setDocumentTitle("AutomationTesting Report");
\t \t htmlReporter.config().setReportName("testReport");
\t \t htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
\t \t htmlReporter.config().setTheme(Theme.STANDARD);
\t }
\t @AfterMethod
\t public void getResult(ITestResult result) throws IOException {
\t \t if (result.getStatus() == ITestResult.FAILURE) {
\t \t \t String screenShotPath = GetScreenShot.capture(Base.driver, "screenShotName", result);
\t \t \t test.log(Status.FAIL, MarkupHelper.createLabel(result.getTestName() + " Test case FAILED due to below issues:",
\t \t \t \t \t ExtentColor.RED));
\t \t \t test.fail(result.getThrowable());
\t \t \t test.fail("Snapshot below: " + test.addScreenCaptureFromPath(screenShotPath));
\t \t } else if (result.getStatus() == ITestResult.SUCCESS) {
\t \t \t test.log(Status.PASS, MarkupHelper.createLabel(result.getTestName() + " Test Case PASSED", ExtentColor.GREEN));
\t \t } else {
\t \t \t test.log(Status.SKIP,
\t \t \t \t \t MarkupHelper.createLabel(result.getTestName()+ " Test Case SKIPPED", ExtentColor.ORANGE));
\t \t \t test.skip(result.getThrowable());
\t \t }
\t \t extent.flush();
\t }
\t @AfterSuite
\t public void tearDown() throws Exception {
\t \t System.out.println("In After Suite");
\t \t SendEmail.execute(SendEmail.path);
\t }
\t public static String getDateTime() {
\t \t // Create object of SimpleDateFormat class and decide the format
\t \t DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
\t \t // get current date time with Date()
\t \t Date date = new Date();
\t \t // Now format the date
\t \t String currentDate = dateFormat.format(date);
\t \t String newDate = currentDate.replace('/', '_');
\t \t String newCurrentDate = newDate.replace(':', '.');
\t \t return newCurrentDate;
\t }
\t public void elementHighlight(WebElement element) {
\t \t for (int i = 0; i < 2; i++) {
\t \t \t JavascriptExecutor js = (JavascriptExecutor) Base.driver;
\t \t \t js.executeScript(
\t \t \t \t \t "arguments[0].setAttribute('style', arguments[1]);",
\t \t \t \t \t element, "color: red; border: 3px solid red;");
\t \t \t js.executeScript(
\t \t \t \t \t "arguments[0].setAttribute('style', arguments[1]);",
\t \t \t \t \t element, "");
\t \t }
\t }
\t
}
내가 선택한 영역에서 보고서에 테스트 이름을 표시합니다. 이미지를 참조하십시오
미리 감사드립니다 !!