數(shù)組:
一維數(shù)組
String[] name = {"12","23","33"}
二維數(shù)組
String[][] name1 ={ {"12","23","33"},{"12","23","33"}}
循環(huán)
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() {
//數(shù)組
String[] bc = {"xuepl123", "aaaaaa", "123456", "學(xué)生查詢"};
String[][] bc1 = {{"xuepl123", "aaaaaa", "123456", "學(xué)生查詢"}, {"xuepl123", "aaaaaa", "123456", "學(xué)生查詢"}};
/*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++) {
//打開(kāi)網(wǎng)頁(yè)
driver.get("http://pro.guoyasoft.com:8080/guoya-medium/jsp/user/login.jsp");
//等待1秒
sleep(1000);
//定位用戶名輸入框
WebElement userName = driver.findElement(By.xpath("http://input[@id ='userName']"));
//清空
userName.clear();
//填值
userName.sendKeys(bc1[cc][0]);
//等待1秒
sleep(2000);
//定位密碼輸入框
WebElement password = driver.findElement(By.xpath("http://input[@id='password']"));
//清空
password.clear();
//填值
password.sendKeys(bc1[cc][1]);
//等待2秒
sleep(2000);
//定位校驗(yàn)碼輸入框
WebElement checkCheckCode = driver.findElement(By.xpath("http://input[@onblur='checkCheckCode()']"));
//清空
checkCheckCode.clear();
//填值
checkCheckCode.sendKeys(bc1[cc][2]);
//等待2秒
sleep(2000);
//定位登錄按鈕
WebElement loginBtn = driver.findElement(By.xpath("http://input[@value=\"登錄\"]"));
//點(diǎn)擊
loginBtn.click();
//等待2秒
sleep(2000);
//獲取網(wǎng)頁(yè)所有的源代碼并判斷是否包含“學(xué)生查詢”
boolean result = driver.getPageSource().contains(bc1[cc][3]);
//斷言實(shí)際結(jié)果和預(yù)期結(jié)果是否一致
Assert.assertEquals(result, true);
}
}
}

java基礎(chǔ).png