在Device Farm上运行测试时无法找到字段

时间:2018-06-11 18:17:16

标签: appium aws-device-farm

我正在尝试使用在AWS的Device Farm上运行的Java / TestNG编写测试;但是我找不到我的"帐户"字段。

HomePage.java

public class HomePage {

    @iOSFindBy(accessibility = "account")
    public IOSElement accountField;

    public HomePage(AppiumDriver driver) {
        PageFactory.initElements(new AppiumFieldDecorator(driver, 5, TimeUnit.SECONDS), this);
    }
}

测试类

@BeforeMethod
public void setup() throws MalformedURLException {
    DesiredCapabilities capabilities = DesiredCapabilities.iphone();
    driver = new IOSDriver<IOSElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}

@Test
public void selectAccount() throws InterruptedException {

    driver.manage().timeouts().implicitlyWait(35, TimeUnit.SECONDS);

    HomePage page = new HomePage(driver);
    new TouchAction(driver).tap(page.accountField).perform();
}

在设备场上运行此测试会出现此错误:

selectAccount failed: Can't locate an element by this strategy: Locator map: - native content: "By.AccessibilityId: account" - html content: "by id or name "account""

相关本地日志

...

[MJSONWP] Responding to client with driver.createSession() result: {"webStorageEnabled":false,"locationContextEnabled":false,"browserName":"","platform":"MAC","javascriptEnabled":true,"databaseEnabled":false,"takesScreenshot":true,"networkConnectionEnabled":false,"app":"/Users/..../Downloads/.....ipa","platformVersion":"11.3.1","automationName":"XCUITest","platformName":"iOS","udid":".....","deviceName":"iPhone SE"}
[JSONWP Proxy] Proxying [POST /elements] to [POST http://localhost:8100/session/1470E279-8FD3-4CFE-944C-051CDF7F2A25/elements] with body: {"using":"accessibility id","value":"account"}
[JSONWP Proxy] Got response with status 200: {"value":[{"ELEMENT":"0C000000-0000-0000-1701-000000000000"}],"sessionId":"1470E279-8FD3-4CFE-944C-051CDF7F2A25","status":0}
[MJSONWP] Responding to client with driver.findElements() result: [{"ELEMENT":"0C000000-0000-0000-1701-000000000000"}]

...

相关设备群日志

...

New IosDriver session created successfully, session 1dd93c26-55f6-4fdd-9963-2e3dbbc17386 added to master session list
[BaseDriver] Event 'newSessionStarted' logged at 1528814874003 (14:47:54 GMT+0000 (UTC))
[MJSONWP] Responding to client with driver.createSession() result: {\"webStorageEnabled\":false,\"locationContextEnabled\":false,\"browserName\":\"iPhone\",\"platform\":\"MAC\",\"javascriptEnabled\":true,\"databaseEnabled\":false,\"takesScreenshot\":true,\"networkConnectionEnabled\":false,\"platformName\":\"iOS\",\"version\":\"\",\"platformVersion\":\"9.3\",\"deviceName\":\".....\",\"app\":\"/tmp/scratch4iVs4j.scratch/share-CjbXpc.scratch/app-3ZPujz.ipa\",\"udid\":\".....\",\"desired\":{\"browserName\":\"iPhone\",\"platformName\":\"iOS\",\"version\":\"\",\"platform\":\"MAC\",\"platformVersion\":\"9.3\",\"deviceName\":\".....\",\"app\":\"/tmp/scratch4iVs4j.scratch/share-CjbXpc.scratch/app-3ZPujz.ipa\",\"udid\":\".....\"}}

...

[MJSONWP] Responding to client with driver.getCurrentContext() result: \"NATIVE_APP\"
<-- GET /wd/hub/session/1dd93c26-55f6-4fdd-9963-2e3dbbc17386/context 200 18 ms - 84
--> POST /wd/hub/session/1dd93c26-55f6-4fdd-9963-2e3dbbc17386/elements {\"using\":\"accessibility id\",\"value\":\"account\"}
[MJSONWP] Calling AppiumDriver.findElements() with args: [\"accessibility id\",\"account\",\"1dd93c26-55f6-4fdd-9963-2e3dbbc17386\"]
[iOS] Executing iOS command 'findElements'
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, -ios uiautomation, accessibility id
[BaseDriver] Waiting up to 0 ms for condition
[UIAuto] Sending command to instruments: au.getElementsByAccessibilityId('account')
[UIAuto] Socket data received (25 bytes)
[UIAuto] Got result from instruments: {\"status\":0,\"value\":[]}
[MJSONWP] Responding to client with driver.findElements() result: []
<-- POST /wd/hub/session/1dd93c26-55f6-4fdd-9963-2e3dbbc17386/elements 200 834 ms - 74

...

我在35秒隐式等待后进行了一次屏幕截图,并确认我的字段在页面上。

我也尝试过这种方法来选择帐户字段但没有成功:

@Test
public void selectAccount() throws InterruptedException {

    driver.manage().timeouts().implicitlyWait(35, TimeUnit.SECONDS);

    WebElement el = driver.findElement(By.name("account"));
    new TouchAction(driver).tap(el).perform();
}

有没有人知道如何找到我的&#34;帐户&#34;领域?这在本地使用appium。

1 个答案:

答案 0 :(得分:0)

我正在ADF中测试一个Android应用,并且遇到了相同的问题,但是设置automationName所需的功能对我来说很有效。

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