package com.yulu.demo;
import io.appium.java_client.AppiumDriver;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.io.File;
import java.net.URL;
import java.sql.Time;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.sql.Time;
public class YCMathTest {
private AppiumDriver driver;
@Before
public void setUp() throws Exception {
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot,"apps");
File app = new File(appDir, "YCMath345-iOS.app");
System.out.println("设置路径完毕");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("appium-version", "1.1.0");
capabilities.setCapability("platformVersion", "9.2");
capabilities.setCapability("platformName", "ios");
capabilities.setCapability("deviceName", "iPhone 6");
System.out.println("设置自动化相关参数");
capabilities.setCapability("app", app.getAbsolutePath());
driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities );
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
System.out.println("初始化 AppiumDriver");
}
@After
public void tearDown() throws Exception{
driver.quit();
System.out.println("运行结束!!!!!!!");
System.out.println("即将开启下一个Session");
}
@Test
public void AppiumTestOne() throws InterruptedException{
System.out.println("Session One-First case-Start");
driver.findElement(By.name("马上开始")).click();
System.out.println("点击马上开始!");
driver.findElement(By.name("人教版")).click();
System.out.println("点击人教版,选择教材!");
driver.findElement(By.name("七年级上")).click();
System.out.println("点击七年级上,选择年纪!");
driver.findElement(By.name("引入")).click();
System.out.println("点击引入,跳转到视频界面!");
driver.findElement(By.name("yc coachmark")).click();
System.out.println("点击蒙版,接下来播放视频");
System.out.println("设置了线程休眠20秒....");
Thread.sleep(20000);
System.out.println("视频播放20秒后");
System.out.println("Session One-First case-End!");
}
@Test
public void AppiumTestTwo() throws InterruptedException{
System.out.println("Session Two-first case-start");
driver.findElement(By.name("注册或登录")).click();
System.out.println("点击注册或登录!");
driver.findElement(By.name("学生")).click();
System.out.println("点击button,身份为学生!");
driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIATextField[1]")).sendKeys("15725040279");;
System.out.println("输入手机号或邮箱!");
driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIASecureTextField[1]")).sendKeys("yulu83741319");
System.out.println("输入密码!");
driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[5]/UIAKeyboard[1]/UIAButton[4]")).click();
System.out.println("点击键盘完成输入!");
driver.findElement(By.name("立即登录")).click();
System.out.println("点击了,立即登录按钮.");
Thread.sleep(10000);
System.out.println("睡眠10秒");
System.out.println("Session Two-first case-End!");
}
}