远程真机appium自动化的用法

TCOE Mobile Farm使用方法

Jeff Xie Feb 2022

  1. Mobile Farm地址:

https://mobilecloud.epam.com

执行机必须可以连接mobile farm的网络,才能执行mobile farm的代码

执行机必须可以连接mobile farm的网络,才能执行mobile farm的代码

执行机必须可以连接mobile farm的网络,才能执行mobile farm的代码

2. Mobile Farm登录,选择”NOT EPAM USER”,登录后用户名选择WELAB

3.生成Access Key

  1. 更新证书

证书文件下载地址:https://welab.sharepoint.com/teams/tech/External%20Sharing/Forms/AllItems.aspx?FolderCTID=0x012000711BF90AE4DBEC43BAB04FBC3B54C156&id=%2Fteams%2Ftech%2FExternal%20Sharing%2FWDL%20Vendors%2FEPAM%2FKT%2FAutomation%20Training&viewid=d94c51b8%2De9d3%2D413b%2Da811%2Dc2b26a355309

keytool -keystore "C:\Program Files\Java\jdk1.8.0_251\jre\lib\security\cacerts" -importcert -trustcacerts -storepass changeit -alias rootca -file RootCA_2026.cer 

keytool -keystore "C:\Program Files\Java\jdk1.8.0_251\jre\lib\security\cacerts" -importcert -trustcacerts -storepass changeit -alias issuing -file IssuingCA_2026.cer 

下载证书文件,执行以上两条命令,需要打开powershell,并且以管理员权限运行,在证书文件所在目录执行命令

注意:需要把java的地址更新成本机对应的地址

  1. 打开mobile farm如下图所示,选择一台手机,如下图所示打开,选择apk文件上传,然后点击Install进行安装

  1. Book 手机,选择一台手机点击Book,然后选择时间,并点击Book

  1. 点击AUTOMATION,然后点击RUN SAMPLE TEST
  2. Project要选择welab,选择系统和手机型号,下方就会生成对应的样本代码,这端代码可以copy到project中执行,但是需要执行机可以连接mobile farm的网络

  1. Mobile Farm进行元素定位,选择Native Inspector,然后点击refresh可以显示元素,进行元素定位

Mobile Farm 代码配置注意事项:

需要要使用的手机配置到1.D:\Project\Program\WorkSpaceIDEA\Automation\automation-test\src\main\resources\clouddevices\device_caps.json中,手机参数可以在SAMPLE TEST(Mobile Farm Step 8)的代码中找到

2.需要定义cloudDevice=HuaweiP30,就是第一步配置的手机,需要定义cloud.uri以及Authorization, 其中 Bearer 后面的字符串就是在Mobile farm中生成的access key

3.需要在全局变量中定义PROJECT_NAME,APPIM_HUB,MOBILE_FARM_API_URL

4 启动mobilefarm代码命令:

test -Denv=sit -Dplatform=mobile -Dmobile=cloudandroid -DtestngXmlFile=src/main/resources/suite/wealth/mobile_android.xml

Mobile Farm代码样本:

package com.test.demo;

import io.appium.java_client.AppiumDriver;

import io.appium.java_client.android.AndroidDriver;

import org.openqa.selenium.remote.DesiredCapabilities;

import org.openqa.selenium.remote.RemoteWebDriver;

import org.openqa.selenium.support.ui.FluentWait;

import org.testng.Assert;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.Test;

import java.net.URL;

import java.net.URLEncoder;

import java.nio.charset.StandardCharsets;

import java.util.concurrent.TimeUnit;

import static java.lang.String.format;

import static java.time.Duration.ofMinutes;

import static java.time.Duration.ofSeconds;

import static java.util.Optional.ofNullable;

import static org.openqa.selenium.By.className;

    public class AppiumDemo {

        private static final String PROJECT_NAME = "welab";

        private static final String API_KEY = "HQJFXdeRUNDovexdFLFLx38Ea6KzcrL8hTdxCObhSkT05Ew9ULMs19ncm9PSB0j334eu2QsiwwE5uOmJNcjRayd21jZlkszKZXHCX2lN3D2b8+KENYz6QpD9qQTjOjJE8hb5veD1seEE+Q4lFU+/X2zsy4HDaOm5wxvyFT3XxbQWgqwug2O9OYxb4Ozh7jV2OdpZjgkLQ96X8dkcZSyoExBUEqtQ7eACU3LfQicECMu5hqxn5LoEMPYIPru7Mmj+kaYn40nndPQO4XQ0TfCvCU7yLmTAP/sPX3a4TkbXDDUsgiWdgxGt9OToCMwf9bKBa8y2M0IapZhgekOPM+IWR5hgf2NrLNor3bNYMxLg70ANOd1yfJyc7SGOIf950KhjCgUM44FAK6F1qQkBXV7YP/+/2fUCOlQJkspXQZ7y9js6aHQRMhOsXonr8GyzsAmDPPSxc8H9URzJ8onZEFwr5IiK0OY6eWX1Pd3hmg8MVjORIpmhCqoEvmzfUJI0+Jma47cn1xPhwIKqCeTHKDdJAscSzG7hJ9DDLQmi2eyFuxjm3wRr0QIJvseby8fSps1p/r9vRhU1CB60SVNskQa5ypCtxPkWUA71ngS64F0rBdu55QhMU0S21//hTOrnMGLTFEJLviJFFUHwPdF5nl+J41/NCFOgg4+lXB77Ytx5p0/Mc5GPrPwMVBgMcLQc11JF7uzAh27ml15YtPy7W166spZQOBE4Eu/PXJN7UH+BtwPh+vwG43Kmty46X383uC0Cy2kJ9tuDp1nGtFCVjMB2dWfbILZnPnVXwlc0yv40Gu9z6kXuwR4oKKZt0VHpY4WTQFUgUeKzX5bxiiFdOqhwzaJ1t2WEC7AVS2oMuTZJ+D+dxIde7WDQGnOAwcnhK3MsuG1PV/qzpj37TQhrphSk2FE";

        private static final String APPIUM_HUB = "mobilecloud.epam.com";

        private static final String PLATFORM_NAME = "Android";

        private static final String PLATFORM_VERSION = "9";

        private static final String BROWSER_NAME = "chrome";

        private static final String DEVICE_NAME = "HUAWEI ELE-L29";

        private final DesiredCapabilities capabilities;

        private AppiumDriver driver = null;

        public AppiumDemo() {

            capabilities = new DesiredCapabilities();

            capabilities.setCapability("platformName", PLATFORM_NAME);

            capabilities.setCapability("platformVersion", PLATFORM_VERSION);

            capabilities.setCapability("browserName", BROWSER_NAME);

            capabilities.setCapability("deviceName", DEVICE_NAME);

        }

        @BeforeMethod

        public void before() throws Exception {

            String key = URLEncoder.encode(API_KEY, StandardCharsets.UTF_8.name());

            driver = new AndroidDriver(

                    new URL(format("https://%s:%s@%s/wd/hub", PROJECT_NAME, key, APPIUM_HUB)), capabilities);

            // For devices with low performance

            driver.manage().timeouts()

                    .pageLoadTimeout(5, TimeUnit.MINUTES)

                    .implicitlyWait(90, TimeUnit.SECONDS);

        }

        @Test

        public void demoTest() {

            final String epamUrl = "https://www.epam.com/";

//            Assert.assertEquals(format("Focus is not on '%s'", BROWSER_NAME), driver.isBrowser());

            driver.get(epamUrl);

            new FluentWait<>(driver).withMessage("Page was not loaded")

                    .pollingEvery(ofSeconds(1))

                    .withTimeout(ofMinutes(1))

                    .until(driver -> driver.findElements(className("header__logo")).size() > 0);

            Assert.assertEquals("Current url is incorrect", epamUrl, driver.getCurrentUrl());

            Assert.assertEquals("Page title is incorrect", "EPAM | Enterprise Software Development, Design & Consulting", driver.getTitle());

        }

        @AfterMethod

        public void after() {

            ofNullable(driver).ifPresent(RemoteWebDriver::quit);

        }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值