zoukankan      html  css  js  c++  java
  • appium-desktop 环境搭建 Java版和python版

    python版的链接如下:

    链接:https://pan.baidu.com/s/10dIjiiI1il6KmQRO6jWwVg
    提取码:exjs

    Java版用的是appium-desktop1.8.1,testng6.11,java-client6.1.0,selenium-java3.13.0

    1、下载逍遥模拟器,装好app

    2、下载adb,用adb连接逍遥模拟器,找到abd路径,在cmd里cd D:platform-tools-latest-windowsplatform-tools ,  用 adb connect 127.0.0.1:21503

    3、用adb devices,查看是否连接到模拟器

    4、下载desktop版,然后配置url和端口号。下载地址是:https://github.com/appium/appium-desktop/releases/tag/v1.17.1-1

    5、启动server1.9.1,Start Inspector Session,配置Desired Capabilities,

    首先配置aapt的环境变量:类似于D:androidSDKuild-tools29.0.3,然后进入CMD

    使用aapt dump badging C:UsersAdministratorDownloadsxxx.apk(APK的全名),

    第一行获取包名,下拉到中间部分获取activity

    6、start session 进入到定位元素页面,大功告成,可以写脚本了

    7、第一个DEMO,创建maven项目,配置pom文件如下

    <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.test</groupId>
    <artifactId>AppiumLatest</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <dependencies>

    <!-- https://mvnrepository.com/artifact/org.testng/testng -->
    <dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.11</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
    <dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.7</version>
    </dependency>
    <dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>23.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/io.appium/java-client -->
    <dependency>
    <groupId>io.appium</groupId>
    <artifactId>java-client</artifactId>
    <version>6.1.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
    <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.13.0</version>
    </dependency>
    </dependencies>
    <build>
    <plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18.1</version>
    <configuration>
    <testFailureIgnore> false </testFailureIgnore>
    <suiteXmlFiles>
    <suiteXmlFile>testng.xml</suiteXmlFile>

    </suiteXmlFiles>
    </configuration>
    </plugin>
    </plugins>
    </build>
    </project>

    8、创建一个hahaha的类,如下

    package com.yidong.Test;


    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.concurrent.TimeUnit;

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.testng.Assert;
    import org.testng.annotations.AfterTest;
    import org.testng.annotations.BeforeTest;
    import org.testng.annotations.Test;

    import io.appium.java_client.android.AndroidDriver;
    import io.appium.java_client.remote.MobileCapabilityType;

    public class hahaha {

    static AndroidDriver<WebElement> driver;
    static DesiredCapabilities capabilities;

    @BeforeTest
    public static void start() throws MalformedURLException, InterruptedException{


    driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"),setCapsforMobileBrowser(capabilities));
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.findElement(By.id("com.creditease.android:id/btnStart")).click();
    driver.findElement(By.id("com.creditease.android:id/agree")).click();
    WebElement tvlift=driver.findElementById("com.creditease.android:id/tv_life");
    Assert.assertEquals(tvlift.isEnabled(), true);

    }

    @Test
    public void init() throws MalformedURLException, InterruptedException {

    try {
    start();


    } catch (Exception e) {
    System.out.println("inside catch");
    e.printStackTrace();
    }

    }


    public static DesiredCapabilities setCapsforMobileBrowser(DesiredCapabilities capabilities){

    capabilities = new DesiredCapabilities();
    capabilities.setCapability(MobileCapabilityType.APPIUM_VERSION, "1.8.1");
    capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "SM-A053F");
    capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1.1");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("appPackage", "com.creditease.android");
    capabilities.setCapability("appActivity", ".view.activity.home.SplashH5AdvertisementActivity");
    capabilities.setCapability("noRest", true);
    return capabilities;
    }

    @AfterTest
    public void tearDown(){
    driver.quit();

    }

    }

    9.运行,testng test,成功

  • 相关阅读:
    Leetcode 283. Move Zeroes
    利用脚本,一键设置java环境变量(默认安装路径)
    'wmic' 不是内部或外部命令,也不是可运行的程序 解决方法
    PowerShell因为在此系统中禁止执行脚本解决方法
    使用VBSCRIPT安装字体
    批处理基本知识以及进阶 V2.0
    Vbs 脚本编程简明教程之一
    用批处理,批量安装字体文件 (Erector.bat)
    windows 7 系统装机优化
    使用批处理替换windows系统中的hosts文件
  • 原文地址:https://www.cnblogs.com/hainabaichuan/p/9957881.html
Copyright © 2011-2022 走看看