草庐IT

javascript - Appium iOS 获取上下文不工作

coder 2024-01-28 原文

我正在开发一个 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

苹果电脑: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: 'PID:27890'
[debug] [RemoteDebugger]         id: "PID: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 'PID: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":"PID:27890","WIRListingKey":{"1":{"WIRPageIdentifierKey":1,"WIRTitleKey":"JSContext","WIRTypeKey":"WIRTypeJavaScript"}}},"__selector":"_rpc_applicationSentListing:"}'
[debug] [RemoteDebugger] Received response from socket send: '["PID: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 操作系统 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/

有关javascript - Appium iOS 获取上下文不工作的更多相关文章

  1. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  2. ruby-on-rails - 'compass watch' 是如何工作的/它是如何与 rails 一起使用的 - 2

    我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t

  3. ruby - 无法让 RSpec 工作—— 'require' : cannot load such file - 2

    我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳

  4. ruby-on-rails - rspec should have_select ('cars' , :options => ['volvo' , 'saab' ] 不工作 - 2

    关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion在首页我有:汽车:VolvoSaabMercedesAudistatic_pages_spec.rb中的测试代码:it"shouldhavetherightselect"dovisithome_pathit{shouldhave_select('cars',:options=>['volvo','saab','mercedes','audi'])}end响应是rspec./spec/request

  5. ruby-on-rails - s3_direct_upload 在生产服务器中不工作 - 2

    在Rails4.0.2中,我使用s3_direct_upload和aws-sdkgems直接为s3存储桶上传文件。在开发环境中它工作正常,但在生产环境中它会抛出如下错误,ActionView::Template::Error(noimplicitconversionofnilintoString)在View中,create_cv_url,:id=>"s3_uploader",:key=>"cv_uploads/{unique_id}/${filename}",:key_starts_with=>"cv_uploads/",:callback_param=>"cv[direct_uplo

  6. ruby - 简单获取法拉第超时 - 2

    有没有办法在这个简单的get方法中添加超时选项?我正在使用法拉第3.3。Faraday.get(url)四处寻找,我只能先发起连接后应用超时选项,然后应用超时选项。或者有什么简单的方法?这就是我现在正在做的:conn=Faraday.newresponse=conn.getdo|req|req.urlurlreq.options.timeout=2#2secondsend 最佳答案 试试这个:conn=Faraday.newdo|conn|conn.options.timeout=20endresponse=conn.get(url

  7. ruby - 从 Ruby 中的主机名获取 IP 地址 - 2

    我有一个存储主机名的Ruby数组server_names。如果我打印出来,它看起来像这样:["hostname.abc.com","hostname2.abc.com","hostname3.abc.com"]相当标准。我想要做的是获取这些服务器的IP(可能将它们存储在另一个变量中)。看起来IPSocket类可以做到这一点,但我不确定如何使用IPSocket类遍历它。如果它只是尝试像这样打印出IP:server_names.eachdo|name|IPSocket::getaddress(name)pnameend它提示我没有提供服务器名称。这是语法问题还是我没有正确使用类?输出:ge

  8. ruby - 获取模块中定义的所有常量的值 - 2

    我想获取模块中定义的所有常量的值:moduleLettersA='apple'.freezeB='boy'.freezeendconstants给了我常量的名字:Letters.constants(false)#=>[:A,:B]如何获取它们的值的数组,即["apple","boy"]? 最佳答案 为了做到这一点,请使用mapLetters.constants(false).map&Letters.method(:const_get)这将返回["a","b"]第二种方式:Letters.constants(false).map{|c

  9. ruby-on-rails - 获取 inf-ruby 以使用 ruby​​ 版本管理器 (rvm) - 2

    我安装了ruby​​版本管理器,并将RVM安装的ruby​​实现设置为默认值,这样'哪个ruby'显示'~/.rvm/ruby-1.8.6-p383/bin/ruby'但是当我在emacs中打开inf-ruby缓冲区时,它使用安装在/usr/bin中的ruby​​。有没有办法让emacs像shell一样尊重ruby​​的路径?谢谢! 最佳答案 我创建了一个emacs扩展来将rvm集成到emacs中。如果您有兴趣,可以在这里获取:http://github.com/senny/rvm.el

  10. Ruby 从大范围中获取第 n 个项目 - 2

    假设我有这个范围:("aaaaa".."zzzzz")如何在不事先/每次生成整个项目的情况下从范围中获取第N个项目? 最佳答案 一种快速简便的方法:("aaaaa".."zzzzz").first(42).last#==>"aaabp"如果出于某种原因你不得不一遍又一遍地这样做,或者如果你需要避免为前N个元素构建中间数组,你可以这样写:moduleEnumerabledefskip(n)returnto_enum:skip,nunlessblock_given?each_with_indexdo|item,index|yieldit

随机推荐