我正在开发一个 iOS React-Native 应用程序。现在我正在为登录功能进行集成测试。为了登录我们的应用程序,用户需要打开电子邮件并点击一个链接。
我想用 Appium 集成测试做什么: - 打开 native 应用程序。 - 按应用程序中的按钮发送电子邮件 - 打开浏览器和gmail - 查找电子邮件并单击链接登录 - 返回应用程序进行其余测试
但是,我在打开电子邮件时遇到了问题,我认为这是因为驱动程序的上下文有误。但是,当我尝试使用 driver.contexts()
函数获取可用上下文时,我只会收到一个错误并且根本没有上下文。
为什么 driver.contexts()
函数不起作用?我尝试做的事情合理吗?
我的测试 stub 如下所示:
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)
})
})
})
Appium 配置如下:
"ios-emulator": {
"platformName": "iOS",
"platformVersion": "11.3",
"deviceName": "iPhone Simulator",
"app": "./ios/build/Build/Products/Release-iphonesimulator/myApp.app"
}
我得到的错误是:
{"message":"[contexts()] 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...
函数文档:https://appium.io/docs/en/commands/context/get-contexts/
Appium:1.7.2
Mac:10.13.4
平台版本:11.3
驱动程序:XCUITest
节点:8.10.0
npm:3.8.6
编辑:这也是我在 Appium 服务器上遇到的错误:
[debug] [MJSONWP] 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"}
[HTTP] <-- POST /wd/hub/session 200 8543 ms - 467
[HTTP]
[HTTP] --> GET /wd/hub/session/f43492eb-baa3-40b3-88b4-9aea2745ff7b/contexts
[HTTP] {}
[debug] [MJSONWP] Calling AppiumDriver.getContexts() with args: ["f43492eb-baa3-40b3-88b4-9aea2745ff7b"]
[debug] [XCUITest] Executing command 'getContexts'
[debug] [iOS] Getting list of available contexts
[debug] [iOS] Retrieving contexts and views
[debug] [iOS] Selecting by url: false
[debug] [RemoteDebugger] Received app, but no match was found. Trying again.
[debug] [RemoteDebugger] Current applications available:
[debug] [RemoteDebugger] Application: 'ID:27890'
[debug] [RemoteDebugger] id: "ID:27890"
[debug] [RemoteDebugger] isProxy: false
[debug] [RemoteDebugger] name: "Meru Health"
[debug] [RemoteDebugger] bundleId: "com.meruhealth.MeruHealthApp"
[debug] [RemoteDebugger] hostId: undefined
[debug] [RemoteDebugger] isActive: 2
[debug] [RemoteDebugger] isAutomationEnabled: false
[debug] [RemoteDebugger] pageDict: []
[debug] [RemoteDebugger] Found app id key 'ID:27890' for bundle 'com.meruhealth.MeruHealthApp'
[debug] [RemoteDebugger] Trying out the possible app ids: PID:27890
[debug] [RemoteDebugger] Selecting app PID:27890 (try #20 of 20)
[debug] [RemoteDebugger] Sending '_rpc_forwardGetListing:' message to remote debugger
[debug] [RemoteDebugger] Receiving data from remote debugger: '{"__argument":{"WIRApplicationIdentifierKey":"ID:27890","WIRListingKey":{"1":{"WIRPageIdentifierKey":1,"WIRTitleKey":"JSContext","WIRTypeKey":"WIRTypeJavaScript"}}},"__selector":"_rpc_applicationSentListing:"}'
[debug] [RemoteDebugger] Received response from socket send: '["ID:27890",{"1":{"WIRPageIdentifierKey":1,"WI...'
[debug] [RemoteDebugger] Page changed: {"1":{"WIRPageIdentifierKey":1,"WIRTitleKey":"JSContext","WIRTypeKey":"WIRTypeJavaScript"}}
[debug] [RemoteDebugger] Received app, but no match was found. Trying again.
[RemoteDebugger] Error: Could not connect to a valid app after 20 tries.
[RemoteDebugger] at Object.wrappedLogger.errorAndThrow (../../lib/logging.js:78:13)
[RemoteDebugger] at RemoteDebugger.selectApp$ (../../lib/remote-debugger.js:277:6)
[RemoteDebugger] at tryCatch (/Users/valtterilaine/meruhealth-app/node_modules/appium-remote-debugger/node_modules/babel-runtime/regenerator/runtime.js:67:40)
[RemoteDebugger] at GeneratorFunctionPrototype.invoke [as _invoke] (/Users/valtterilaine/meruhealth-app/node_modules/appium-remote-debugger/node_modules/babel-runtime/regenerator/runtime.js:315:22)
[RemoteDebugger] at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/Users/valtterilaine/meruhealth-app/node_modules/appium-remote-debugger/node_modules/babel-runtime/regenerator/runtime.js:100:21)
[RemoteDebugger] at GeneratorFunctionPrototype.invoke (/Users/valtterilaine/meruhealth-app/node_modules/appium-remote-debugger/node_modules/babel-runtime/regenerator/runtime.js:136:37)
[RemoteDebugger] at <anonymous>
它对我来说非常适合原生应用程序
wd.js v1.6.1
appium 服务器 v1.7.2
节点 v7.9.0
npm v4.2.0
Mac OS Sierra 10.12.6
代码与你的相似:
const wd = require('wd')
const driver = wd.promiseChainRemote(server)
await driver.init(desired)
const contexts = await driver.contexts()
服务器日志:
> 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"]
您的日志状态错误 ECONNREFUSED
意味着您的 appium 服务已关闭,可能它在处理请求时崩溃了 -> 检查完整日志以了解发生了什么。
我想说这个问题很可能是因为您试图在同一个 session 中执行所有步骤(重用相同的驱动程序实例)。 尝试在单独的 session 中进行浏览器导航到 gmail,然后返回使用第一个继续进行应用程序测试。多个应用 session 开始使用 XCode 9,因此它可能会有所帮助。
关于javascript - Appium iOS获取上下文不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49943098/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |