org.testng.annotations.AfterSuite似乎应该在它之前解雇

时间:2018-02-14 16:52:02

标签: java selenium testng

据我了解, org.testng.annotations.AfterSuite应该在整个套件的末尾触发,但它会在单个类的末尾被触发。

当然这是错的?

我以为我们在这里有一个层面 - 套房>测试>类。

这是我的testng.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="tests">
    <listeners>
        <listener class-name="listeners.TestNGCustomReportListener" />
    </listeners>
    <test thread-count="5" name="firefoxTest">
        <parameter name="browser" value="firefox" />

        <classes>
            <class name="tests.loginTests.LoginTest" />
            <class name="tests.loginTests.AutoLogOutTest" />
            <class name="tests.loginTests.AutoLogOutWithRestApi" />
            <class name="tests.loginTests.ChangePasswordTest" />
            <class name="tests.loginTests.SwitchCustomerProjects" /> 
            <class name="tests.loginTests.ForgotPasswordResetTest" />
            <class name="tests.loginTests.EditUserNameTest" />

            <class name="tests.layersTests.EnableLayerTest" />
            <class name="tests.layersTests.EnableLayerStyleTest" />
            <class name="tests.layersTests.ChangeLayerNameTest" />
            <class name="tests.layersTests.ChangeStyleNameTest" />
            <class name="tests.layersTests.ChangeStyleColourTest" />

            <class name="tests.networks.SwitchNetworks" />

            <class name="tests.basemaps.SwitchBasemaps" />
            <class name="tests.basemaps.AddWmsLayer" />
            <class name="tests.basemaps.DeleteBasemap" />

            <class name="tests.jobs.ViewJobsLayer" />

            <class name="tests.defectsTests.ViewDefectsLayerTest" />
            <class name="tests.defectsTests.CreateDefectTest" />
            <class name="tests.defectsTests.CreateDefectNewCaller" />
            <class name="tests.defectsTests.CreateDefectExistingCaller" />
            <class name="tests.defectsTests.ViewAllDefects" />
            <class name="tests.defectsTests.DeleteDefectTest" />
            <class name="tests.defectsTests.ViewDefectDetails" />
            <class name="tests.defectsTests.EditDefectDetails" />

            <class name="tests.streetlighting.ViewStreetlightsLayer" />

        </classes>
    </test>
</suite> 

以下段落是错误的&#39;调用

    @AfterSuite
    public void afterSuite() {
    debug.print(thisClass + " afterSuite.");
    Common.myPrint(thisClass + " driver details " + driver.toString());
    try {
        debug.print(thisClass + " afterSuite. Final log out.");
        LogoutUtility.logout(driver, loggedInPage);
        Common.printLine();
        debug.print("\n" + thisClass + " Clean up.");
        deleteAllCookies();
        driverClose();
    }catch(Exception e) {
        System.err.println(thisClass+" error trying to logout. " + e.getMessage());
        e.printStackTrace();
    }
}

报告:

[15:31:56] :     [Step 2/4]    [testng] pageObjects.LoggedInPage                 Logged in page loaded
[15:31:56] :     [Step 2/4]    [testng] tests.loginTests.LoginTest               ASSERT: Is logged in true
[15:31:56] :     [Step 2/4]    [testng] 
[15:31:56] :     [Step 2/4]    [testng] listeners.CustomTestListener             PASSED TEST
[15:31:56] :     [Step 2/4]    [testng] listeners.CustomTestListener             tests.loginTests.LoginTest
[15:31:56] :     [Step 2/4]    [testng] ------------------------------------------------------------------------------------------------------------------------------
[15:31:56] :     [Step 2/4]    [testng] crossBrowserFramework.CrossBrowserTest   afterTest. 
[15:31:56] :     [Step 2/4]    [testng] listeners.CustomTestListener             FINISH.
[15:31:56] :     [Step 2/4]    [testng] Command line test
[15:31:56] :     [Step 2/4]    [testng] crossBrowserFramework.CrossBrowserTest   afterSuite.
[15:31:56] :     [Step 2/4]    [testng] crossBrowserFramework.CrossBrowserTest   driver details FirefoxDriver: firefox on XP (52c39e00-80ae-4576-a0f4-52d4a25442b5)
[15:31:56] :     [Step 2/4]    [testng] crossBrowserFramework.CrossBrowserTest   afterSuite. Final log out.

理想情况下,我不想登录&amp;为每个班级。整个套房只需一次。

0 个答案:

没有答案