繁体   English   中英

如何停止执行测试用例失败 Java selenium

[英]How to stop the execution of test cases fails in Java selenium

我有一个场景,一旦它达到其他部分的条件之一,我需要停止执行。 下面是我的代码。一旦条件达到其他条件,我想停止执行。如何使用断言条件?

So once I reach last condition ,that is if any employee reaches Exception,I want to stop the execution

If a condition reaches,HR department,variable counter will be incremented by 1 and if it reaches Finance department ,variable i will be decremented by 1

for (int i=0;i<EmployeeID.size();i++) { 
//while(i++<=EmployeeID.size()) {
    if(counter==EmployeeID.size())break;
    stmt = con.prepareStatement("select * from Employee where EmployeeID=?");                   
    stmt.setInt(1,EmployeeID.get(i));
    //System.out.println(EmployeeID.get(i));                
    rs3= stmt.executeQuery();
//  while(counter!=EmployeeID.size()) {
        while(rs3.next()) {     
        getCurrentQueueID= rs3.getString("CurrentQueueID");
        if(getCurrentQueueID.equals("1")) {
        log.info(+EmployeeID.get(i) + " is in HR Department");
        counter++;
        //System.out.println("Count is"+counter);
        }

        else if(getCurrentQueueID.equals("7")) {
        log.info(+EmployeeID.get(i) + " is in Finance Department");
        --i;
        System.out.println("Value of i is" +i);
        Thread.sleep(10000);

        }

        else if(getCurrentQueueID.equals("3")) {
            log.info(+EmployeeID.get(i) + " is in Exception");
        }
}   //End of While rs loop

如果您想停止测试以使其不被视为失败,则只需使用return; 陈述。

如果您需要停止测试失败,那么您可以:

  • 如果不使用任何测试框架,则抛出异常
  • 或使用assert false; 如果您不使用任何测试框架,请声明
  • 或使用org.junit.Assert.fail(); 如果您使用 JUnit
  • 或使用org.testng.Assert.fail()如果您使用 TestNG

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM