我正在测试混合iOS移动应用程序。前两个屏幕是本机屏幕,然后是本地注册屏幕,然后是WebView。注册后,应用程序将返回本机屏幕。
我的问题是,对于WebView屏幕,Appium Inspector将其显示为本地屏幕。它为我提供了看起来像本机元素的xpath标识符(但在实际测试中很难识别)。
此外,我似乎无法与Appium中的这些屏幕进行交互,就好像它们是网络元素一样。当我尝试使用Web元素的ID识别它们时,Appium表示CSS选择器不是有效的定位器策略。我尝试添加一行代码,如果找到了,则会切换到一个webview,但是坦率地说,我在appium日志中看不到任何实际尝试这样做的迹象(尽管它也没有显示错误)。
我不知道这里正在发生什么,并且想要。
我正在使用Appium 1.13.0和1.14.0,并在模拟器(12.2)上运行iOS应用。我正在使用从https://github.com/webdriverio/appium-boilerplate派生的代码库。
Appium Inspector中的元素如下所示:
<XCUIElementTypeTextField type="XCUIElementTypeTextField" value="Username" label="" enabled="true" visible="true" x="40" y="224" width="294" height="60"/>
,检查员提供给我的定位器看起来像这样:
//XCUIElementTypeOther[@name="Login from mobile"]/XCUIElementTypeOther[4]/XCUIElementTypeTextField
但是在浏览器中,该元素如下所示:
<input id="username" name="username" placeholder="Username" type="text">
我的能力如下:
config.capabilities = [
{
// The defaults you need to have in your config
// browserName: 'safari',
platformName: 'iOS',
maxInstances: 1,
// For W3C the appium capabilities need to have an extension prefix
// This is `appium:` for all Appium Capabilities which can be found here
// http://appium.io/docs/en/writing-running-appium/caps/
'appium:deviceName': 'iPhone X',
'appium:platformVersion': '12.2',
'appium:orientation': 'PORTRAIT',
// `automationName` will be manatory, see
// https://github.com/appium/appium/releases/tag/v1.13.0
'appium:app': join(process.cwd(), './apps/AiView.app.zip'),
'appium:automationName': 'XCUITest',
'appium:newCommandTimeout': 240,
'autoAcceptAlerts': true,
'appium:noReset': false
},
];
我的实际测试摘要如下:
ParticipantLanguageScreen.setLanguageButton.click();
// That line is native code
driver.switchContext(this.getCurrentContexts()[1]);
ActivateLoginScreen.usernameInput.setValue(SC_USERNAME);
// That line should be a webview, but Appium is treating it as a native view
此定位器有效:
SC_USERNAME_INPUT: '//XCUIElementTypeOther[@name="Login from mobile"]/XCUIElementTypeOther[4]/XCUIElementTypeTextField'
但这不是:
SC_USERNAME_INPUT: '#username'
以下是鸦片记录的一部分:
[HTTP] --> POST /wd/hub/session/30491fcf-e3c4-41bf-bad0-bbf1cc71d2f9/element
[HTTP] {"using":"accessibility id","value":"SET PARTICIPANT LANGUAGE"}
[W3C (30491fcf)] Calling AppiumDriver.findElement() with args: ["accessibility id","SET PARTICIPANT LANGUAGE","30491fcf-e3c4-41bf-bad0-bbf1cc71d2f9"]
[XCUITest] Executing command 'findElement'
[BaseDriver] Valid locator strategies for this request: xpath, id, name, class name, -ios predicate string, -ios class chain, accessibility id
[BaseDriver] Waiting up to 0 ms for condition
[WD Proxy] Matched '/element' to command name 'findElement'
[WD Proxy] Proxying [POST /element] to [POST http://localhost:8100/session/1E3BE1C7-5210-49E5-B405-FEE9393DEEB8/element] with body: {"using":"accessibility id","value":"SET PARTICIPANT LANGUAGE"}
[WD Proxy] Got response with status 200: {"value":{"ELEMENT":"C2030000-0000-0000-CE45-000000000000"},"sessionId":"1E3BE1C7-5210-49E5-B405-FEE9393DEEB8","status":0}
[W3C (30491fcf)] Responding to client with driver.findElement() result: {"element-6066-11e4-a52e-4f735466cecf":"C2030000-0000-0000-CE45-000000000000","ELEMENT":"C2030000-0000-0000-CE45-000000000000"}
[HTTP] <-- POST /wd/hub/session/30491fcf-e3c4-41bf-bad0-bbf1cc71d2f9/element 200 104 ms - 137
[HTTP]
[HTTP] --> POST /wd/hub/session/30491fcf-e3c4-41bf-bad0-bbf1cc71d2f9/element/C2030000-0000-0000-CE45-000000000000/click
[HTTP] {}
[W3C (30491fcf)] Driver proxy active, passing request on via HTTP proxy
[XCUITest] Executing command 'proxyReqRes'
[WD Proxy] Matched '/wd/hub/session/30491fcf-e3c4-41bf-bad0-bbf1cc71d2f9/element/C2030000-0000-0000-CE45-000000000000/click' to command name 'click'
[WD Proxy] Proxying [POST /wd/hub/session/30491fcf-e3c4-41bf-bad0-bbf1cc71d2f9/element/C2030000-0000-0000-CE45-000000000000/click] to [POST http://localhost:8100/session/1E3BE1C7-5210-49E5-B405-FEE9393DEEB8/element/C2030000-0000-0000-CE45-000000000000/click] with body: {}
[WD Proxy] Got response with status 200: {"status":0,"id":"C2030000-0000-0000-CE45-000000000000","value":"","sessionId":"1E3BE1C7-5210-49E5-B405-FEE9393DEEB8"}
[WD Proxy] Replacing sessionId 1E3BE1C7-5210-49E5-B405-FEE9393DEEB8 with 30491fcf-e3c4-41bf-bad0-bbf1cc71d2f9
[HTTP] <-- POST /wd/hub/session/30491fcf-e3c4-41bf-bad0-bbf1cc71d2f9/element/C2030000-0000-0000-CE45-000000000000/click 200 391 ms - 118
[HTTP] --> POST /wd/hub/session/30491fcf-e3c4-41bf-bad0-bbf1cc71d2f9/element
[HTTP] {"using":"css selector","value":"#username"}
[W3C (30491fcf)] Calling AppiumDriver.findElement() with args: ["css selector","#username","30491fcf-e3c4-41bf-bad0-bbf1cc71d2f9"]
[XCUITest] Executing command 'findElement'
[BaseDriver] Valid locator strategies for this request: xpath, id, name, class name, -ios predicate string, -ios class chain, accessibility id
[W3C (30491fcf)] Encountered internal error running command: InvalidSelectorError: Locator Strategy 'css selector' is not supported for this session
[W3C (30491fcf)] at XCUITestDriver.validateLocatorStrategy (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/driver.js:366:13)
[W3C (30491fcf)] at XCUITestDriver.validateLocatorStrategy (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/lib/driver.js:991:11)
[W3C (30491fcf)] at XCUITestDriver.validateLocatorStrategy [as findElOrElsWithProcessing] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/commands/find.js:31:8)
[W3C (30491fcf)] at XCUITestDriver.findElOrElsWithProcessing [as findElement] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/commands/find.js:53:21)
[W3C (30491fcf)] at curCommandCancellable._bluebird.default.resolve.then (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/driver.js:305:66)
[W3C (30491fcf)] at tryCatcher (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/bluebird/js/release/util.js:16:23)
[W3C (30491fcf)] at Promise._settlePromiseFromHandler (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/bluebird/js/release/promise.js:517:31)
[W3C (30491fcf)] at Promise._settlePromise (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/bluebird/js/release/promise.js:574:18)
[W3C (30491fcf)] at Promise._settlePromiseCtx (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/bluebird/js/release/promise.js:611:10)
[W3C (30491fcf)] at _drainQueueStep (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/bluebird/js/release/async.js:142:12)
[W3C (30491fcf)] at _drainQueue (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/bluebird/js/release/async.js:131:9)
[W3C (30491fcf)] at Async._drainQueues (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/bluebird/js/release/async.js:147:5)
[W3C (30491fcf)] at Immediate.Async.drainQueues (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/bluebird/js/release/async.js:17:14)
[W3C (30491fcf)] at runCallback (timers.js:696:18)
[W3C (30491fcf)] at tryOnImmediate (timers.js:667:5)
[W3C (30491fcf)] at processImmediate (timers.js:649:5)
[HTTP] <-- POST /wd/hub/session/30491fcf-e3c4-41bf-bad0-bbf1cc71d2f9/element 400 96 ms - 2501
我希望Appium Inspector不会为我提供xpath且看起来像本机元素的元素定位器,并且我希望我的测试可以使用id属性标识Web元素来运行。