jave-client。5.0前后 版本不同,调用API不一同
脚本包含了2个情况如下:
package com.test.firstAppium;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.touch.WaitOptions;
import io.appium.java_client.touch.offset.PointOption;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.touch.WaitOptions;
import io.appium.java_client.touch.offset.PointOption;
public class SwipeTest {
// 声明全局变量
public static AndroidDriver<WebElement> androidDriver;
// 声明全局变量
public static AndroidDriver<WebElement> androidDriver;
@BeforeTest
public void setup() throws MalformedURLException {
// 1.創建配置對象
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
// 2.添加配置
// deviceName:可以找到我们测试的设备
desiredCapabilities.setCapability("deviceName", "127.0.0.1:62001");
// platformName:测试平台android or IOS
desiredCapabilities.setCapability("platformName", "Android");
// appPackage:找到测试 APP:aapt dump badging.....
desiredCapabilities.setCapability("appPackage", "com.handsgo.jiakao.android");
// automationName:uiautomator2来解决输入框输入不了数据
// 自动化引擎
// desiredCapabilities.setCapability("automationName", "uiautomator2");
//不清理应用的数据,默认是清理的
desiredCapabilities.setCapability("noReset",true);
// appActivity:测试app入口
desiredCapabilities.setCapability("appActivity", "com.handsgo.jiakao.android.splash.Login");
// 创建驱动
// 传入2个参数,第一个参数:Appium通讯地址,第二个参数:配置对象
androidDriver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), desiredCapabilities);
//隐式等待
androidDriver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
public void setup() throws MalformedURLException {
// 1.創建配置對象
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
// 2.添加配置
// deviceName:可以找到我们测试的设备
desiredCapabilities.setCapability("deviceName", "127.0.0.1:62001");
// platformName:测试平台android or IOS
desiredCapabilities.setCapability("platformName", "Android");
// appPackage:找到测试 APP:aapt dump badging.....
desiredCapabilities.setCapability("appPackage", "com.handsgo.jiakao.android");
// automationName:uiautomator2来解决输入框输入不了数据
// 自动化引擎
// desiredCapabilities.setCapability("automationName", "uiautomator2");
//不清理应用的数据,默认是清理的
desiredCapabilities.setCapability("noReset",true);
// appActivity:测试app入口
desiredCapabilities.setCapability("appActivity", "com.handsgo.jiakao.android.splash.Login");
// 创建驱动
// 传入2个参数,第一个参数:Appium通讯地址,第二个参数:配置对象
androidDriver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), desiredCapabilities);
//隐式等待
androidDriver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
}
// 自定义方法
@Test
public void testRefresh() {
//下拉刷新pom:java-client:4.1.2
//androidDriver.swipe(356,954,356,900,800)
//java-client :6.14.3
TouchAction<TouchAction<T>> touchAction = new TouchAction(androidDriver);
//把原始坐标转换成PointOption类型的
PointOption startPointOption=PointOption.point(356,594);
PointOption endPointOption = PointOption.point(356.900);
//把原始的时间转换成Duration类型的
Duration duration = Duration.ofMillis(800);
//把Duration类型转换为waitOptions类型
WaitOptions waitOptions= WaitOptions.waitOptions(duration);
touchAction.press(startPointOption).waitAction(waitOptions).moveTo(endPointOption).release();
//让滑动生效
touchAction.perform();
}
@Test
public void testRefresh() {
//下拉刷新pom:java-client:4.1.2
//androidDriver.swipe(356,954,356,900,800)
//java-client :6.14.3
TouchAction<TouchAction<T>> touchAction = new TouchAction(androidDriver);
//把原始坐标转换成PointOption类型的
PointOption startPointOption=PointOption.point(356,594);
PointOption endPointOption = PointOption.point(356.900);
//把原始的时间转换成Duration类型的
Duration duration = Duration.ofMillis(800);
//把Duration类型转换为waitOptions类型
WaitOptions waitOptions= WaitOptions.waitOptions(duration);
touchAction.press(startPointOption).waitAction(waitOptions).moveTo(endPointOption).release();
//让滑动生效
touchAction.perform();
}
@AfterTest
public void teardown() {
androidDriver.quit();
}
}
}