如何在firefox浏览器上运行一些规格[它阻止],并在量角器中运行少量规格[它阻止]在Chrome浏览器上

时间:2019-06-12 19:13:43

标签: javascript protractor

说我有一个测试用例(一个js文件-说it),其中有10个规范[10 it个块]。现在,要求是我们需要在chrome浏览器中执行前8个it块,其余两个it块应在firefox中运行。

以另一种方式在需要时在#this is a function for a square matrix so on the while loop rows does not have to be less than cols. #you can make your own condition. But if you want your a square matrix, use this code. import random import numpy as np def random_matrix(R, cols): matrix = [] rows = 0 while rows < cols: N = random.sample(R, cols) matrix.append(N) rows = rows + 1 return np.array(matrix) print(random_matrix(range(10), 5)) #make sure you understand the function random.sample 块级别初始化浏览器。有什么方法/过程可以实现吗?

3 个答案:

答案 0 :(得分:0)

这种方式之一

it("Chrome specific test", async () => {

    let capabilities = await browser.getCapabilities();
    let browserName = capabilities.map_.get('browserName');

    if (browserName === "chrome") {
        // your test goes here
    } else {
        console.log("Test case will be skipped")
    }
});

答案 1 :(得分:0)

是的,有一个参数'restartBrowserBetweenTests',它使我们可以在每个it块上启动浏览器。

// An example configuration file.
exports.config = {
  directConnect: true,

  // Capabilities to be passed to the webdriver instance.
  capabilities: {
    'browserName': 'chrome'
  },

  // Framework to use. Jasmine is recommended.
  framework: 'jasmine',

  **restartBrowserBetweenTests: true,**

  // Spec patterns are relative to the current working directory when
  // protractor is called.
  specs: ['example_spec.js'],

  // Options to be passed to Jasmine.
  jasmineNodeOpts: {
    defaultTimeoutInterval: 30000
  }
};

您也可以在beforeEach中更改浏览器名称,该名称在每个it块之前执行。 示例代码:

 beforeEach(async function() {
      var config = await browser.getProcessedConfig();
      config.capabilities.browserName = 'firefox';

      browser.get('http://www.angularjs.org');

      todoList = element.all(by.repeater('todo in todoList.todos'));
    });

答案 2 :(得分:-1)

首先,量角器Jasmine / Mocha测试框架中没有支持单独运行'it'块的方式。

第二,在一个浏览器上运行8个测试用例,并在其他浏览器上运行这不是一个好主意。在多个浏览器上进行测试的目的是检查每个浏览器上的应用程序兼容性。为了实现这一目标,我们应该运行所有规范文件,并且在所有浏览器上将其阻止。

如果您仍然想这样做,则必须创建两个规格文件。一个包含8个it块,第二个包含2个it块。由于您需要在不同的浏览器上运行,因此,如果要避免手动更改配置文件,则必须创建两个配置文件才能分别运行规格文件。

相关问题