1.startActivity实现页面跳转(包括APP 内部页面和APP 相互跳转)
开启某一个activity,实现跳转
先创建一个activity对象,用activity构造方法初始化,参数为对应的包名和类名
Activity activity = new Activity("AppPackage","当前页面得类名");
androidDriver.startActivity(activity);
当前页面的类名查找如下:
查询包名appPackage
//1.页面的跳转-APP内部页面的跳转
//Activity activity = new Activity("com.handsgo.jiakao.android","cn.mucang.android.account.activity.LoginMultiDefaultSmsActivity");
//androidDriver.startActivity(activity);
如果是测试APP之间得跳转
Activity activity = new Activity("AppPackage","AppActivity");
androidDriver.startActivity(activity);
//2.app相互跳转-跳转到其他app页面(入口)
Activity activity = new Activity("com.baidu.BaiduMap","com.baidu.baidumaps.WelcomeScreen");
androidDriver.startActivity(activity);
脚本class如下
package com.test.firstAppium;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import io.appium.java_client.android.Activity;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidDriver;
public class AppiumApiTest {
// 声明全局变量
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 ApiTest() throws InterruptedException {
Thread.sleep(6000);
//1.页面的跳转-APP内部页面的跳转
//Activity activity = new Activity("com.handsgo.jiakao.android","cn.mucang.android.account.activity.LoginMultiDefaultSmsActivity");
//androidDriver.startActivity(activity);
//2.app相互跳转-跳转到其他app页面(入口)
Activity activity = new Activity("com.baidu.BaiduMap","com.baidu.baidumaps.WelcomeScreen");
androidDriver.startActivity(activity);
}
@AfterTest
public void teardown() throws InterruptedException {
Thread.sleep(3000);
androidDriver.quit();
@Test
public void ApiTest() throws InterruptedException {
Thread.sleep(6000);
//1.页面的跳转-APP内部页面的跳转
//Activity activity = new Activity("com.handsgo.jiakao.android","cn.mucang.android.account.activity.LoginMultiDefaultSmsActivity");
//androidDriver.startActivity(activity);
//2.app相互跳转-跳转到其他app页面(入口)
Activity activity = new Activity("com.baidu.BaiduMap","com.baidu.baidumaps.WelcomeScreen");
androidDriver.startActivity(activity);
}
@AfterTest
public void teardown() throws InterruptedException {
Thread.sleep(3000);
androidDriver.quit();
}
}