注册功能Selenium代码:
package com.selenium.testng;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.selenium.test.We;
public class RegisterTest {
WebDriver driver;
String Url="http://172.31.19.159/ecshop/";
@BeforeClass
public void print(){
System.out.println("beforeclass at register");
driver=We.findDriver();
We.findURL(driver,Url );
}
@Test
public void regist() throws InterruptedException {
//进入前台主页,前提是之前登录的已经退出,浏览器不记忆登录信息
for (int i = 0; i <1; i++) {
register();
}
}
int systime=(int) System.currentTimeMillis();
String uname1=systime+"yang";
String uname=uname1.substring(3);
public void register() throws InterruptedException{
String pwd="123456";
String mail=systime+"@qq.com";
//点击注册
We.byPathClick(driver,"//a[@href='user.php?act=register']");
//输入用户名
We.byIdWrite(driver, "username",uname);
//输入用密码
We.byIdWrite(driver, "password1", pwd);
//输入email
We.byIdWrite(driver, "email", mail);
//输入确认密码
We.byIdWrite(driver, "conform_password", pwd);
//输入msn
We.byNameWrite(driver,"extend_field1", mail);
//输入qq
We.byNameWrite(driver,"extend_field2", pwd);
//输入电话
We.byNameWrite(driver,"extend_field3", pwd);
//输入家庭电话
We.byNameWrite(driver,"extend_field4", pwd);
//输入手机
We.byNameWrite(driver,"extend_field5", pwd);
//输入密保问题
We.byNameSelect(driver, "sel_question", "motto");
//输入密保答案
We.byNameWrite(driver,"passwd_answer", pwd);
//点击确定
We.byNameClick(driver, "Submit00");
//检查是否登录成功
We.AssertEByClassName(driver, "f4_b", uname);
}
}
Selenium工具类示例代码:
//----------------------------下拉框选择
//通过名字找到并选择
public static void byNameSelect(WebDriver driver,String name,String value){
wait = new WebDriverWait(driver,10,1);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name(name)));
WebElement el=driver.findElement(By.name(name));
Select sel = new Select(el);
sel.selectByValue(value);
}
//通过xpath找到并选择
public static void byPathSelect(WebDriver driver,String name,String value){
wait = new WebDriverWait(driver,10,1);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(name)));
WebElement el=driver.findElement(By.xpath(name));
Select sel = new Select(el);
sel.selectByValue(value);
}
//----------------------------断言assetEquals
//通过name找到并选择
public static void AssertEByName(WebDriver driver,String name,String actual){
wait = new WebDriverWait(driver,10,1);
WebElement el= wait.until(ExpectedConditions.visibilityOfElementLocated(By.name(name)));
Assert.assertEquals(el.getText(),actual);
};
//通过id找到并选择
public static void AssertEById(WebDriver driver,String name,String actual){
wait = new WebDriverWait(driver,10,1);
WebElement el= wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(name)));
Assert.assertEquals(el.getText(),actual);
};
信息录入功能Appium代码示例:
public class AppDemo {
private AndroidDriver driver;
@BeforeMethod(alwaysRun=true)
public void set() throws Exception{
this.driver=wUtils.setUp();
}
@AfterMethod(alwaysRun=true)
public void tearDown() throws Exception {
driver.quit();
}
@Test(groups={"InfoQuery"} )
public void inforQuery(){
wUtils.byNameClick(driver, "信息查询");
wUtils.byNameClick(driver, "社区人口信息查询");
wUtils.radiobuttons_Click(driver, 1);
wUtils.editTexts_SendKeys(driver, 0, "高林达");
}
}