问题描述
如果@BeforeSuite批注中满足条件,是否可以退出整个测试套件?也许可以调用@AfterSuite并绕过整个测试吗?
Is there a way to quit the entire test suite if a condition is met in the @BeforeSuite annotation? Maybe a way to call the @AfterSuite and bypass the entire test?
我在@BeforeSuite中进行数据库调用.如果查询返回任何结果,我会发送一封电子邮件,现在想终止整个测试套件.
I make a database call in the @BeforeSuite. If the query returns any results, I send an email and now am wanting to kill the entire test suite.
我尝试过System.exit(1);
和org.testng.Assert.fail("There are unpaid invoices");
,但是它们都不终止整个套件.我的脚本设置为并行运行类,并且当我从test.xml文件运行测试时,每个类都会尝试启动并打开一个窗口,然后立即将其关闭.
I have tried System.exit(1);
and org.testng.Assert.fail("There are unpaid invoices");
, but neither of those terminate the entire suite. My scripts are setup to run classes in parallel and when I run the test from the test.xml file, each class tries to start and opens a window and then immediately closes it.
仅供参考,直到@BeforeClass或@BeforeMethod(取决于我为并行方法或类创建的开关),才会创建驱动程序.因此,在所有现实中,甚至都不应尝试打开浏览器窗口.
FYI, the drivers do not get created until the @BeforeClass or @BeforeMethod (depending on the switch I created for parallel methods or classes). So in all reality, there should never even be an attempt to open a browser window.
推荐答案
尝试new SkipException("message");
如果提供的条件不正确,这将跳过测试.
try new SkipException("message");
this will skip the tests if the provided condition is not true.
这篇关于TestNG-如果满足条件,如何从BeforeSuite注释中强制结束整个测试套件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!