博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Appium小试
阅读量:4160 次
发布时间:2019-05-26

本文共 3643 字,大约阅读时间需要 12 分钟。

最近有空玩了一下,记录一下

1.下载Appium for windows,现在是0.12.3版本

解压后如下图

双击Appium.exe就能启动Appium界面

点击Launch开启服务

2. 下载Android SDK

解压后

3. 配置系统环境变量

ANDROID_HOME: C:\adt-bundle-windows-x86_64-20131030\sdk

Path添加: %ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools

4. 启动AVD,耗资源啊,这时候我T400的CPU已经100%了

5. 编写Test,使用ADT安装好Maven插件,创建一个Maven项目,添加一个文件夹apps用来存放被测的app,这里测试的是ContactManager.apk

pom.xml添加如下依赖

1   
2
3
junit
4
junit
5
4.11
6
test
7
8
9
org.seleniumhq.selenium
10
selenium-java
11
LATEST
12
test
13
14

编写AndroidContactsTest

1 package com.guowen.appiumdemo; 2  3 import org.junit.After; 4 import org.junit.Before; 5 import org.junit.Test; 6 import org.openqa.selenium.*; 7 import org.openqa.selenium.interactions.HasTouchScreen; 8 import org.openqa.selenium.interactions.TouchScreen; 9 import org.openqa.selenium.remote.CapabilityType;10 import org.openqa.selenium.remote.DesiredCapabilities;11 import org.openqa.selenium.remote.RemoteTouchScreen;12 import org.openqa.selenium.remote.RemoteWebDriver;13 import java.io.File;14 import java.net.URL;15 import java.util.List;16 17 public class AndroidContactsTest {18     private WebDriver driver;19 20     @Before21     public void setUp() throws Exception {22         // set up appium23         File classpathRoot = new File(System.getProperty("user.dir"));24         File appDir = new File(classpathRoot, "apps/ContactManager");25         File app = new File(appDir, "ContactManager.apk");26         DesiredCapabilities capabilities = new DesiredCapabilities();27         capabilities.setCapability("device","Android");28         capabilities.setCapability(CapabilityType.BROWSER_NAME, "");29         capabilities.setCapability(CapabilityType.VERSION, "4.4");30         capabilities.setCapability(CapabilityType.PLATFORM, "WINDOWS");31         capabilities.setCapability("app", app.getAbsolutePath());32         capabilities.setCapability("app-package", "com.example.android.contactmanager");33         capabilities.setCapability("app-activity", ".ContactManager");34         driver = new SwipeableWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);35     }36 37     @After38     public void tearDown() throws Exception {39         driver.quit();40     }41 42     @Test43     public void addContact(){44         WebElement el = driver.findElement(By.name("Add Contact"));45         el.click();46         List
textFieldsList = driver.findElements(By.tagName("textfield"));47 textFieldsList.get(0).sendKeys("Some Name");48 textFieldsList.get(2).sendKeys("Some@example.com");49 driver.findElement(By.name("Save")).click();50 }51 52 public class SwipeableWebDriver extends RemoteWebDriver implements HasTouchScreen {53 private RemoteTouchScreen touch;54 55 public SwipeableWebDriver(URL remoteAddress, Capabilities desiredCapabilities) {56 super(remoteAddress, desiredCapabilities);57 touch = new RemoteTouchScreen(getExecuteMethod());58 }59 60 public TouchScreen getTouch() {61 return touch;62 }63 }64 }

6. 运行Test,注意AVD里的Android如果没有解锁需要先解锁

这时候我们可以看到AVD在运行了,

同时Appium的命令行有对应的输出

7. 更多信息请参考Appium的Github

建议可以Clone下这个项目,在Sample-code文件夹下有示例

同时发起翻译活动的中文文档也提交进去了

关注质量与体验——电子商务与自动化测试

转载地址:http://rgcxi.baihongyu.com/

你可能感兴趣的文章
nginx反代 499 502 bad gateway 和timeout
查看>>
linux虚拟机安装tar.gz版jdk步骤详解
查看>>
k8s web终端连接工具
查看>>
手绘VS码绘(一):静态图绘制(码绘使用P5.js)
查看>>
链睿和家乐福合作推出下一代零售业隐私保护技术
查看>>
Unifrax宣布新建SiFAB™生产线
查看>>
艾默生纪念谷轮™在空调和制冷领域的百年创新成就
查看>>
JavaSE_day14 集合中的Map集合_键值映射关系
查看>>
异常 Java学习Day_15
查看>>
Mysql初始化的命令
查看>>
浅谈HTML
查看>>
css基础
查看>>
Servlet进阶和JSP基础
查看>>
servlet中的cookie和session
查看>>
过滤器及JSP九大隐式对象
查看>>
【Python】学习笔记——-7.0、面向对象编程
查看>>
【Python】学习笔记——-7.2、访问限制
查看>>
【Python】学习笔记——-7.3、继承和多态
查看>>
【Python】学习笔记——-7.5、实例属性和类属性
查看>>
git中文安装教程
查看>>