【问题标题】:In protractor can I define the browser specially to the spec because I want to run 2 specs in 2 different browsers在量角器中,我可以专门为规范定义浏览器,因为我想在 2 个不同的浏览器中运行 2 个规范
【发布时间】:2019-12-18 11:51:27
【问题描述】:

我有 2 个规范需要在非并行模式下运行,1 个规范应该在 chrome 中运行,其他在 firefox 中。

这是我的 config.js

   exports.config = {
  framework: 'jasmine',
//Potractor will run tests in parallel against each set of capabilities. 
//Please note that if multiCapabilities is defined, the runner will ignore the capabilities configuration   

    multiCapabilities: [{
        'name': 'test1',
        browserName: 'firefox',
        'moz:firefoxOptions': {
            args: ['--verbose'],
            binary: 'C:/Program Files/Mozilla Firefox/firefox.exe',
            specs: ['src/com/sam/scriptjs/iframes.spec.js']
        },
        }, {
            'name': 'test2',
          browserName: 'chrome',
          specs: ['src/com/sam/scriptjs/rightclickme.spec.js']
        }],
  seleniumAddress: 'http://localhost:4444/wd/hub'

}

这是我的 chrometest.spec.js describe('chrome desc', function() {

  it('Navigae to the site using chrome', function() {         
        browser.driver.get(browser.baseUrl);
        expect(browser.getTitle()).toEqual('Super Calculator');

  });
  });

这是我的 firefoxtest.spec.js。请让我知道是否有办法,我已经检查了类似的How to, so to speak, restart or close browser after every protractor -spec test,但这不足以解决我的查询。谢谢。

describe('firefox desc', function() {
      it('Navigae to the site using firefox', function() {        
            browser.driver.get(browser.baseUrl);
            expect(browser.getTitle()).toEqual('Super Calculator');

      });
      });     

【问题讨论】:

    标签: jasmine protractor


    【解决方案1】:

    我认为这可以通过多能力而不是能力来实现。你可以试试下面的sn-p吗?

    multiCapabilities: [{
        'name': 'test1',
        'browserName': 'chrome',
        specs: ['chrometest.spec.js']
      }, {
        'name': 'test2',
        'browserName': 'firefox',
        specs: ['firefoxtest.spec.js']
      }],
    

    希望这会有所帮助!

    【讨论】:

    • 感谢 dheeraj 的建议,我修改了我的配置,js,请在我编辑的问题中查看。但是,现在它会抛出新的错误('Spec patterns did not match any files.');
    • spec 文件路径似乎有些问题,您可以试试 ['./src/com/sam/scriptjs/rightclickme.spec.js'] 之类的东西。还有看起来应该是'rightclickme.spec.js'而不是逗号,可能是错字。
    • 谢谢我纠正了我的错字。现在它抛出 crossbrowerconfig.js:15 规格:['src/com/sam/scriptjs/nonangularstackscript.js'] ^^^^^
    • 您能否简要介绍一下控制台中的确切错误。我没有收到问题
    • Hi dheeraj 感谢您的支持,我设法通过添加几行来解决它。现在错误消失了,我也不得不删除 name': 'test1',因为它抛出了一个错误。再次感谢,祝你有美好的一天。
    【解决方案2】:

    经过 dhreeraj 的回答和一些进一步的阅读,下面的 config.js 在量角器和 Jasmine 的 5.4.2 版本中为我工作。

        exports.config = {
      framework: 'jasmine',
      directConnect: false,
    
    
      multiCapabilities: [{
          browserName: 'firefox',
          'moz:firefoxOptions': {
                args: ['--verbose'],
                binary: 'C:/Program Files/Mozilla Firefox/firefox.exe'
           //Need to start cmd via admin mode to avoid permission error
            },
          specs: ['src/com/sam/scriptjs/draganddrop.spec.js']
        }, 
        {
            browserName : 'chrome',
            chromeOptions: {
                args: [ "--start-maximized" ]
                         },
            specs: ['src/com/sam/scriptjs/iframes.spec.js']
    
        }],
        maxSessions: 1,//To run in sequential mode so first Firefox then chrome 
        //without max session it will open two windows at the same time for both browsers
         seleniumAddress: 'http://localhost:4444/wd/hub'
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-23
      • 1970-01-01
      • 2015-03-05
      • 2018-04-16
      • 1970-01-01
      相关资源
      最近更新 更多