package com.lemon.day01;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
public class APPTest3 {
AppiumDriver<WebElement> driver;
@BeforeClass
public void beforeClass() throws MalformedURLException, InterruptedException{
//1;添加配置
//手工:找到设备、APP、APP某个页面
DesiredCapabilities desiredcapabilities = new DesiredCapabilities();
desiredcapabilities.setCapability("deviceName","127.0.0.1:52001");//设备名
desiredcapabilities.setCapability("appPackage","com.tencent.mm");//app包,区别我们每台设备的app
//使用命令:adb shell dumpsys activity | find "mFocusedActivity"
desiredcapabilities.setCapability("appActivity","com.tencent.mm.ui.LauncherUI");//指定页面
//2;创建驱动
//remoteAddress:远程url地址
//desiredCapablites :这个驱动期望得到的能力
URL remoteAddress = new URL("http://127.0.0.1:4723/wd/hub");//固定不变的
driver = new AndroidDriver<WebElement>(remoteAddress,desiredcapabilities);
//3;找到页面元素
//自动化:程序自动定位到页面元素
Thread.sleep(10000);
WebElement registerBtn = driver.findElement(By.id("d36"));
Thread.sleep(10000);
registerBtn.click();
Thread.sleep(1000);
}
@AfterClass
public void fun(){
driver.quit();
}
@Test(dataProvider = "testDatas")
//拿到数据提供者的数据,循环这个二维数组,提取元素(一维数组),会把一维数组中的每个元素依次注入到形式参数里
//可以把数据提供者的数据注入到测试方法的形式参数里
public void TestCase(String nickName,String mobilPhone,String pwd ) throws MalformedURLException, InterruptedException {
//4;操作页面元素来模拟用户操作
//测试用例,进入注册页面,如 昵称、手机号、密码都不输入的情况,然后点击注册
List<WebElement> elements = driver.findElements(By.id("ht"));
//每次清空
elements.get(0).clear();
elements.get(1).clear();
elements.get(2).clear();
// WebElement nickNameInput = driver.findElement(By.id("ht"));
//nickNameInput.sendKeys("");//输入字符串
elements.get(0).sendKeys(nickName);
// WebElement mobilPhoneInput = driver.findElement(By.id("ht"));
// mobilPhoneInput.sendKeys("");
elements.get(1).sendKeys(mobilPhone);
// WebElement pwdInput = driver.findElement(By.id("ht"));
//pwdInput.sendKeys("");
elements.get(2).sendKeys(pwd);
WebElement registerBtnn = driver.findElement(By.id("cw1"));
boolean isEnabled = registerBtnn.isEnabled();//是否被激活
Assert.assertFalse(isEnabled);//断言判断是否可以点击
}
@DataProvider
public Object[][] testDatas(){
//int[] array1 = {1,2,3,4};//静态数组
Object[][] datas = {{"","",""},{"shashe","",""},{"shashe","15111917843",""}};
return datas;
}
}