【发布时间】:2019-01-05 06:01:09
【问题描述】:
我正在尝试使用在 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"}]
...
相关 Device Farm 日志
...
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();
}
有人知道如何找到我的“帐户”字段吗?这在本地使用 appium 工作。
【问题讨论】:
-
能否请您添加来自设备场测试和本地执行的 appium 服务器日志?
-
当然!如果您需要他们提供更多信息,请告诉我。我试过弄乱设备功能但没有运气。我还尝试了其他几种技术来等待元素进入页面:我在
@iOSFindBy注释下方添加了@WithTimeout(time = 5000, unit = TimeUnit.MILLISECONDS),并在HomePage page = new HomePage(driver);之后添加了这个等待命令HomePage page = new HomePage(driver);,但没有成功。所有仍然在本地通过,只是不在设备场上 -
看起来设备场正在使用 uiautomation,我敢打赌您的本地日志正在使用 xcui。有机会的时候能确认一下吗?
-
如果是这种情况,请尝试使用 OS 级别为 10 或更高级别的 iOS 设备,然后查看是否可以正常工作。设备场应该选择 xcui 作为自动化名称,如果它没有在代码中设置,它可能会有所作为。
-
抱歉,回复晚了。我可以确认本地测试运行使用的是 xcui。 IOS 11 似乎可以在设备场上运行,但 IOS 10 及更低版本即使在将automationName 设备功能设置为 XCUITest 后也无法运行。离开github.com/appium/appium/blob/master/docs/en/drivers/…,这是我需要手动设置的唯一功能,因为设备场负责平台名称、平台版本、设备名称和应用程序功能,对吗?我是否缺少使 plus 电话也无法使用 IOS 11