我正在寻找一种按顺序制作测试用例的方法,以便可以一次使用登录和注销。
@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
中就可以看到
测试用例运行:2,失败:0 Check_Home_page
登录(通过)
ValidateProfilePic(通过)
要使用一次登录和注销,只需将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
}
Test -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.
}
我希望它会有所帮助。