Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Browser capabilities - protractor 2 vs. protractor 3

Tags:

protractor

i've got an issue regarding my code and different behaviour depending on protractor-version used. My tests are working with protractor version 2.5.1. but to have all benefits from newest development i tried to move to version 3.x.

My onPrepare-function works fine with protractor version 2.5.1:

onPrepare: function () {  //configure junit xml report

    browser.getCapabilities().then(function (capabilities) {
        browser.capabilities = capabilities;
        browser.browserName = capabilities.caps_.browserName;
    });

    var jasmineReporters = require('jasmine-reporters');
    jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
        consolidateAll: true,
        filePrefix: 'frontendtests_result',
        savePath: 'reports'
    }));

    var htmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
    jasmine.getEnv().addReporter(
        new htmlScreenshotReporter({
            dest: 'screenshots',
            pathBuilder: function (currentSpec) {
                return browser.capabilities.get('platform') + '/' + browser.capabilities.get('browserName') + '/v.' + browser.capabilities.get('version') + '/' + currentSpec.fullName.substring(0, 4) + '/' + currentSpec.fullName;
            },
            preserveDirectory: false,
            ignoreSkippedSpecs: true,
            reportOnlyFailedSpecs: true,
            captureOnlyFailedSpecs: false,
            filename: 'my-report.html',
            reportTitle: 'End-to-end-Tests e.VISOR v.4.0 Development Status',
            showSummary: true,
            showQuickLinks: true
        })
  );
},



With protractor version 3.2.2 i got the following error message:

        C:\Program Files (x86)\nodejs\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1329
          return callbackFn(this.value_);
                 ^
    TypeError: Cannot read property 'browserName' of undefined
        at D:\SWE\Nitsch\Entwicklung\Hauptprojekt\Entwicklungszweig\Client\EnMS.Angular\EnMS\Frontendtests\protractor.config.js:83:53
        at Promise.invokeCallback_ (C:\Program Files (x86)\nodejs\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1329:14)
        at TaskQueue.execute_ (C:\Program Files (x86)\nodejs\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2790:14)
        at TaskQueue.executeNext_ (C:\Program Files (x86)\nodejs\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2773:21)
        at C:\Program Files (x86)\nodejs\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2652:27
        at C:\Program Files (x86)\nodejs\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:639:7
        at process._tickCallback (node.js:368:9)
    [launcher] Process exited with error code 1

The code line the error is conplaining about is

    browser.browserName = capabilities.caps_.browserName;

What is my mistake here? What is the differnce between protractor 2 and 3 regarding getting browser capabilities.

Any help is welcome ;)

Thanks in advance

Best regards

Akki

like image 519
Andreas 'Akki' Nitsch Avatar asked Apr 01 '16 14:04

Andreas 'Akki' Nitsch


2 Answers

It changed to capabilities.get('browserName').

like image 80
Davi Ferreira Avatar answered Oct 01 '22 03:10

Davi Ferreira


You can also Update your protractor.conf.js like this

capabilities: {
     'browserName': 'chrome',
     chromeOptions: { args: [ "--headless", "--disable-gpu", "--window-ze=800,600" ] } 
   },

this is for Chrome headless mode

like image 45
Rahul Solanki Avatar answered Oct 01 '22 01:10

Rahul Solanki