是执行循环的测试。从数据库中检索登录详细信息。测试密码是否不正确会被中断,因为 WD 在登录后没有找到该项目 他应该单击。例如,十个密码中的第四个被证明是错误的,只标记异常,并继续下一步测试,如何使测试不中断?
我关心这个例子。 100 个登录名和密码,以找出不正确的登录名和密码。
一段代码:
driver.get(baseUrl + "a url");
AssertJUnit.assertEquals("assert text", driver.getTitle());
driver.findElement(By.id("login")).clear();
driver.findElement(By.id("login")).sendKeys(login);
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys(password);
driver.findElement(By.cssSelector("span.triangle")).click();
如果登录不成功,可以点击最后一行代码的按钮。 用什么?断言等于吗?验证?软断言?怎么办?
最佳答案
我明白了吗?在测试用例中添加您的逻辑。三种风格三种情况。
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
public class StackOverFlow26116823 {
private static String password = "s";
private static String getPassword(){
return password + "a";
}
@Test
public void testFail() {
for(int i = 0 ; i < 100; i ++){
assertEquals("a" , getPassword());
}
}
@Test
public void testLoopToSave() {
List<AssertionError> errorS = new ArrayList<AssertionError>();
for(int i = 0 ; i < 100; i ++){
try{
assertEquals("a" , getPassword());
}catch(AssertionError e){
errorS.add(e);
}
}
assertTrue( getAllErrorMessageTrace(errorS) , errorS.size() == 0 );
}
private String getAllErrorMessageTrace(List<AssertionError> errorS) {
// TODO Auto-generated method stub
return "";
}
@Test
public void testLoopJustCountAndLogging() {
boolean errorFlag = false;
for(int i = 0 ; i < 100; i ++){
try{
assertEquals("a" , getPassword());
}catch(AssertionError e){
System.out.println( i + ": " + e.getMessage() );
errorFlag = true;
}
}
assertTrue( "Some errors that you can find in log. ", errorFlag);
}
}
关于java - 尽管出现错误,如何继续循环中的测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26116823/