1

Im Erweiterungsbericht möchte ich den Namen des Tests anstelle des Methodennamens anzeigen. So fand ich eine Lösung, ein Testname Attribut für @Test Annotation hinzugefügtWie wird der Testname unter Extent Report anstelle von Method Name angezeigt?

Problem 1: Im Bericht sehe ich Null für GetTestName Methode zurückgegeben werden.

Problem 2: Ich bin nicht in der Lage, einen Test in der Spalte 'Tests' im Bericht mit dem Testnamen zu erstellen. Hier ist die Linie, die das tut:

test = extent.createTest (.. Thread.currentThread() getStackTrace() 1 .getMethodName() toString());

Ich habe meinen Testfall und den Extent Report-Code hinzugefügt. Bitte vorschlagen.

/*============================================================================================================================ 
 

 
\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

Mein Code für Umfang Report:

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 
 
}

Ich möchte Testnamen im ausgewählten Bereich in dem Bericht angezeigt werden soll. Bitte verweisen Sie das Bild screenshot

Vielen Dank im Voraus!

Antwort

2

Für Problem 1 sollten Sie result.getMethod().getMethodName() verwenden, um den Namen der Testmethode zu erhalten.

Für Problem 2 wäre eine sauberere Möglichkeit, dies zu tun, eine BeforeMethod hinzuzufügen und den Extent-Test hier zu initialisieren, anstatt ihn in jeder Testmethode zu initialisieren. Sie können den Testnamen oder einen anderen Anmerkungswert mithilfe der folgenden Technik innerhalb von BeforeMethod abrufen:

Verwandte Themen