栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

搭建 Appium 自动化测试环境

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

搭建 Appium 自动化测试环境

一、JAVA 环境搭建

JAVA_HOME
Path: %JAVA_HOME%bin %JAVA_HOME%jrebin
CLASSPATH: .;%JAVA_HOME%libdt.jar;%JAVA_HOME%libtools.jar;

二、SDK 环境搭建

下载并安装Android SDK

ANDROID_HOME

Path: ;%ANDROID_HOME%platform-tools;%ANDROID_HOME%tools

下载并安装 Windows 10 SDK

三、安卓模拟器安装

https://www.bluestacks.com/bluestacks-5.html

四、连接模拟器
adb devices

emulator-5554

adb connect 127.0.0.1:5555
adb shell dumpsys window windows | findstr mFocusedApp

mFocusedApp=AppWindowToken{8ea0a2e token=Token{5e90030 ActivityRecord{740c973 u0 com.antfortune.wealth/com.alipay.mobile.quinox.LauncherActivity t16}}}

包名:com.antfortune.wealth
界面:com.alipay.mobile.quinox.LauncherActivity

获取操作系版本

adb shell getprop ro.build.version.release

7.1.2

推送文件

adb push /computer_path /phone_path

拉取文件

adb pull /phone_path /computer_path

安装包

adb install /computer_path/***.apk
五、安装 Appium
{
    "platformName": "Android",
    "platformVersion": "7.1.2",
    "deviceName": "emulator-5554",
    "automationName": "UiAutomator2",
    "appPackage": "com.antfortune.wealth",
    "appActivity": "com.alipay.mobile.quinox.LauncherActivity"
}
adb connect 127.0.0.1:5555
六、编写脚本
dotnet add package Appium.WebDriver

1、创建 Driver

var opts = new AppiumOptions();
opts.AddAdditionalCapability("platformName", "Android");
opts.AddAdditionalCapability("platformVersion", "7.1.2");
opts.AddAdditionalCapability("automationName", "UiAutomator2");
opts.AddAdditionalCapability("deviceName", "emulator-5554");
opts.AddAdditionalCapability("appPackage", "com.antfortune.wealth");
opts.AddAdditionalCapability("appActivity", "com.alipay.mobile.quinox.LauncherActivity");
var uri = new Uri("http://127.0.0.1:4723/wd/hub");
var driver = new AndroidDriver(uri, opts, INIT_TIMEOUT_SEC);
var driver = new WindowsDriver(uri, opts, INIT_TIMEOUT_SEC);
driver.Manager().Timeouts().ImplicitWait = IMPLICIT_TIMEOUT_SEC;
driver.Quit();

2、选择控件

var elem = driver.FindElementsByAccessibilityId("Content");
var elem = driver.FindElementsById("android:id/action_bar_container");
var elem = driver.FindElementsByClassName("android.widget.FrameLayout");
var elem = driver.FindElementsByXPath("//*[@class='android.widget.FrameLayout']");

3、操作页面

var searchBox = driver.FindElementById("txt_query_prefill");
searchBox.SendKeys("Hello World!");

var searchButton = driver.FindElementById("bt_start_search");
searchButton.Click();

var searchText = driver.FindElementById("android:id/search_src_text");
driver.StartActivity("io.appium.android.apis", ".app.AlertDialogSamples");

var openDialogButton = driver.FindElementById("io.appium.android.apis:id/two_buttons");
openDialogButton.Click();

var alert = driver.FindElementById("android:id/alertTitle");
var alertText = alert.Text;

driver.FindElementById("android:id/button1").Click();
driver.CurrentActivity;
driver.Url = "https://www.google.com"
Assert.AreEqual("Google", title);
七、开始测试

1、启动 Appium
2、打开 模拟器
3、ADB 连接模拟器

adb connect 127.0.0.1:5555
{
  server: 'http://127.0.0.1:4723',
  options: {
      "platformName": "Android",
      "platformVersion": "7.1.2",
      "deviceName": "emulator-5554",
      "automationName": "UiAutomator2",
      "appPackage": "com.antfortune.wealth",
      "appActivity": "com.alipay.mobile.nebulax.integration.mpaas.activity.NebulaActivity$Main",
      "noReset": 'true',
      "autoLaunch": 'false'
  },
  operations: [{
    find: 'element',
    by: 'id',
    selector: 'android:id/button2',
    operation: 'click'
  }]
}

com.alipay.mobile.nebulax.integration.mpaas.activity.NebulaActivity$Main
com.alipay.mobile.quinox.LauncherActivity

adb shell uiautomator
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1013461.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号