package com.appium.cases;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.ios.IOSElement;
import io.appium.java_client.remote.IOSMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;
import java.io.File;
import java.net.URL;
public class IOSDeijtong {
IOSDriver<IOSElement> driver;
//命令行启动
@BeforeClass
public void setUp() throws Exception {
File appDir = new File(System.getProperty("user.dir"));
final File app = new File(appDir, "/app/Toon.ipa");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName","IOS"); //手机os
capabilities.setCapability("platformVersion", "11.0.3"); //要启动的手机OS版本
capabilities.setCapability("deviceName", "iPhonexq"); //手机类型或模拟器类型,比如MI_2A/Android Emulator/iPhone Simulator
capabilities.setCapability("udid","0259411d3508a459149c8aec521ff5845a2e835b"); //物理机ID //使用的是Mac平台 a779c7953c50967fca89500e932981029e306659
capabilities.setCapability("useNewWDA",false); //false
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");
capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 3600);
//capabilities.setCapability(IOSMobileCapabilityType.AUTO_ACCEPT_ALERTS, true); //所有IOS的提醒出现选择接受
capabilities.setCapability("bundleId", "com.systoon.beijingtong");
capabilities.setCapability("app", app.getAbsolutePath()); //得到app绝对路径(工程下的一个路径 如果安装就启用,如果不安装就不用启动)
driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@Test
public void allinLogin() throws InterruptedException { //登陆
/** 允许*/
Thread.sleep(5000);
//System.out.println(driver.getPageSource()); //获取元素
//driver.findElement(By.name("允许")).click();
//登录用户名 XCUIElementTypeTextField
driver.findElementByName("请输入手机号码").clear();
driver.findElementByName("请输入手机号码").sendKeys("14725000001");
//密码
driver.findElementByName("请输入你的密码").sendKeys("1111");
//登录
driver.findElementByName("登录").click();
Thread.sleep(5000);
System.out.println("这个是登录后的页面");
System.out.println(driver.getPageSource()); //获取元素
//final WebElement text = river.findElement(By.xpath("//UIATextField[1]"));
}
@AfterClass
public void tearDown() throws Exception {
// driver.quit();
}
}
原文地址:http://357712148.blog.51cto.com/6440370/1982311