Отчет об объеме не дает должного отчета о параллельном выполнении - PullRequest
0 голосов
/ 11 октября 2018

ReporterClass.Java:

package POM_Classes;

import com.aventstack.extentreports.AnalysisStrategy;
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;

public class ReporterClass {

    public static ExtentHtmlReporter html;
    public ExtentReports extent;
    public ExtentTest test, suiteTest;
    public String testCaseName, testNodes, testDescription, category, authors;

    public void startResult() {
        html = new ExtentHtmlReporter("./reports/result.html");
        html.setAppendExisting(true);
        extent = new ExtentReports();

        extent.attachReporter(html);        
    }

    /*public ExtentTest startTestModule(String testCaseName, String testDescription) {
        suiteTest = extent.createTest(testCaseName, testDescription);
        return suiteTest;
    }*/

    public ExtentTest startTestCase(String testName) {
        System.out.println(testName);
        test = extent.createTest(testName);
        return test;
    }

    public void reportStep(String desc, String status) {
        if (status.equalsIgnoreCase("PASS")) {
            test.pass(desc);
        } else if (status.equalsIgnoreCase("FAIL")) {
            test.fail(desc);
        } else if (status.equalsIgnoreCase("WARNING")) {
            test.warning(desc);
        } else if (status.equalsIgnoreCase("INFO")) {
            test.info(desc);
        }
    }

    public void endTestcase() {
        extent.setAnalysisStrategy(AnalysisStrategy.CLASS);
    }

    public void endResult() {
        extent.flush();
    }

}

Использование:

@Test   
    public void 961_NavigateToMyAlertsAndAddNewAlerts()
            throws IOException, InterruptedException, ATUTestRecorderException, APIException {

        driver = launchTargetUrl(this.getClass().getSimpleName().toString());
        startResult();
        test = startTestCase(Thread.currentThread().getStackTrace()[1].getMethodName().toString()); 
        LoginApplication(driver,transactionusername, transactionuserpassword,test);
        HomePage homePage = new HomePage(driver,test);
        homePage.MyAlerts.click();
        MyAlerts myalerts = new MyAlerts(driver,test);
        String selectedcardName;
        selectedcardName = driver.findElement(myalerts.cardName).getText().trim();
        System.out.println(selectedcardName);       
    }



    @AfterMethod
    public void afterMethod(ITestResult result) throws ATUTestRecorderException {   
        resultOfTest(result);
        endTestcase();
        endResult();
        closeBrowsers(driver);
    }

Тестовый случай, который был получен первым, имеет отчет, и если другой тестовый случай завершен, этот результат переопределяетстарый ..

Если я изменю публичный статический экстент ExtentReports;затем он поддерживает только поток, поэтому он регистрирует только один тестовый пример, а другое параллельное выполнение даже не записывается. Как решить эту проблему?

1 Ответ

0 голосов
/ 12 октября 2018

Хорошо, вот, пожалуйста.Я еще не проверял это, но это должно позволить вам использовать экстент с параллельным использованием.

Репортер:

public abstract class ReporterClass {

    private static final ExtentReports EXTENT = ExtentManager.getInstance();

    public ExtentTest test, suiteTest;
    public String testCaseName, testNodes, testDescription, category, authors;

    public synchronized ExtentTest startTestCase(String testName) {
        System.out.println(testName);
        return ExtentTestManager.createTest(testName);
    }

    public synchronized void reportStep(String desc, String status) {
        if (status.equalsIgnoreCase("PASS")) {
            ExtentTestManager.getTest().pass(desc);
        } else if (status.equalsIgnoreCase("FAIL")) {
            ExtentTestManager.getTest().fail(desc);
        } else if (status.equalsIgnoreCase("WARNING")) {
            ExtentTestManager.getTest().warning(desc);
        } else if (status.equalsIgnoreCase("INFO")) {
            ExtentTestManager.getTest().info(desc);
        }
    }

    public synchronized void endResult() {
        EXTENT.flush();
    }

    @BeforeMethod
    public synchronized void beforeMethod(Method method) {
        startTestCase(method.getName());
    }

    @AfterMethod
    public synchronized void afterMethod(ITestResult result) throws ATUTestRecorderException {   
        reportStep(result.getThrowable(), result.getStatus());
        endResult();
        closeBrowsers(driver);
    }

}

База:

public abstract class BaseClass extends ReporterClass {

    // .. abstractions

}

Утилиты экстента:

public class ExtentTestManager {

    static Map<Integer, ExtentTest> extentTestMap = new HashMap<Integer, ExtentTest>();
    private static final ExtentReports EXTENT = ExtentManager.getInstance();

    public static synchronized ExtentTest getTest() {
        return extentTestMap.get((int) (long) (Thread.currentThread().getId()));
    }

    public static synchronized ExtentTest createTest(String testName) {
        return createTest(testName, "");
    }

    public static synchronized ExtentTest createTest(String testName, String desc) {
        ExtentTest test = EXTENT.createTest(testName, desc);
        extentTestMap.put((int) (long) (Thread.currentThread().getId()), test);

        return test;
    }

}


public class ExtentManager {

    private static ExtentReports extent;

    public synchronized static ExtentReports getInstance() {
        if (extent == null) {
            createInstance("reports/extent.html");
        }

        return extent;
    }

    public synchronized static ExtentReports createInstance(String fileName) {
        ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(fileName);
        htmlReporter.config().setTestViewChartLocation(ChartLocation.BOTTOM);
        htmlReporter.config().setChartVisibilityOnOpen(true);
        htmlReporter.config().setTheme(Theme.STANDARD);
        htmlReporter.config().setDocumentTitle(fileName);
        htmlReporter.config().setEncoding("utf-8");
        htmlReporter.config().setReportName(fileName);
        htmlReporter.setAppendExisting(true);

        extent = new ExtentReports();
        extent.setAnalysisStrategy(AnalysisStrategy.CLASS);
        extent.attachReporter(htmlReporter);

        return extent;
    }

}   

Наконец, твои тонкие тесты.Обратите внимание, что здесь 0 строк кода репортера - см. ReporterClass.

public class MyTestsClass extends BaseClass {
    @Test   
    public void 961_NavigateToMyAlertsAndAddNewAlerts()
            throws IOException, InterruptedException, ATUTestRecorderException, APIException {
        driver = launchTargetUrl(this.getClass().getSimpleName().toString());
        LoginApplication(driver,transactionusername, transactionuserpassword,test);
        HomePage homePage = new HomePage(driver,test);
        homePage.MyAlerts.click();
        MyAlerts myalerts = new MyAlerts(driver,test);
        String selectedcardName;
        selectedcardName = driver.findElement(myalerts.cardName).getText().trim();
        System.out.println(selectedcardName);       
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...