09 Browser Setup - biswajitsundara/Protractor GitHub Wiki

Protractor recommends two browsers chrome & firefox. However we can also test using internet explorer.

Driver Files

In selenium we download the webdrivers and set the path, here in protractor the drivers are downloaded when we execute webdriver-manager update command. The location of the files depend on how we have installed protractor.

  • If we have installed globally then it will be available under AppData/Roaming/npm/node_modules
  • If we have setup at project level then \node_modules\protractor\node_modules\webdriver-manager\selenium
  • By default the internet explorer driver is not available as protractor doesn't recommend it.
  • If we want to test for IE then use the command webdriver-manager update --ie
  • Check the driver location and you should see IE drivers.

Default Browser

The default browser is chrome.

Firefox browser

add this in conf.js file

capabilities:{
      'browserName': 'firefox'
}

Internet Explorer browser

 capabilities:{
      'browserName': 'internet explorer'
 }

Chrome browser

No need to set anything as chrome is the default browser however if we want to apply headless option etc.

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

Direct Connect

Protractor can directly test in chrome/firefox without using selenium server. Use directConnect: true in conf.js file.

  • Only chrome and firefox browser can be used with this option, for other browsers it will error out
  • The main reason for using this option is speed
  • Running the tests using selenium server allows us to run in remote machines using the ip address and port numbers also in different browser/browser versions.
  • Where as directConnect: true will run tests only on the local installation of FireFox and Chrome. It will run the test on the same machine where test codebase exist.
  • Best practice is to use selenium server

Testing Non Angular

As we know using protractor we can also test non angular web pages. Basically when protractor starts the browser it waits for the angular component to be loaded. If we use any non angular website then there won't be any angular component and it will error out with this error

Message:
    Failed: Angular could not be found on the page https://www.google.com/. 
    If this is not an Angular application, you may need to turn off waiting for Angular.

The error message suggests the solution, we need to disable the waiting for angular components by using browser.waitForAngularEnabled(false);

const { element, browser } = require("protractor");

describe('Protractor Practice Project', function () {
    it('Testing Non Angular WebPages', function () {
        browser.waitForAngularEnabled(false);
        browser.get('https://www.google.com/');
        element(by.css('input[name="q"]')).sendKeys("Biswajit");
    });
});

As a best practice don't mix non angular and angular pages.



Reference
https://www.protractortest.org/#/browser-setup
https://www.protractortest.org/#/server-setup
https://www.protractortest.org/#/timeouts

⚠️ **GitHub.com Fallback** ⚠️