安装运行Appium初体验

最近有空玩了一下 Appium,记录一下
   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   <dependencies>
2     <dependency>
3             <groupId>junit</groupId>
4             <artifactId>junit</artifactId>
5             <version>4.11</version>
6             <scope>test</scope>
7         </dependency>
8         <dependency>
9             <groupId>org.seleniumhq.selenium</groupId>
10             <artifactId>selenium-java</artifactId>
11             <version>LATEST</version>
12             <scope>test</scope>
13         </dependency>
14   </dependencies>
 编写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     @Before
21     public void setUp() throws Exception {
22         // set up appium
23         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     @After
38     public void tearDown() throws Exception {
39         driver.quit();
40     }
41
42     @Test
43     public void addContact(){
44         WebElement el = driver.findElement(By.name("Add Contact"));
45         el.click();
46         List<WebElement> 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

最新内容请见作者的GitHub页:http://qaseven.github.io/
优秀的个人博客,低调大师

微信关注我们

原文链接:https://yq.aliyun.com/articles/130595

转载内容版权归作者及来源网站所有!

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

相关文章

发表评论

资源下载

更多资源
优质分享Android(本站安卓app)

优质分享Android(本站安卓app)

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Oracle Database,又名Oracle RDBMS

Oracle Database,又名Oracle RDBMS

Oracle Database,又名Oracle RDBMS,或简称Oracle。是甲骨文公司的一款关系数据库管理系统。它是在数据库领域一直处于领先地位的产品。可以说Oracle数据库系统是目前世界上流行的关系数据库管理系统,系统可移植性好、使用方便、功能强,适用于各类大、中、小、微机环境。它是一种高效率、可靠性好的、适应高吞吐量的数据库方案。

Apache Tomcat7、8、9(Java Web服务器)

Apache Tomcat7、8、9(Java Web服务器)

Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache、Sun 和其他一些公司及个人共同开发而成。因为Tomcat 技术先进、性能稳定,而且免费,因而深受Java 爱好者的喜爱并得到了部分软件开发商的认可,成为目前比较流行的Web 应用服务器。

Eclipse(集成开发环境)

Eclipse(集成开发环境)

Eclipse 是一个开放源代码的、基于Java的可扩展开发平台。就其本身而言,它只是一个框架和一组服务,用于通过插件组件构建开发环境。幸运的是,Eclipse 附带了一个标准的插件集,包括Java开发工具(Java Development Kit,JDK)。