是执行循环的测试。登录详细信息从数据库中检索。测试密码是否不正确被打断,因为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();
如果登录失败,则可以单击代码最后一行上的按钮。使用什么?assertEquals?真实性?softAssert?如何?
我明白了吗?在测试用例中添加您的逻辑。三种样式的三种情况。
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);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句