简体   繁体   English

使用Appium运行Web应用程序自动化的步骤

[英]Steps to run web application automation using Appium

I am having a lot of trouble trying to get my automated tests to run through a physical Android device using appium. 尝试让我的自动化测试在使用appium的物理Android设备上运行时遇到很多麻烦。 I am not so good with using cmd and configuring and there are very little tutorials on setting it up to run web apps. 我对使用cmd和配置不太满意,关于将其设置为运行Web应用程序的教程很少。 Heres what i have 这是我所拥有的

  1. Intellij automation project coded in Java. 用Java编码的Intellij自动化项目。 Tests are ran through testng xml files and synced up to browserstack. 测试通过testng xml文件运行,并同步到浏览器堆栈。
  2. I have downloaded Appium. 我已经下载了Appium。
  3. I have set up ANDROID_HOME variable in my path 我在路径中设置了ANDROID_HOME变量
  4. I have hooked up a device and can see it when I enter adb devices 我已经连接了一个设备,当我输入adb设备时可以看到它

I think I have most everything I need, but I dont know the steps to take or how to alter the desired capabilities to run it through my phone! 我想我拥有所需的大部分东西,但是我不知道要采取的步骤或如何更改所需的功能以通过手机运行它! Please, I know this is a broad question but if someone can shed some insight as to how to make this happen I would be forever grateful. 拜托,我知道这是一个广泛的问题,但是如果有人可以就如何实现这一目标提供一些见解,我将永远感激不已。 Thanks! 谢谢! Below is an example of how I have my tests set up in the xml file. 以下是如何在xml文件中设置测试的示例。

<test name="Standard Ad Regression">
    <parameter name="browserName" value="Android"/>
    <parameter name="device" value="Samsung Galaxy S5"/>
    <parameter name="emulator" value="true"/>
    <parameter name="browser_version" value=""/>
    <parameter name="platform" value="ANDROID"/>
    <parameter name="local" value="true"/>
    <parameter name="baseUrl" value="https://mywebsite.com/"/>
    <parameter name="os" value="os"/>
    <parameter name="os_version" value="4.4"/>
    <parameter name="resolution" value="1024x768"/>
    <parameter name="bsAccount" value="http://myusername:BcB9786AAvEoa45Fj@hub.browserstack.com/wd/hub"/>
    <classes>
        <class name="com.testsuites.regression.TestThis"/>
    </classes>
</test>

This is a pretty general question, but I have done pretty much exactly what you are attempting to do. 这是一个非常笼统的问题,但我所做的几乎就是您要尝试做的事情。

  1. Add Selenium and Appium Jars to Java Project 将Selenium和Appium Jars添加到Java项目
  2. Write your Java test scripts and initialise AndroidDriver: 编写Java测试脚本并初始化AndroidDriver:

I'm using a separate method to get the driver. 我正在使用一种单独的方法来获取驱动程序。 The reason I did this is so when I expanded my testing to run in parallel I did not need to redesign. 我这样做的原因是,当我将测试扩展到可以并行运行时,不需要重新设计。

    public static AndroidDriver getDriver(String udid) throws MalformedURLException{

    String URL = "XXXX";
    ThreadLocal<AndroidDriver> driver = null;  

    DesiredCapabilities capabilities = new DesiredCapabilities();       
    capabilities.setCapability("device", udid);
    capabilities.setCapability("deviceName", udid);
    capabilities.setCapability("udid", udid);
    capabilities.setPlatform(Platform.ANDROID);
    capabilities.setCapability("browserName", "Chrome");    

    try {
        driver = new ThreadLocal<AndroidDriver>();
        driver.set(new AndroidDriver(new URL(URL),
                capabilities));
    } catch (MalformedURLException e) {
        System.out.println("Tackle Issue with RemoteDriverSetup");
    }
    driver.get().manage().timeouts()
            .pageLoadTimeout(20L, TimeUnit.SECONDS);
    driver.get().manage().timeouts()
            .implicitlyWait(20L, TimeUnit.SECONDS);

    return driver.get();
    }
  1. Create your testNG.xml 创建您的testNG.xml

I am only passing the device's UDID through this file, I see you are using multiple parameters which is also fine. 我只是通过该文件传递设备的UDID,我看到您正在使用多个参数,这也很好。

<?xml version="1.0" encoding="UTF-8"?>
    <suite name="Suite" parallel="false">
        <test name="Nexus 7">
            <parameter name="udid"  value="XXXX" />
            <classes>
                <class name="testNG.TestOne"/>
            </classes>
        </test> <!-- Test -->
   </suite> <!-- Suite -->
  1. Start Appium Server 启动Appium服务器

Using the GUI you just need to press the button, make sure the URL used is the same one used to initialise the AndroidDriver. 使用GUI,您只需按一下按钮,确保使用的URL与用于初始化AndroidDriver的URL相同。

  1. Right click on testNG and run as Test Suite. 右键单击testNG并作为Test Suite运行。

If you have any problems, run Appium doctor and make sure everything is installed correctly. 如果您有任何问题,请运行Appium doctor并确保一切均已正确安装。

Hope this helps, 希望这可以帮助,

Liam 利亚姆

// Switch to WebView
    Set<String> contextNames = driver.getContextHandles();
    System.out.println(contextNames.size());
    for (String contextName : contextNames) {
        System.out.println(contextName);
        if (contextName.contains("WEBVIEW")){
            driver.context(contextName);
        }
    }

Then once you switched to webview you can use appium APIs in the same way but now those will interact with webviews. 然后,一旦您切换到Webview,就可以以相同的方式使用appium API,但是现在这些API将与Webview交互。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用appium自动化移动应用程序 - Automation mobile application using appium 使用Java实现Appium自动化 - appium automation using java 使用Selenium和Appium自动化Windows Phone应用程序 - Automation of Windows Phone Application with Selenium and Appium BrowserStack 不支持 swipeGesture - 使用 Appium 进行自动化 - Android - swipeGesture not supported by BrowserStack - Automation using Appium - Android Android应用程序自动化脚本:通过Appium,Selenium WebDriver,Java:NoSuchElementFoundException - Android application Automation Script: Through Appium, Selenium WebDriver, Java: NoSuchElementFoundException Maven为Web应用程序构建自动化 - Maven build Automation for a web Application 使用Java的Appium iOS自动化:使用可访问性ID获取元素? - Appium iOS automation using Java : get element using accessibility Id? 使用Appium查找Xpath for Mobile App(阻止我的自动化)的问题 - Issue in finding Xpath for Mobile App (Blocking my Automation) using Appium 使用Appium和Java进行移动测试自动化时,不会发生此类元素问题 - No such element issue occurring on mobile test automation using Appium and Java Appium 中的 Xpath 使用 Java - 移动应用程序 - 自动化测试 - Xpath in Appium Using Java - Mobile App - Automation testing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM