qileilove

          blog已經(jīng)轉(zhuǎn)移至github,大家請(qǐng)?jiān)L問(wèn) http://qaseven.github.io/

          安裝運(yùn)行Appium初體驗(yàn)

           最近有空玩了一下Appium,記錄一下
            1.下載Appium for windows,現(xiàn)在是0.12.3版本
            解壓后如下圖
            雙擊Appium.exe就能啟動(dòng)Appium界面
            點(diǎn)擊Launch開(kāi)啟服務(wù)
            2. 下載Android SDK
            解壓后
            3. 配置系統(tǒng)環(huán)境變量
            ANDROID_HOME: C:\adt-bundle-windows-x86_64-20131030\sdk
            Path添加: %ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools
           4. 啟動(dòng)AVD,耗資源啊,這時(shí)候我T400的CPU已經(jīng)100%了
            5. 編寫(xiě)Test,使用ADT安裝好Maven插件,創(chuàng)建一個(gè)Maven項(xiàng)目,添加一個(gè)文件夾apps用來(lái)存放被測(cè)的app,這里測(cè)試的是ContactManager.apk
            pom.xml添加如下依賴(lài)
          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>
           編寫(xiě)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. 運(yùn)行Test,注意AVD里的Android如果沒(méi)有解鎖需要先解鎖
            這時(shí)候我們可以看到AVD在運(yùn)行了,
            同時(shí)Appium的命令行有對(duì)應(yīng)的輸出
            7. 更多信息請(qǐng)參考Appium的Github

          posted on 2014-11-27 11:57 順其自然EVO 閱讀(1370) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): android

          <2014年11月>
          2627282930311
          2345678
          9101112131415
          16171819202122
          23242526272829
          30123456

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(55)

          隨筆分類(lèi)

          隨筆檔案

          文章分類(lèi)

          文章檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 成武县| 黔西县| 和顺县| 宁阳县| 水城县| 师宗县| 南雄市| 北宁市| 宿松县| 都江堰市| 大足县| 辽宁省| 奉贤区| 博兴县| 襄城县| 武城县| 江北区| 渑池县| 新化县| 磐安县| 临泽县| 乐平市| 遂溪县| 庐江县| 辛集市| 南溪县| 博罗县| 井陉县| 长葛市| 福鼎市| 秀山| 衡山县| 南投市| 台州市| 宁南县| 恭城| 清新县| 宁强县| 吴桥县| 昌平区| 无锡市|