zoukankan      html  css  js  c++  java
  • UI自动化框架-一个小demo

    一。 一个小demo

    先实现一个小demo,能够对appium的自动化有一定的了解,理解他的流程。pom配置

    <dependencies>
    <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>2.42.1</version>
    </dependency>
    <dependency>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.12.4</version>
    </dependency>
    <dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.8.8</version>
    </dependency>
    <dependency>
    <groupId>io.appium</groupId>
    <artifactId>java-client</artifactId>
    <version>3.2.0</version>
    </dependency>
    <dependency>
    <groupId>com.google.android</groupId>
    <artifactId>android</artifactId>
    <version>4.1.1.4</version>
    </dependency>
    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    </dependency>
    </dependencies>

    demo代码:

    先手动启动appium  server。在4723端口

    import io.appium.java_client.AppiumDriver;
    import io.appium.java_client.android.AndroidDriver;
    import org.junit.After;
    import org.junit.Before;
    import org.junit.Test;
    import org.openqa.selenium.By;
    import org.openqa.selenium.remote.DesiredCapabilities;
    
    import java.net.URL;
    
    public class demo1 {
    
    private AppiumDriver driver;
    
    @Before
    public void calc() throws Exception {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("clearSystemFiles","True");
    capabilities.setCapability("androidDeviceReadyTimeout",5);
    capabilities.setCapability("deviceName","hammerhead");
    capabilities.setCapability("platformVersion","5.0");
    capabilities.setCapability("platformName","Android");
    capabilities.setCapability("appPackage", "com.android.calculator2");
    capabilities.setCapability("appActivity", ".Calculator");
    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
    }
    
    @After
    public void tearDown() throws Exception {
    driver.quit();
    }
    
    @Test
    public void add() {
    driver.findElement(By.id("com.android.calculator2:id/digit_1")).click();
    driver.findElement(By.id("com.android.calculator2:id/op_add")).click();
    driver.findElement(By.id("com.android.calculator2:id/digit_2")).click();
    driver.findElement(By.id("com.android.calculator2:id/eq")).click();
    }
    }

    从这个简单的demo中可以看出:

    1. 启动appium server

    2. 配置capabilities

    3. 启动,获取driver

    4. 通过driver找到element。然后进行操作

  • 相关阅读:
    TCP的核心系列 — SACK和DSACK的实现(一)
    Linux2.6中的Slab层
    UVA 11549 Calculator Conundrum (Floyd判圈算法)
    2013第四届蓝桥杯决赛Java高职高专组题目以及解法答案
    hdu-Common Subsequence
    UVA 10869
    【Struts2学习笔记(3)】至Action注入属性值
    【winows7+android-ndk-r9+Cygwin 】cocos2dx 2.*游戏移植Android平台完全手册
    Ubuntu 14.04 64位字体美化(使用黑文泉驿)
    Android Fragment——详细解释
  • 原文地址:https://www.cnblogs.com/zqlmmd/p/12931757.html
Copyright © 2011-2022 走看看