我使用JUnit进行自动化测试,将上下文更改为混合应用程序,经过测试后,我将生成输出excel文件并得到结果。我对自动化很陌生,找到了一种方法,如果没有找到什么东西,等等,使用try / catch块来填充excel文件的结果。我认为,所有的东西看起来都很有魅力,但是当有一个长测试用例(有很多测试步骤)时,我就有问题了,如果有什么东西进入了"catch块“,那么excel文件中的测试步骤在”失败“测试步骤之后被标记为"Pass”。我想解决这个问题。如果某个测试步骤被标记为"FAIL“,那么他下面的所有其他测试步骤是否也会被标记为"FAIL”之类的。
public class LoginProcess extends Settings {
static SXSSFWorkbook workbook;
public static String[] columns = { "TestStep", "ExpectedResult", "Pass/Fail" };
public static List<TestCaseForExcel> testCases = new ArrayList<>();
@Before
public void BeforeTest() throws MalformedURLException, InterruptedException {
Capabilities();
}
@Test
public void TC_1_LoginProcess() throws MalformedURLException, InterruptedException {
try {
driver.findElement(By.xpath("/html/body/div[2]")).isDisplayed();
testCases.add(new TestCaseForExcel("Opened Customer application", "Splash screen opened", "PASS"));
} catch (Exception e) {
testCases.add(new TestCaseForExcel("Opened Customer application", "Splash screen opened", "FAIL"));
}
// Click on Login Button
try {
driver.findElement(By.className("button-simple")).click();
testCases.add(new TestCaseForExcel("Press Login button", "Login screen opened", "PASS"));
} catch (Exception e ) {
testCases.add(new TestCaseForExcel("Press Login button", "Login screen openedd", "FAIL"));
}
} 在这种情况下,如果xpath中断,且元素未显示,则第二个测试步骤被写为"PASS“,由于第一个测试步骤”失败“,它甚至没有被正确检查。
发布于 2018-04-26 17:32:44
如果某个测试步骤被标记为"FAIL“,那么他下面的所有其他测试步骤是否也会被标记为"FAIL”之类的?
在测试开始时,声明一个布尔值作为您的标志,并包装每个try catch。
var keepGoing = true;
if (keepGoing) {
try {
// your code
} catch {
// your code
keepGoing = false;
}
}
// rinse repeat这就完成了任务,但我不认为这是最佳实践。这就是断言出现的地方。如果您断言一个条件而它失败了,则测试方法将停止它的跟踪(通过抛出一个异常,然后将其记录下来)。
https://sqa.stackexchange.com/questions/33355
复制相似问题