Appium测试不在AWS Device Farm上运行,但在本地运行良好

时间:2018-08-07 16:43:46

标签: android maven appium aws-device-farm

我为使用Java和TestNG的Appium为Android应用程序编写了一些测试。我的测试在模拟器上本地运行良好,但是当我将它们上传到设备场时,我的测试总是失败。我已尽可能简化了测试,但仍然无法正常工作。目前,我正在尝试运行的测试会在打开应用后出现的提示中找到并单击权限允许按钮。代码:

module.exports = {
  mode: "development",
  entry: {
    bundle: "./main.ts",
},
  devtool: 'inline-source-map',
  module:{
    rules: [
        {
            test: /\.tsx?$/,
            include: [ path.resolve(__dirname, ".") ],
            use: {
                loader: 'ts-loader',
                loader: 'obfuscator-loader'
            },
            exclude: /node_modules/
        }

观看Device Farm提供的视频,我可以看到它打开了我的应用程序并立即将其关闭。它甚至没有像它应该等待的那样等待。我在这里不知所措,已经度过了很多小时,没有运气。我唯一能想到的是,在将文件上传到设备场之前压缩文件时,Maven发生了某些事情。任何建议表示赞赏。

编辑:Appium服务器日志(来自Device Farm)

package com.mycompany.app;

import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;

public class MyAppTest {

    public static AndroidDriver<MobileElement> driver;

    @BeforeClass
    public void Setup(){

        DesiredCapabilities cap = new DesiredCapabilities();

        try {
        driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), cap);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }


    }
    @Test
    public void authTest() {        

    WebDriverWait wait = new WebDriverWait(driver, 60);
  wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("com.android.packageinstaller:id/permission_allow_button")));   

    MobileElement allowBtn = (MobileElement) driver.findElement(By.id("com.android.packageinstaller:id/permission_allow_button"));
    allowBtn.click();

    }

@AfterTest
    public void teardown() {

        driver.quit();

    }

本地测试成功的Appium服务器日志:

   2018-08-09 19:21:52:790 - [debug] [MJSONWP] Calling AppiumDriver.findElements() with args: ["id","com.android.packageinstaller:id/permission_allow_button","e27184af-22d3-4a4e-8505-f2e47b35dc7f"]
2018-08-09 19:21:52:823 - [debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
2018-08-09 19:21:52:825 - [debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
2018-08-09 19:21:52:840 - [debug] [BaseDriver] Waiting up to 0 ms for condition
2018-08-09 19:21:52:936 - [debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.android.packageinstaller:id/permission_allow_button","context":"","multiple":true}}
2018-08-09 19:21:52:960 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.android.packageinstaller:id/permission_allow_button","context":"","multiple":true}}
2018-08-09 19:21:52:962 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
2018-08-09 19:21:52:963 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
2018-08-09 19:21:52:964 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'com.android.packageinstaller:id/permission_allow_button' using 'ID' with the contextId: '' multiple: true
2018-08-09 19:21:52:965 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[RESOURCE_ID=com.android.packageinstaller:id/permission_allow_button]
2018-08-09 19:21:52:966 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelector[RESOURCE_ID=com.android.packageinstaller:id/permission_allow_button]
2018-08-09 19:21:52:967 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Element[] is null: (0)
2018-08-09 19:21:52:976 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements tmp selector:UiSelector[INSTANCE=0, RESOURCE_ID=com.android.packageinstaller:id/permission_allow_button]
2018-08-09 19:21:52:977 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
2018-08-09 19:21:52:978 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'com.android.packageinstaller:id/permission_allow_button' using 'ID' with the contextId: '' multiple: true
2018-08-09 19:21:52:978 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[RESOURCE_ID=com.android.packageinstaller:id/permission_allow_button]
2018-08-09 19:21:52:979 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelector[RESOURCE_ID=com.android.packageinstaller:id/permission_allow_button]
2018-08-09 19:21:52:980 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Element[] is null: (0)
2018-08-09 19:21:52:981 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements tmp selector:UiSelector[INSTANCE=0, RESOURCE_ID=com.android.packageinstaller:id/permission_allow_button]
2018-08-09 19:21:52:981 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":[]}
2018-08-09 19:21:52:982 - [debug] [AndroidBootstrap] Received command result from bootstrap
2018-08-09 19:21:53:004 - [debug] [MJSONWP] Responding to client with driver.findElements() result: []
2018-08-09 19:21:53:018 - [HTTP] <-- POST /wd/hub/session/e27184af-22d3-4a4e-8505-f2e47b35dc7f/elements 200 247 ms - 74 
2018-08-09 19:21:53:600 - [HTTP] --> POST /wd/hub/session/e27184af-22d3-4a4e-8505-f2e47b35dc7f/elements {"using":"id","value":"com.android.packageinstaller:id/permission_allow_button"}
2018-08-09 19:21:53:602 - [debug] [MJSONWP] Calling AppiumDriver.findElements() with args: ["id","com.android.packageinstaller:id/permission_allow_button","e27184af-22d3-4a4e-8505-f2e47b35dc7f"]
2018-08-09 19:21:53:604 - [debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
2018-08-09 19:21:53:615 - [debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
2018-08-09 19:21:53:618 - [debug] [BaseDriver] Waiting up to 0 ms for condition
2018-08-09 19:21:53:620 - [debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.android.packageinstaller:id/permission_allow_button","context":"","multiple":true}}
2018-08-09 19:21:53:651 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.android.packageinstaller:id/permission_allow_button","context":"","multiple":true}}
2018-08-09 19:21:53:652 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
2018-08-09 19:21:53:652 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
2018-08-09 19:21:53:653 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'com.android.packageinstaller:id/permission_allow_button' using 'ID' with the contextId: '' multiple: true
2018-08-09 19:21:53:653 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[RESOURCE_ID=com.android.packageinstaller:id/permission_allow_button]
2018-08-09 19:21:53:666 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelector[RESOURCE_ID=com.android.packageinstaller:id/permission_allow_button]
2018-08-09 19:21:53:667 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Element[] is null: (0)
2018-08-09 19:21:53:679 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements tmp selector:UiSelector[INSTANCE=0, RESOURCE_ID=com.android.packageinstaller:id/permission_allow_button]
2018-08-09 19:21:54:032 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Element[] is null: (1)
2018-08-09 19:21:54:042 - [debug] [AndroidBootstrap] Received command result from bootstrap
2018-08-09 19:21:54:045 - [debug] [MJSONWP] Responding to client with driver.findElements() result: [{"ELEMENT":"1"}]
2018-08-09 19:21:54:064 - [HTTP] <-- POST /wd/hub/session/e27184af-22d3-4a4e-8505-f2e47b35dc7f/elements 200 446 ms - 89 
2018-08-09 19:21:54:079 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements tmp selector:UiSelector[INSTANCE=1, RESOURCE_ID=com.android.packageinstaller:id/permission_allow_button]
2018-08-09 19:21:54:085 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":[{"ELEMENT":"1"}]}
2018-08-09 19:21:54:160 - [HTTP] --> DELETE /wd/hub/session/e27184af-22d3-4a4e-8505-f2e47b35dc7f {}
2018-08-09 19:21:54:162 - [debug] [MJSONWP] Calling AppiumDriver.deleteSession() with args: ["e27184af-22d3-4a4e-8505-f2e47b35dc7f"]
2018-08-09 19:21:54:163 - [debug] [BaseDriver] Event 'quitSessionRequested' logged at 1533842514163 (19:21:54 GMT+0000 (UTC))
2018-08-09 19:21:54:174 - [Appium] Removing session e27184af-22d3-4a4e-8505-f2e47b35dc7f from our master session list
2018-08-09 19:21:54:178 - [debug] [AndroidDriver] Shutting down Android driver

2 个答案:

答案 0 :(得分:1)

我很抱歉延迟。我使用该应用编写了该测试,并且这些方法在Device farm(测试的video)中显示成功。

测试课程

package Tests;

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

import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;

public class DismissPopupTest{

     /**
     * Make the driver static. This allows it to be created only once
     * and used across all of the test classes.
     */
    public static AndroidDriver<MobileElement> driver;

    /**
     * This method runs before any other method.
     *
     * Appium follows a client - server model:
     * We are setting up our appium client in order to connect to Device Farm's appium server.
     *
     * We do not need to and SHOULD NOT set our own DesiredCapabilities
     * Device Farm creates custom settings at the server level. Setting your own DesiredCapabilities
     * will result in unexpected results and failures.
     *
     * @throws MalformedURLException An exception that occurs when the URL is wrong
     */
    @BeforeSuite
    public void setUpAppium() throws MalformedURLException {

        final String URL_STRING = "http://127.0.0.1:4723/wd/hub";

        URL url = new URL(URL_STRING);

        //Use a empty DesiredCapabilities object fro device farm
        DesiredCapabilities capabilities = new DesiredCapabilities();

        driver = new AndroidDriver<MobileElement>(url, capabilities);

        //Use a higher value if your mobile elements take time to show up
        driver.manage().timeouts().implicitlyWait(35, TimeUnit.SECONDS);
    }

    @Test
    public void authTest() {        

        WebDriverWait wait = new WebDriverWait(driver, 60);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("com.android.packageinstaller:id/permission_allow_button")));   

        MobileElement allowBtn = (MobileElement) driver.findElement(By.id("com.android.packageinstaller:id/permission_allow_button"));
        allowBtn.click();

    }



    /**
     * Always remember to quit
     */
    @AfterSuite
    public void tearDownAppium() {
        driver.quit();
    }

    /**
     * Restart the app after every test class to go back to the main
     * screen and to reset the behavior
     */
    @AfterClass
    public void restartApp() {
        driver.resetApp();
    }
}

Appium服务器日志显示在驱动程序上设置了隐式等待,并找到了元素。

Appium服务器日志

2018-08-27 04:35:19:589 - [HTTP] --> POST /wd/hub/session/2feb5200-b336-47d5-94ba-63c45d749af8/timeouts/implicit_wait {"ms":35000}
2018-08-27 04:35:19:627 - [debug] [MJSONWP] Calling AppiumDriver.implicitWait() with args: [35000,"2feb5200-b336-47d5-94ba-63c45d749af8"]
2018-08-27 04:35:19:630 - [debug] [BaseDriver] Set implicit wait to 35000ms
2018-08-27 04:35:19:631 - [debug] [MJSONWP] Responding to client with driver.implicitWait() result: null
2018-08-27 04:35:19:652 - [HTTP] <-- POST /wd/hub/session/2feb5200-b336-47d5-94ba-63c45d749af8/timeouts/implicit_wait 200 44 ms - 76 
2018-08-27 04:35:19:725 - [HTTP] --> POST /wd/hub/session/2feb5200-b336-47d5-94ba-63c45d749af8/element {"using":"id","value":"com.android.packageinstaller:id/permission_allow_button"}
2018-08-27 04:35:19:727 - [debug] [MJSONWP] Calling AppiumDriver.findElement() with args: ["id","com.android.packageinstaller:id/permission_allow_button","2feb5200-b336-47d5-94ba-63c45d749af8"]
2018-08-27 04:35:19:728 - [debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
2018-08-27 04:35:19:729 - [debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
2018-08-27 04:35:19:730 - [debug] [BaseDriver] Waiting up to 35000 ms for condition
2018-08-27 04:35:19:764 - [debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.android.packageinstaller:id/permission_allow_button","context":"","multiple":false}}
2018-08-27 04:35:19:785 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.android.packageinstaller:id/permission_allow_button","context":"","multiple":false}}
2018-08-27 04:35:19:821 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
2018-08-27 04:35:19:822 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
2018-08-27 04:35:19:822 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'com.android.packageinstaller:id/permission_allow_button' using 'ID' with the contextId: '' multiple: false
2018-08-27 04:35:19:823 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.android.packageinstaller:id/permission_allow_button]
2018-08-27 04:35:20:000 - [debug] [AndroidBootstrap] Received command result from bootstrap
2018-08-27 04:35:20:002 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":{"ELEMENT":"1"}}
2018-08-27 04:35:20:007 - [debug] [MJSONWP] Responding to client with driver.findElement() result: {"ELEMENT":"1"}
2018-08-27 04:35:20:032 - [HTTP] <-- POST /wd/hub/session/2feb5200-b336-47d5-94ba-63c45d749af8/element 200 298 ms - 87

然后单击该元素,弹出窗口被关闭

2018-08-27 04:35:20:113 - [HTTP] --> GET /wd/hub/session/2feb5200-b336-47d5-94ba-63c45d749af8/element/1/displayed {}
2018-08-27 04:35:20:114 - [debug] [MJSONWP] Calling AppiumDriver.elementDisplayed() with args: ["1","2feb5200-b336-47d5-94ba-63c45d749af8"]
2018-08-27 04:35:20:116 - [debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:getAttribute","params":{"attribute":"displayed","elementId":"1"}}
2018-08-27 04:35:20:145 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:getAttribute","params":{"attribute":"displayed","elementId":"1"}}
2018-08-27 04:35:20:145 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
2018-08-27 04:35:20:146 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: getAttribute
2018-08-27 04:35:20:162 - [debug] [AndroidBootstrap] Received command result from bootstrap
2018-08-27 04:35:20:163 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":"true"}
2018-08-27 04:35:20:163 - [debug] [MJSONWP] Responding to client with driver.elementDisplayed() result: true
2018-08-27 04:35:20:178 - [HTTP] <-- GET /wd/hub/session/2feb5200-b336-47d5-94ba-63c45d749af8/element/1/displayed 200 76 ms - 76 
2018-08-27 04:35:20:180 - [HTTP] --> POST /wd/hub/session/2feb5200-b336-47d5-94ba-63c45d749af8/element {"using":"id","value":"com.android.packageinstaller:id/permission_allow_button"}
2018-08-27 04:35:20:180 - [debug] [MJSONWP] Calling AppiumDriver.findElement() with args: ["id","com.android.packageinstaller:id/permission_allow_button","2feb5200-b336-47d5-94ba-63c45d749af8"]
2018-08-27 04:35:20:181 - [debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
2018-08-27 04:35:20:182 - [debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
2018-08-27 04:35:20:182 - [debug] [BaseDriver] Waiting up to 35000 ms for condition
2018-08-27 04:35:20:203 - [debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.android.packageinstaller:id/permission_allow_button","context":"","multiple":false}}
2018-08-27 04:35:20:218 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.android.packageinstaller:id/permission_allow_button","context":"","multiple":false}}
2018-08-27 04:35:20:235 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
2018-08-27 04:35:20:235 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
2018-08-27 04:35:20:236 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'com.android.packageinstaller:id/permission_allow_button' using 'ID' with the contextId: '' multiple: false
2018-08-27 04:35:20:251 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.android.packageinstaller:id/permission_allow_button]
2018-08-27 04:35:20:258 - [debug] [AndroidBootstrap] Received command result from bootstrap
2018-08-27 04:35:20:286 - [debug] [MJSONWP] Responding to client with driver.findElement() result: {"ELEMENT":"2"}
2018-08-27 04:35:20:290 - [HTTP] <-- POST /wd/hub/session/2feb5200-b336-47d5-94ba-63c45d749af8/element 200 107 ms - 87 
2018-08-27 04:35:20:311 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":{"ELEMENT":"2"}}
2018-08-27 04:35:20:312 - [HTTP] --> POST /wd/hub/session/2feb5200-b336-47d5-94ba-63c45d749af8/element/2/click {"id":"2"}
2018-08-27 04:35:20:313 - [debug] [MJSONWP] Calling AppiumDriver.click() with args: ["2","2feb5200-b336-47d5-94ba-63c45d749af8"]
2018-08-27 04:35:20:329 - [debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:click","params":{"elementId":"2"}}
2018-08-27 04:35:20:348 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"2"}}
2018-08-27 04:35:20:368 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
2018-08-27 04:35:20:384 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: click
2018-08-27 04:35:23:548 - [debug] [AndroidBootstrap] Received command result from bootstrap
2018-08-27 04:35:23:550 - [debug] [MJSONWP] Responding to client with driver.click() result: true
2018-08-27 04:35:23:568 - [HTTP] <-- POST /wd/hub/session/2feb5200-b336-47d5-94ba-63c45d749af8/element/2/click 200 3238 ms - 76 

鉴于到目前为止的所有信息,可能是代码测试包或结果混合在一起的情况。

我希望这会有所帮助。

-詹姆斯

答案 1 :(得分:-1)

设置automationName所需的功能对我来说很有效。

capabilities.setCapability("automationName", "uiautomator2");