按顺序制作测试用例,以便我可以在 TestNG 中删除多个登录调用

Make test cases in a sequence so I can remove multiple Login calls in TestNG

我正在寻找一种按顺序制作测试用例的方法,这样我就可以使用登录和注销一次。

@WebTest
@Test(groups = {"main_feature"} )
public void Check_Home_page () {
    flow.login();  //Inside login() we do assertion to find login was successful
    flow.ValidateProfilePic(); //Inside ValidateProfilePic() we do assertion to find picture section is available
}

我们将运行xml归档如下

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Smoke Result" parallel="false" thread-count="0">
<parameter name="seleniumHub" value="false" />
<parameter name="hubUrl" value="http://someurl:1144/wd/hub" />

<test name="Test Run">
    <parameter name="webPageUrl" value="http://mttesting.com" />
    <parameter name="browser" value="chrome" />
    <groups>
        <run>
            <include name="main_feature" />
        </run>
    </groups>
    <classes>
        <class name="test.HomeTest" />
    </classes>
</test>

<listeners>
    <listener class-name="selenium.DefaultCapability"></listener>
    <listener class-name="selenium.WebCapability"></listener>
    </listeners>
</suite>

执行完毕后在报告中we should可以看到喜欢

要使用一次登录和注销,只需将priority = 1用于testHomePage,将dependsOnMethods用于testProfilePicture即可。这样就可以实现一次性登录和注销。请查看以下代码:

测试-1 :

@Test(priority = 1, groups = { "main_feature" })
public void testHomePage () {
    flow.login();  //we do assertion to find login was successful
}

测试-2 :

    @Test(dependsOnMethods = { "testHomePage" }, groups = { "main_feature" })
    public void testProfilePicture () {
        flow.ValidateProfilePic(); //we do assertion to find picture section is available

// Call logout function here.
    }

希望对你有所帮助。