zoukankan      html  css  js  c++  java
  • 3、第一个Appium测试

    运行脚本前环境准备:

    1、IDE,推荐使用IJ

    2、安装jdk环境,推荐>1.8

    3、准备一台真机或者模拟器

    4、SDK

    5、maven环境

    项目目录:

    CalculatorTest.java文件代码:
    package example;
    import org.openqa.selenium.*;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import io.appium.java_client.android.AndroidDriver;
    import java.net.MalformedURLException;
    import java.net.URL;
    public class CalculatorTest {
        public static AndroidDriver driver;
        public static void main(String[] args) throws MalformedURLException,
                InterruptedException {
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability("deviceName", "msm8953_64");
            capabilities.setCapability("automationName", "Appium");
            capabilities.setCapability("platformName", "Android");
            capabilities.setCapability("platformVersion", "6.0");
            capabilities.setCapability("appPackage", "com.android.calculator2");
            capabilities.setCapability("appActivity", ".Calculator");
            driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),
                    capabilities);
            driver.findElementByAndroidUIAutomator("text("1")").click();
            driver.findElementByAndroidUIAutomator("text("+")")  .click();
            driver.findElementByAndroidUIAutomator("text("6")").click();
            driver.findElementByAndroidUIAutomator("text("=")").click();
            Thread.sleep(2000);
            String result = driver.findElement(By.id("com.android.calculator2:id/result"))
                    .getText();
            System.out.println(result);
            driver.quit();
        }
    }

    pom.xml文件(配置java-client):

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.test1.cn</groupId>
        <artifactId>testC</artifactId>
        <version>1.0-SNAPSHOT</version>
    
    
        <dependencies>
            <dependency>
                <groupId>io.appium</groupId>
                <artifactId>java-client</artifactId>
                <version>3.2.0</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    
    
    </project>

    CalculatorTest.java代码较为简单,启动计算机,计算1+6,然后打印结果,pom.xml主要 配置java-client  下面我们对CalculatorTest.java代码进行详细分析

    deviceName:启动哪种设备,是真机还是模拟器? iPhone SimulatoriPad SimulatoriPhone Retina 4-inch
    Android EmulatorGalaxy S4...
    automationName: 使用哪种自动化引擎。 appium(默认) 还是 Selendroid
    platformName: 使用哪种移动平台。 iOS, Android, orFirefoxOS
    platformVersion: 指定平台的系统版本。 例如指的 Android 平台, 版本为 5.1
    appActivity: 待测试的 app Activity 名字。 比如 MainActivity.Settings。 注意, 原生 App 的话要在activity 前加个"."
    appPackage: 待测试的 app Java package。 比如 com.example.android.myAppcom.android.settings

    元素定位:

    driver.findElementByAndroidUIAutomator("text("1")").click();
    

     

  • 相关阅读:
    在安装SqlServer2008时,有一项安装程序支持规则,为什么重新启动计算机那一项总是失败
    在 ServiceModel 客户端配置部分中,找不到引用协定“WebServiceTest.WebServiceSoap”的默认终结点元素。这可能是因为未找到应用程序的配置文件,或者是因为客户端元素
    IIS7上设置MIME让其支持android和Iphone的更新下载
    c# 常用正则
    数据库增容方法
    初识MAC(由window到mac的转变适应)
    无需控件直接导出xls(csv)
    2017中国屏幕分辨率统计---UI设计应注重的问题
    网页制作基础及HTML教学模块安排
    传统教学设计模板
  • 原文地址:https://www.cnblogs.com/suim1218/p/8781462.html
Copyright © 2011-2022 走看看