首页 > 解决方案 > 面临范围报告、日志和测试文件中的问题

问题描述

我正在开发同时需要两个浏览器的应用程序,因此我的代码同时启动两个浏览器 Chrome 和 FF,在 chrome 上执行一些测试用例,在 FF 上并行执行一些测试用例 - 当我通过执行文件执行我的代码时,它执行得很好并生成所有诉讼的范围报告单独。现在我正在尝试通过包含不止一套西装的 testng.xml(见下文)执行我的项目,我看到以下问题;1. 每个测试用例在日志下显示两次,但在范围报告中显示一次 2. 为两个套装生成一个范围报告,因为我想为每个套装生成一个报告

testng.xml

    <test name="Some Workflow Tests 1"  thread-count="5" parallel="none">
        <classes>
            <class name="Master.Websites"/>
        </classes>
    </test>


    <test name="Some Workflow Tests 2"  thread-count="5" parallel="none">
        <classes>
            <class name="Master.CompanyStore"/>
        </classes>
    </test>

请参阅下面的范围报告代码

@AfterMethod

    public void getResult(ITestResult result ) throws IOException, InterruptedException{
    /*
         System.out.println("Get Status "+ result.getStatus());
         System.out.println("Get Method with className "+ result.getMethod());
         System.out.println("Get TC Name "+ result.getName());
         System.out.println("Get test calsss Name "+ result.getTestClass());
         System.out.println("Get Test Name"+ result.getTestName());
         System.out.println("Get Method Name"+ result.isSuccess());
    */
         test = extent.createTest(result.getName());

        if(result.getStatus()==ITestResult.SUCCESS){
            test.log(Status.PASS, result.getMethod().getDescription());
            test.log(Status.PASS, MarkupHelper.createLabel(result.getName() + " Test Case is Passed", ExtentColor.GREEN));
            test.log(Status.PASS, " Please see attached screenshot");
            String screenshotPath = HelpingFunction.capture(result.getName());
            test.addScreenCaptureFromPath(screenshotPath);

            extent.flush();
            }


        if(result.getStatus()==ITestResult.FAILURE){

            test.log(Status.FAIL, MarkupHelper.createLabel(result.getName() + "Test Case is Failed due to Below Issue", ExtentColor.RED));
    /*
     * String screenshotPath = HelpingFunction.capture(result.getName());
     * test.addScreenCaptureFromPath(screenshotPath);
     */
            test.fail(result.getThrowable());
            extent.flush();
            }


        if(result.getStatus()==ITestResult.SKIP){
            System.out.print("Test cases is skipped");
             test.log(Status.SKIP, MarkupHelper.createLabel(result.getName() + "Test Case is SKIPPED", ExtentColor.YELLOW));
             test.skip(result.getThrowable());
            }                       

     }


        @AfterTest
        public void endReport(){
        driver.close();
        //extent.flush();

        //driver.get(System.getProperty("user.dir")+"/Reports/"+Suite);
        }

下面是范围报告配置的代码

public static void Property(String Suite, String RName) throws InterruptedException, AWTException, IOException{

                try {
                    ExtentHtmlReporter htmlReporter;
                    htmlReporter = new ExtentHtmlReporter("./Reports/"+Suite);

                    extent = new ExtentReports();
                    extent.attachReporter(htmlReporter);
                    extent.setSystemInfo("HostName", "Iftikhar");
                    extent.setSystemInfo("Environment", "QA");
                    extent.setSystemInfo("UserName", "Muhammad Iftikhar");
                    extent.setSystemInfo("URL", envirnment);
            //      extent.setReportUsesManualConfiguration(true);
                    htmlReporter.config().setDocumentTitle("Automation Testing Report");
                    htmlReporter.config().setReportName("Sep Report");
                    htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
                    htmlReporter.config().setTheme(Theme.DARK);
                    htmlReporter.getStartTime();
                    htmlReporter.getEndTime();

                } 
                catch (IndexOutOfBoundsException e) {
                    System.err.println("IndexOutOfBoundsException: " + e.getMessage());
                    }

                }

请参阅下面的屏幕截图以获取日志和范围报告

这就是我看到测试用例的方式

这就是我看到范围报告的方式

我在这个问题上工作了很多天,但仍然没有成功。请求所有人的帮助。谢谢你。

标签: javaselenium-webdriverselenium-extent-reporttestng.xml

解决方案


推荐阅读