【问题标题】:Test cross browser in the same test case using protractor使用量角器在同一测试用例中测试跨浏览器
【发布时间】:2020-05-29 22:41:38
【问题描述】:

我需要测试一个聊天应用程序,我想要测试的方式是打开一个 chrome 实例和另一个 Firefox 实例,并在两者之间发送消息。根据我的发现,我可以打开两个浏览器会话,但它们用于同一个应用程序并使用多种功能来跨平台测试所有测试用例。有没有人尝试过这个? 提前致谢。

编辑: 所以我将此添加到我的量角器配置中,我曾尝试在多个浏览器上测试相同的测试用例

  multicapabilities:[
    {
       browserName: 'chrome'
    },
    {
       browserName: 'firefox'
    }
  ]

我添加了这个,我能够在多个浏览器上独立运行相同的测试用例。

因为我需要在多个浏览器上运行测试用例。我发现我们可以使用 browser.forkNewDriverInstance()。这使我可以启动相同浏览器的多个窗口。这使我能够测试更多场景。现在我需要能够在同一个测试用例中测试多个浏览器(firefox、chrome)。

如果需要提供更多信息,请告诉我。

【问题讨论】:

  • 请详细说明您的尝试。发布代码示例并提供更多信息非常重要,以便有人能够查看并帮助您解决问题。

标签: angular selenium selenium-webdriver protractor cross-browser


【解决方案1】:

在搜索更多 stackoverflow 页面和 github 问题后。我发现这篇文章https://github.com/angular/protractor/issues/4962。这告诉我如何在同一个测试用例中同时启动 chrome 和 firefox。我使用的代码如下:

describe('Video Tests', () => {
    let ffBrowser: ProtractorBrowser;

    beforeAll(async () => {
        ffBrowser = await protractor.browser.forkNewDriverInstance().ready;
        (await ffBrowser.getProcessedConfig()).capabilities = {
          'browserName': 'firefox',
          'marionette': true,
          'moz:firefoxOptions': {
            'prefs': {
              'media.navigator.streams.fake': true,
              'media.navigator.permission.disabled': true
            }
          }
        } // new caps goes here;
        ffBrowser = await ffBrowser.restart();
    });

    it('testing cross browser', async () => {
      await browser.get(browser.baseUrl);
      await ffBrowser.get(browser.baseUrl);
      await browser.sleep(5000);
    });

    afterEach(async () => {
      // Assert that there are no errors emitted from the browser
      const logs = await browser.manage().logs().get(logging.Type.BROWSER);
      expect(logs).not.toContain(jasmine.objectContaining({
        level: logging.Level.SEVERE
      } as logging.Entry));
    });
  });

【讨论】:

    猜你喜欢
    • 2016-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-18
    • 2015-11-03
    • 2012-05-17
    • 2015-03-26
    • 1970-01-01
    相关资源
    最近更新 更多