0

我正在开发一个expo应用程序,并希望将我的 Appium 的自动化测试集成到Browwserstack

但是我对webdriver.io有点迷茫。

我的测试使用这个工作流在本地工作:

  • appium我首先使用简单的命令行启动 Appium 服务器
  • 然后我使用 Jest 来触发测试:jest automatedTests/login.test.js --testTimeout=900000

这是我的测试样本的代码:

import { remote } from 'webdriverio';

const capabilities = {
  platformName: 'android',
  deviceName: 'Pixel',
  avd: 'Pixel',
  automationName: 'UiAutomator2',
  appPackage: 'com.myapp.slug',
  appActivity: 'host.exp.exponent.MainActivity',
  appWaitForLaunch: true,
};

const options = {
  path: '/wd/hub/',
  port: 4723,
};

describe("Test suite", () => {
 let client;

  beforeAll(async () => {
     client = await remote({ ...options, capabilities });
  });

  it('should test my app', async () => {
    const fieldLogin = await client.$('~login');
    const loginBtn = await client.$('~loginSubmit');
    await fieldLogin.isDisplayed();
  });

});

正如浏览器堆栈文档提到的那样,我已将这些属性添加到我的功能中:

'browserstack.user' : '<username>',
'browserstack.key' : '<key>',

// Set URL of the application under test
'app' : 'bs://<app-id>',

问题是BrowserStackSample.js他们使用promiseRemote

 driver = wd.promiseRemote("http://hub-cloud.browserstack.com/wd/hub");
 driver
  .init(capabilities)
  //  Write your code here
  .fin(function() { 
     return driver.quit(); })
  .done();

这似乎返回了driver对象,而不是client我曾经拥有的......

然后我面临这个错误:TypeError: driver.$ is not a function如果我试图将驱动程序用作客户端对象。

我怎样才能让我的测试运行?

PS:我也尝试过像这样等待 promiseRemote 没有运气:

const amIClient = await wd.remote('http://hub-cloud.browserstack.com/wd/hub');
await amIClient.init(desiredCaps);
return amIClient;
4

0 回答 0