How do I open multiple windows or operate multiple instances

后端 未结 1 796
隐瞒了意图╮
隐瞒了意图╮ 2020-12-30 16:45

If for whatever crazy reason I need to open 100 windows/tabs and navigate to 100 different links in them how do I do that? Can I simultaneously run certain tests in all 100

相关标签:
1条回答
  • 2020-12-30 17:23

    It sounds terribly inefficient to kick off 100 different browsers just so they can run very similar scenarios. If those different values kick off the same flow, just slightly different output, you might want to use unit tests for those and run just one or few using protractor to test end-to-end.

    But to answer your question, there are two ways.

    1) multiCapabilities: Here, each browser will run a completely different test. (You might want to reuse a common component if your tests are similar).

    exports.config = {
      specs: [
        // leave this empty if you have no shared tests. 
      ],
    
      multiCapabilities: [{
        'browserName': 'chrome',
        'specs': ['test1.js']
      }, {
        'browserName': 'chrome',
        'specs': ['test2.js']
      }, {
        'browserName': 'chrome',
        'specs': ['test3.js']
      }],
    };
    

    Doc: https://github.com/angular/protractor/blob/master/docs/referenceConf.js

    2) browser.forkNewDriverInstance(): Here, you only run one test, but the test can spawn off n separate browsers. Disadvantage is that since everything is in just 1 test, if 1 case out of 100 fails, you'll just get a single failure.

    var runtest = function(input, output) {
      var newBrowser = browser.forkNewDriverInstance(true); // true means use same url
      // note I used newBrowser.element instead of element, because you are accessing the new browser. 
      newBrowser.element(by.model(...)).sendKeys(input).click();
      expect(newBrowser.element(by.css('blah')).getText()).toEqual(output);
    };
    
    describe('...', function() {
      it('spawn browsers', function() {
        browser.get(YOUR_COMMON_URL);
    
        runtest('input1', 'output1');
        runtest('input2', 'output2');
        runtest('input3', 'output3');
        runtest('input4', 'output4');
      });
    });
    

    Doc: https://github.com/angular/protractor/blob/master/docs/browser-setup.md#using-multiple-browsers-in-the-same-test

    0 讨论(0)
提交回复
热议问题