菜鸟教程小白 发表于 2022-12-11 20:04:01

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 &#39;wd&#39;
import { config, port } from &#39;../appiumConfig&#39;

const driver = wd.promiseChainRemote(&#39;localhost&#39;, port)

describe(&#39;Login&#39;, () =&gt; {
beforeAll(async () =&gt; await driver.init(config))
afterAll(async () =&gt; await driver.quit())

it(&#39;Should get contexts&#39;, async () =&gt; {
    await driver.contexts((err, handle) =&gt; {
      if (err) { // Error!
      console.log(err)
      }
      console.log(handle)
    })
})
})
</code></pre>

<p>Appium 配置如下:</p>

<pre><code>&#34;ios-emulator&#34;: {
    &#34;platformName&#34;: &#34;iOS&#34;,
   &#34;platformVersion&#34;: &#34;11.3&#34;,
   &#34;deviceName&#34;: &#34;iPhone Simulator&#34;,
   &#34;app&#34;: &#34;./ios/build/Build/Products/Release-iphonesimulator/myApp.app&#34;
   }
</code></pre>

<p>我得到的错误是:</p>

<blockquote>
<p>{&#34;message&#34;:&#34; 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&#34;,&#34;status&#34;:13,&#34;cause&#34;:{&#34;status&#34;:13,&#34;value&#34;:{&#34;message&#34;:&#34;An
unknown server-side error occurred while processing the command.
Original error: connect ECONNREFUSED
::1:27753&#34;},&#34;sessionId&#34;:&#34;a55f921f-b98c-4304-bc8d-cf3af1a48cd4&#34;},&#34;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: {&#34;webStorageEnabled&#34;:false,&#34;locationContextEnabled&#34;:false,&#34;browserName&#34;:&#34;&#34;,&#34;platform&#34;:&#34;MAC&#34;,&#34;javascriptEnabled&#34;:true,&#34;databaseEnabled&#34;:false,&#34;takesScreenshot&#34;:true,&#34;networkConnectionEnabled&#34;:false,&#34;platformName&#34;:&#34;iOS&#34;,&#34;platformVersion&#34;:&#34;11.3&#34;,&#34;deviceName&#34;:&#34;iPhone Simulator&#34;,&#34;app&#34;:&#34;./ios/build/Build/Products/Release-iphonesimulator/MeruHealth.app&#34;,&#34;udid&#34;:&#34;DD7881BD-3D0A-4C5B-8774-993954C6D349&#34;}
&lt;-- POST /wd/hub/session 200 8543 ms - 467

--&gt; GET /wd/hub/session/f43492eb-baa3-40b3-88b4-9aea2745ff7b/contexts
{}
Calling AppiumDriver.getContexts() with args: [&#34;f43492eb-baa3-40b3-88b4-9aea2745ff7b&#34;]
Executing command &#39;getContexts&#39;
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: &#39;PID:27890&#39;
         id: &#34;PID:27890&#34;
         isProxy: false
         name: &#34;Meru Health&#34;
         bundleId: &#34;com.meruhealth.MeruHealthApp&#34;
         hostId: undefined
         isActive: 2
         isAutomationEnabled: false
         pageDict: []
Found app id key &#39;PID:27890&#39; for bundle &#39;com.meruhealth.MeruHealthApp&#39;
Trying out the possible app ids: PID:27890
Selecting app PID:27890 (try #20 of 20)
Sending &#39;_rpc_forwardGetListing:&#39; message to remote debugger
Receiving data from remote debugger: &#39;{&#34;__argument&#34;:{&#34;WIRApplicationIdentifierKey&#34;:&#34;PID:27890&#34;,&#34;WIRListingKey&#34;:{&#34;1&#34;:{&#34;WIRPageIdentifierKey&#34;:1,&#34;WIRTitleKey&#34;:&#34;JSContext&#34;,&#34;WIRTypeKey&#34;:&#34;WIRTypeJavaScript&#34;}}},&#34;__selector&#34;:&#34;_rpc_applicationSentListing:&#34;}&#39;
Received response from socket send: &#39;[&#34;PID:27890&#34;,{&#34;1&#34;:{&#34;WIRPageIdentifierKey&#34;:1,&#34;WI...&#39;
Page changed: {&#34;1&#34;:{&#34;WIRPageIdentifierKey&#34;:1,&#34;WIRTitleKey&#34;:&#34;JSContext&#34;,&#34;WIRTypeKey&#34;:&#34;WIRTypeJavaScript&#34;}}
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 &lt;anonymous&gt;
</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(&#39;wd&#39;)

const driver = wd.promiseChainRemote(server)
await driver.init(desired)
const contexts = await driver.contexts()
</code></pre>

<p>服务器日志:</p>

<pre><code>&gt; CALL init({&#34;platformName&#34;:&#34;iOS&#34;,&#34;platformVersion&#34;:&#34;11.1&#34;,&#34;deviceName&#34;:&#34;iPhone SE&#34;,&#34;automationName&#34;:&#34;XCUITest&#34;,&#34;noReset&#34;:true,&#34;app&#34;:&#34;/Users/dmitry/Downloads/Nigeria-TEST.app&#34;})
&gt; POST /session {&#34;desiredCapabilities&#34;:{&#34;platformName&#34;:&#34;iOS&#34;,&#34;platformVersion&#34;:&#34;11.1&#34;,&#34;deviceName&#34;:&#34;iPhone SE&#34;,&#34;automationName&#34;:&#34;XCUITest&#34;,&#34;noReset&#34;:true,&#34;app&#34;:&#34;/Users/dmitry/Downloads/Nigeria-TEST.app&#34;}}
Driving the web on session: 425b04c9-3f26-4f67-bd2e-f955ada0abbd
&gt; RESPONSE init({&#34;platformName&#34;:&#34;iOS&#34;,&#34;platformVersion&#34;:&#34;11.1&#34;,&#34;deviceName&#34;:&#34;iPhone SE&#34;,&#34;automationName&#34;:&#34;XCUITest&#34;,&#34;noReset&#34;:true,&#34;app&#34;:&#34;/Users/dmle/Downloads/test.app&#34;}) &#34;425b04c9-3f26-4f67-bd2e-f955ada0abbd&#34;,{&#34;webStorageEnabled&#34;:false,&#34;locationContextEnabled&#34;:false,&#34;browserName&#34;:&#34;&#34;,&#34;platform&#34;:&#34;MAC&#34;,&#34;javascriptEnabled&#34;:true,&#34;databaseEnabled&#34;:false,&#34;takesScreenshot&#34;:true,&#34;networkConnectionEnabled&#34;:false,&#34;platformName&#34;:&#34;iOS&#34;,&#34;platformVersion&#34;:&#34;11.1&#34;,&#34;deviceName&#34;:&#34;iPhone SE&#34;,&#34;automationName&#34;:&#34;XCUITest&#34;,&#34;noReset&#34;:true,&#34;app&#34;:&#34;/Users/dmle/Downloads/test.app&#34;,&#34;udid&#34;:&#34;2CA85561-B4B9-4C59-A83A-E197ADD4E0C8&#34;}
&gt; CALL contexts()
&gt; GET /session/:sessionID/contexts
&gt; RESPONSE contexts() [&#34;NATIVE_APP&#34;]
</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]
查看完整版本: javascript - Appium iOS获取上下文不起作用