如何操作两个不同的应用程序,它们应该同时在两个不同的模拟器(webdriverio)上相互通信?

问题描述 投票:0回答:1

我有两个应用程序,一个是给客户的,另一个是给拣货员的。客户插入订单后,选择器应用程序应收到一条通知,如果获得批准,客户订单状态将发生变化。 我正在尝试自动化上述场景,但是我无法在两个不同的模拟器上同时运行这两个应用程序。

运行时,应用程序在单个模拟器上打开,并且在不考虑应用程序应打开的顺序的情况下一个接一个地失败,并注意应用程序不应同时在同一个模拟器上打开。最后我收到这个错误:

`in "0: Given A user is on the toters app home tab"invalid session id: The session identified by 6bb7ce21-dcdd-49ee-b5b3-bd9b56abb8a1 is not knownat getErrorFromResponseBody (file:///C:/Users/Toters/Desktop/toters-automated-tests/node_modules/webdriver/build/utils.js:195:12)at NodeJSRequest._request (file:///C:/Users/Toters/Desktop/toters-automated-tests/node_modules/webdriver/build/request/index.js:193:23)at processTicksAndRejections (node:internal/process/task_queues:95:5)at async Browser.wrapCommandFn (file:///C:/Users/Toters/Desktop/toters-automated-tests/node_modules/@wdio/utils/build/shim.js:90:29)at async Browser.$ (file:///C:/Users/Toters/Desktop/toters-automated-tests/node_modules/webdriverio/build/commands/browser/$.js:74:17)at async Browser.wrapCommandFn (file:///C:/Users/Toters/Desktop/toters-automated-tests/node_modules/@wdio/utils/build/shim.js:90:29)at async Common.accessHomePage (file:///C:/Users/Toters/Desktop/toters-automated-tests/features/pageobjects/mobile/android/common/common.ts:29:18)at async World.<anonymous> (file:///C:/Users/Toters/Desktop/toters-automated-tests/features/step-definitions/mobile/android/dark-store/order.ts:10:5)at async wrapPromiseWithTimeout (C:\Users\Toters\Desktop\toters-automated-tests\node_modules@cucumber\cucumber\src\time.ts:55:10)at async Object.run (C:\Users\Toters\Desktop\toters-automated-tests\node_modules@cucumber\cucumber\src\user_code_runner.ts:86:16)[0-0] 2024-05-02T16:01:33.285Z INFO webdriver: COMMAND deleteSession()[0-0] 2024-05-02T16:01:33.285Z INFO webdriver: COMMAND deleteSession()[0-0] 2024-05-02T16:01:33.286Z INFO webdriver: [DELETE] http://0.0.0.0:4723/session/9bf0b941-f990-41bb-804e-afca003d57fe[0-0] 2024-05-02T16:01:33.286Z INFO webdriver: [DELETE] http://0.0.0.0:4723/session/de7d06d8-b0e7-4752-9021-ecd7dd50ebee[0-0] 2024-05-02T16:01:33.786Z INFO webdriver: RESULT null[0-0] 2024-05-02T16:01:33.863Z INFO webdriver: RESULT null[0-0] FAILED in MultiRemote - file:///C:/Users/Toters/Desktop/toters-automated-tests/features/features/mobile/dark-store/place.order.feature2024-05-02T16:01:33.987Z INFO @wdio/cli:launcher: Run onWorkerEnd hook2024-05-02T16:01:33.987Z INFO @wdio/cli:launcher: Run onComplete hook

鉴于我已经启动并运行了两个 Android 模拟器 客户应用程序、选择器应用程序

鉴于我已经在终端中运行了 appium 命令,因此在端口 4723 上启动 appium 服务器

鉴于端口 4728 和 4729 是免费的

鉴于我的 android.conf.ts 文件中有以下功能

capabilities: {
    customerApp: {
      capabilities: {
        platformName: "Android",
        "appium:app":
          "/Users/Toters/Desktop/toters-automated-tests/apps/app-staging-debug.apk",
        "appium:platformVersion": "11",
        "appium:deviceName": "customer-app",
        "appium:automationName": "UIAutomator2",
        "appium:systemPort": 4728, // It's good to specify different system ports if running multiple sessions
      },
    },
    pickerApp: {
      capabilities: {
        platformName: "Android",
        "appium:app":
          "/Users/Toters/Desktop/toters-automated-tests/apps/picker-staging-build.apk",
        "appium:platformVersion": "11",
        "appium:deviceName": "picker-app",
        "appium:automationName": "UIAutomator2",
        "appium:systemPort": 4729, // Example of a different system port
      },
    },
  },

并且考虑到我已经编辑了以下类型文件:node_modules@wdio ypes uild\index.d.ts 以在代码中的任何位置使用这些功能:

 declare global {     namespace WebdriverIO {             interface MultiRemoteBrowser {                 myAppiumDriver: WebdriverIO.Browser                 myChromeDriver: WebdriverIO.Browser             }         interface MochaOpts {             [key: string]: any;         }         interface JasmineOpts {             [key: string]: any;         }         interface CucumberOpts {             [key: string]: any;         }         interface ServiceOption extends Services.ServiceOption {         }         interface ReporterOption extends Reporters.Options {         }         interface Config extends Options.Testrunner {         }         interface HookFunctionExtension {         }         interface WDIODevtoolsOptions {         }         interface WDIOVSCodeServiceOptions {         }         interface BrowserRunnerOptions {         }         interface ChromedriverOptions extends DriverOptions {         }         interface GeckodriverOptions extends DriverOptions {         }         interface EdgedriverOptions extends DriverOptions {         }         interface SafaridriverOptions {         }     } }

并且鉴于我已经在 multiRemoteBrowser 的 node_modules\webdriverio uild ypes.d.ts 中声明了这两个功能

interface MultiRemoteBrowser extends MultiRemoteBrowserType { customerApp: WebdriverIO.Browser; pickerApp: WebdriverIO.Browser; }

鉴于我有一个 common.ts 文件,我正在其中编写代码 我已声明以下内容

const { customerApp, pickerApp } = multiremotebrowser;

这是我尝试启动两个设备的功能

  async accessHomePage() {
    while (
      !(await customerApp
        .$("[resource-id = 'com.toters.customer.staging:id/btnGetStarted']")
        .isExisting())
    ) {
      console.log("waiting for get started button to appear");
    }
    while (
      !(await pickerApp
        .$("[resource-id = 'com.toters.customer.staging:id/btnGetStarted']")
        .isExisting())
    ) {
      console.log("waiting for get started button to appear");
    }
  }
typescript android-emulator appium webdriver-io appium-android
1个回答
0
投票

查看评论,可能无法为 1 台设备使用 2 个 appium 服务器: https://discuss.appium.io/t/testing-multiple-apps-in-one-device-first-session-is-terminate-when-second-starts/37776

© www.soinside.com 2019 - 2024. All rights reserved.