失败后,TestNG不会继续执行测试 [英] TestNG does not continue execute tests after failure
问题描述
我有一个带有页面对象模型的测试自动化框架. 我所有的测试都位于同一包中的单独类中.
I have test automation framework with a page object model. All my test are located in separate classes in same package.
在testng.xml中,我有
In testng.xml i have
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Smoke Test">
<test name="SmokeTest">
<classes>
<class name="name.test1"/>
<class name="name.test2"/>
<class name="name.test3"/>
</classes>
</test>
</suite>
问题是运行TestNG.xml后,如果第一个测试失败,它将停止测试执行.但是我想继续执行所有测试用例.
Problem is that after running TestNG.xml if the 1st test will fail, it will stop test execution. But i want to continue executing of all test cases.
我在项目上使用Jenkins,如果其中一项测试失败,它将立即停止执行.
I use Jenkins on my project and if one of the tests are failed it stops execution immediately.
测试示例
public class LoginTestTest {
public AndroidDriver<AndroidElement> driver;
public AOWebClient aoWebClient;
AOWebClient aoWeb;
public LoginTestTest(AndroidDriver<AndroidElement> driver, AOWebClient aoWeb){
this.driver = driver;
this.aoWeb = aoWeb;
PageFactory.initElements(new AppiumFieldDecorator(driver), this);
}
public LoginTestTest() {
}
SoftAssert softAssert = new SoftAssert();
@BeforeClass
public void setUp() throws Exception {
driver = DesiredCapabilitiesSetup.startAppiumServer();
aoWebClient = DesiredCapabilitiesSetup.getAOWeb();
LogIn logIn = new LogIn(driver,aoWebClient);
logIn.logIn();
}
@org.testng.annotations.Test
public void goToSettings() throws InterruptedException {
HeaderMenu header = new HeaderMenu(driver,aoWeb);
HamburgerMenuList ham = new HamburgerMenuList(driver);
header.clickHamburgerButton();
header.clickHamburgerButton();
header.editButtonClick();
softAssert.assertAll();
}
@AfterClass
public void tearDown(ITestResult result) throws Exception {
if (result.getStatus() == ITestResult.FAILURE) {
TakeScreenshot screenshot = new TakeScreenshot();
screenshot.TakeScreenshot("screenshots/");
}
LogOut logOut = new LogOut(driver,aoWeb);
logOut.logOut();
}
}
如果我的测试在@Test
中失败,它将永远不会继续使用@AfterClass
方法.
我希望如果@Test
失败,它将继续使用@AfterClass
方法,并且在此类之后,继续执行testng.xml
中其他类的测试.
If my test will fail in @Test
it will never continue to @AfterClass
method.
And I want that if @Test
fail it will continue to @AfterClass
method and After This Class continue executes test from other classes from testng.xml
.
推荐答案
您在xml中的套件标签应包含configfailurepolicy ="continue".这告诉testng,即使一个类中的配置失败,您仍然希望在该套件中运行其他类.请参见文档中的"configfailurepolicy".
Your suite tag in your xml should include configfailurepolicy="continue". This tells testng that even though a config failed in one class, you still want to run other classes in that suite. See "configfailurepolicy" in the documentation.
因此您的xml将变为:
So your xml would become:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Smoke Test" configfailurepolicy="continue">
<test name="SmokeTest">
<classes>
<class name="name.test1"/>
<class name="name.test2"/>
<class name="name.test3"/>
</classes>
</test>
</suite>
这篇关于失败后,TestNG不会继续执行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!