javascript - Appium iOS获取上下文不起作用
<p><p>我正在开发一个 iOS React-Native 应用程序。现在我正在为登录功能进行集成测试。为了登录我们的应用程序,用户需要打开电子邮件并点击一个链接。</p>
<p>我想用 Appium 集成测试做什么:
- 打开 native 应用程序。
- 按应用程序中的按钮发送电子邮件
- 打开浏览器和gmail
- 查找电子邮件并单击链接登录
- 返回应用程序进行其余测试</p>
<p>但是,我在打开电子邮件时遇到了问题,我认为这是因为驱动程序的上下文有误。但是,当我尝试使用 <code>driver.contexts()</code> 函数获取可用上下文时,我只会收到一个错误并且根本没有上下文。 </p>
<p><strong>为什么 <code>driver.contexts()</code> 函数不起作用?我尝试做的事情合理吗?</strong></p>
<p>我的测试 stub 如下所示:</p>
<pre><code>import wd from 'wd'
import { config, port } from '../appiumConfig'
const driver = wd.promiseChainRemote('localhost', port)
describe('Login', () => {
beforeAll(async () => await driver.init(config))
afterAll(async () => await driver.quit())
it('Should get contexts', async () => {
await driver.contexts((err, handle) => {
if (err) { // Error!
console.log(err)
}
console.log(handle)
})
})
})
</code></pre>
<p>Appium 配置如下:</p>
<pre><code>"ios-emulator": {
"platformName": "iOS",
"platformVersion": "11.3",
"deviceName": "iPhone Simulator",
"app": "./ios/build/Build/Products/Release-iphonesimulator/myApp.app"
}
</code></pre>
<p>我得到的错误是:</p>
<blockquote>
<p>{"message":" Error response status: 13, , UnknownError -
An unknown server-side error occurred while processing the command.
Selenium error: An unknown server-side error occurred while processing
the command. Original error: connect ECONNREFUSED
::1:27753","status":13,"cause":{"status":13,"value":{"message":"An
unknown server-side error occurred while processing the command.
Original error: connect ECONNREFUSED
::1:27753"},"sessionId":"a55f921f-b98c-4304-bc8d-cf3af1a48cd4"},"jsonwire...</p>
</blockquote>
<p>函数文档:<a href="https://appium.io/docs/en/commands/context/get-contexts/" rel="noreferrer noopener nofollow">https://appium.io/docs/en/commands/context/get-contexts/</a> </p>
<p>Appium:1.7.2</p>
<p>Mac:10.13.4</p>
<p>平台版本:11.3</p>
<p>驱动程序:XCUITest</p>
<p>节点:8.10.0</p>
<p>npm:3.8.6</p>
<p>编辑:这也是我在 Appium 服务器上遇到的错误:</p>
<pre><code> Responding to client with driver.createSession() result: {"webStorageEnabled":false,"locationContextEnabled":false,"browserName":"","platform":"MAC","javascriptEnabled":true,"databaseEnabled":false,"takesScreenshot":true,"networkConnectionEnabled":false,"platformName":"iOS","platformVersion":"11.3","deviceName":"iPhone Simulator","app":"./ios/build/Build/Products/Release-iphonesimulator/MeruHealth.app","udid":"DD7881BD-3D0A-4C5B-8774-993954C6D349"}
<-- POST /wd/hub/session 200 8543 ms - 467
--> GET /wd/hub/session/f43492eb-baa3-40b3-88b4-9aea2745ff7b/contexts
{}
Calling AppiumDriver.getContexts() with args: ["f43492eb-baa3-40b3-88b4-9aea2745ff7b"]
Executing command 'getContexts'
Getting list of available contexts
Retrieving contexts and views
Selecting by url: false
Received app, but no match was found. Trying again.
Current applications available:
Application: 'PID:27890'
id: "PID:27890"
isProxy: false
name: "Meru Health"
bundleId: "com.meruhealth.MeruHealthApp"
hostId: undefined
isActive: 2
isAutomationEnabled: false
pageDict: []
Found app id key 'PID:27890' for bundle 'com.meruhealth.MeruHealthApp'
Trying out the possible app ids: PID:27890
Selecting app PID:27890 (try #20 of 20)
Sending '_rpc_forwardGetListing:' message to remote debugger
Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"PID:27890","WIRListingKey":{"1":{"WIRPageIdentifierKey":1,"WIRTitleKey":"JSContext","WIRTypeKey":"WIRTypeJavaScript"}}},"__selector":"_rpc_applicationSentListing:"}'
Received response from socket send: '["PID:27890",{"1":{"WIRPageIdentifierKey":1,"WI...'
Page changed: {"1":{"WIRPageIdentifierKey":1,"WIRTitleKey":"JSContext","WIRTypeKey":"WIRTypeJavaScript"}}
Received app, but no match was found. Trying again.
Error: Could not connect to a valid app after 20 tries.
at Object.wrappedLogger.errorAndThrow (../../lib/logging.js:78:13)
at RemoteDebugger.selectApp$ (../../lib/remote-debugger.js:277:6)
at tryCatch (/Users/valtterilaine/meruhealth-app/node_modules/appium-remote-debugger/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke (/Users/valtterilaine/meruhealth-app/node_modules/appium-remote-debugger/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) (/Users/valtterilaine/meruhealth-app/node_modules/appium-remote-debugger/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (/Users/valtterilaine/meruhealth-app/node_modules/appium-remote-debugger/node_modules/babel-runtime/regenerator/runtime.js:136:37)
at <anonymous>
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>它对我来说非常适合原生应用程序</p>
<p>wd.js v1.6.1</p>
<p>appium 服务器 v1.7.2</p>
<p>节点 v7.9.0</p>
<p>npm v4.2.0</p>
<p>Mac OS Sierra 10.12.6</p>
<p>代码与你的相似:</p>
<pre><code>const wd = require('wd')
const driver = wd.promiseChainRemote(server)
await driver.init(desired)
const contexts = await driver.contexts()
</code></pre>
<p>服务器日志:</p>
<pre><code>> CALL init({"platformName":"iOS","platformVersion":"11.1","deviceName":"iPhone SE","automationName":"XCUITest","noReset":true,"app":"/Users/dmitry/Downloads/Nigeria-TEST.app"})
> POST /session {"desiredCapabilities":{"platformName":"iOS","platformVersion":"11.1","deviceName":"iPhone SE","automationName":"XCUITest","noReset":true,"app":"/Users/dmitry/Downloads/Nigeria-TEST.app"}}
Driving the web on session: 425b04c9-3f26-4f67-bd2e-f955ada0abbd
> RESPONSE init({"platformName":"iOS","platformVersion":"11.1","deviceName":"iPhone SE","automationName":"XCUITest","noReset":true,"app":"/Users/dmle/Downloads/test.app"}) "425b04c9-3f26-4f67-bd2e-f955ada0abbd",{"webStorageEnabled":false,"locationContextEnabled":false,"browserName":"","platform":"MAC","javascriptEnabled":true,"databaseEnabled":false,"takesScreenshot":true,"networkConnectionEnabled":false,"platformName":"iOS","platformVersion":"11.1","deviceName":"iPhone SE","automationName":"XCUITest","noReset":true,"app":"/Users/dmle/Downloads/test.app","udid":"2CA85561-B4B9-4C59-A83A-E197ADD4E0C8"}
> CALL contexts()
> GET /session/:sessionID/contexts
> RESPONSE contexts() ["NATIVE_APP"]
</code></pre>
<p>您的日志状态错误 <code>ECONNREFUSED</code> 意味着您的 appium 服务已关闭,可能它在处理请求时崩溃了 -> 检查完整日志以了解发生了什么。</p>
<p>我想说这个问题很可能是因为您试图在同一个 session 中执行所有步骤(重用相同的驱动程序实例)。
尝试在单独的 session 中进行浏览器导航到 gmail,然后返回使用第一个继续进行应用程序测试。多个应用 session 开始使用 XCode 9,因此它可能会有所帮助。</p></p>
<p style="font-size: 20px;">关于javascript - Appium iOS获取上下文不起作用,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/49943098/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/49943098/
</a>
</p>
页:
[1]