数组:
一维数组
String[] name = {"12","23","33"}
二维数组
String[][] name1 ={ {"12","23","33"},{"12","23","33"}}
循环
for (int cc=0;cc<bc1.length;cc++){
for (int ce=0;ce<bc1[cc].length;ce++){
System.out.println(bc1[cc][ce]);
}
package com.guoyasoft.autoUI.firstDemo;
import com.guoyasoft.autoUI.common.BaseUI;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import org.testng.annotations.Test;
public class MyUITest extends BaseUI {
@Test
public void testLogin() {
//数组
String[] bc = {"xuepl123", "aaaaaa", "123456", "学生查询"};
String[][] bc1 = {{"xuepl123", "aaaaaa", "123456", "学生查询"}, {"xuepl123", "aaaaaa", "123456", "学生查询"}};
/*for (int cc=0;cc<bc1.length;cc++){
for (int ce=0;ce<bc1[cc].length;ce++){
System.out.println(bc1[cc][ce]);
}
}*/
for (int cc = 0; cc < bc1.length; cc++) {
//打开网页
driver.get("http://pro.guoyasoft.com:8080/guoya-medium/jsp/user/login.jsp");
//等待1秒
sleep(1000);
//定位用户名输入框
WebElement userName = driver.findElement(By.xpath("//input[@id ='userName']"));
//清空
userName.clear();
//填值
userName.sendKeys(bc1[cc][0]);
//等待1秒
sleep(2000);
//定位密码输入框
WebElement password = driver.findElement(By.xpath("//input[@id='password']"));
//清空
password.clear();
//填值
password.sendKeys(bc1[cc][1]);
//等待2秒
sleep(2000);
//定位校验码输入框
WebElement checkCheckCode = driver.findElement(By.xpath("//input[@onblur='checkCheckCode()']"));
//清空
checkCheckCode.clear();
//填值
checkCheckCode.sendKeys(bc1[cc][2]);
//等待2秒
sleep(2000);
//定位登录按钮
WebElement loginBtn = driver.findElement(By.xpath("//input[@value=\"登录\"]"));
//点击
loginBtn.click();
//等待2秒
sleep(2000);
//获取网页所有的源代码并判断是否包含“学生查询”
boolean result = driver.getPageSource().contains(bc1[cc][3]);
//断言实际结果和预期结果是否一致
Assert.assertEquals(result, true);
}
}
}