zoukankan      html  css  js  c++  java
  • appium testcase1(Java)

    官网源码地址
    https://github.com/appium/sample-code/blob/47fc0305396b8322b727820ca55a07607395040c/sample-code/examples/java/junit/src/test/java/com/saucelabs/appium/AndroidContactsTest.java#

    1 package com.saucelabs.appium;
    2

    3 import io.appium.java_client.AppiumDriver;
    4 import io.appium.java_client.android.AndroidDriver;
    5

    6 import java.io.File;
    7 import java.net.URL;
    8 import java.util.List;
    9

    10 import org.junit.After;
    11 import org.junit.Before;
    12 import org.junit.Test;
    13 import org.openqa.selenium.By;
    14 import org.openqa.selenium.WebElement;
    15 import org.openqa.selenium.remote.CapabilityType;
    16 import org.openqa.selenium.remote.DesiredCapabilities;
    17

    18 public class AndroidContactsTest {
    19 private AppiumDriver driver;
    20

    21 @Before
    22 public void setUp() throws Exception {
    23 // set up appium
    24 File classpathRoot = new File(System.getProperty("user.dir"));
    25 File appDir = new File(classpathRoot, "../../../apps/ContactManager"); //目录位置对应好
    26 File app = new File(appDir, "ContactManager.apk");
    27 DesiredCapabilities capabilities = new DesiredCapabilities();
    28 capabilities.setCapability("deviceName","Android Emulator");
    29 capabilities.setCapability("platformVersion", "4.4");
    30 capabilities.setCapability("app", app.getAbsolutePath());
    31 capabilities.setCapability("appPackage", "com.example.android.contactmanager");
    32 capabilities.setCapability("appActivity", ".ContactManager");
    33 driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    34 }
    35

    36 @After
    37 public void tearDown() throws Exception {
    38 driver.quit();
    39 }
    40

    41 @Test
    42 public void addContact(){
    43 WebElement el = driver.findElement(By.name("Add Contact"));
    44 el.click();
    45 List textFieldsList = driver.findElementsByClassName("android.widget.EditText");
    46 textFieldsList.get(0).sendKeys("Some Name");
    47 textFieldsList.get(2).sendKeys("Some@example.com");
    48 driver.swipe(100, 500, 100, 100, 2);
    49 driver.findElementByName("Save").click();
    50 }
    51

    52 }

    调试时遇到问题1:AndroidDriver包找不到,原因是我前面导的包是java-client-1.2.1.jar,需要导入新的包java-client-2.1.0.jar,下载地址:https://search.maven.org/remotecontent?filepath=io/appium/java-client/2.1.0/java-client-2.1.0.jar
    import io.appium.java_client.android.AndroidDriver;

    调试时遇到问题2:调试时跑起来没问题,执行到44行时程序退出,eclipse的failure trace报的错是找不到element,考虑到43行元素已经定位都没问题,觉得应该是第二个页面元素还没找到,于是在44行后添加如下代码,等待页面加载
    try{Thread.sleep(10);}catch(Exception e){}

    调试时遇到问题3:定位行数为42,即@Test后的函数那行,这个问题基本都是由于appium没启动或者长时间开着的缘故,一般调试前最好重新launch下
    org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
    Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37'
    System info: host: 'PC201404231316', ip: '192.168.18.100', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_45'

  • 相关阅读:
    POJ 1251 Jungle Roads 最小生成树
    HDU 1879 继续畅通工程 最小生成树
    HDU 1875 畅通工程再续 最小生成树
    HDU 1863 畅通工程 最小生成树
    CodeForces 445B DZY Loves Chemistry (并查集)
    UVA 11987 Almost Union-Find (并查集)
    UVALive(LA) 4487 Exclusive-OR(带权并查集)
    UVALive 3027 Corporative Network (带权并查集)
    UVALive(LA) 3644 X-Plosives (并查集)
    POJ 2524 Ubiquitous Religions (并查集)
  • 原文地址:https://www.cnblogs.com/cingchen/p/4320506.html
Copyright © 2011-2022 走看看