What is conf file

The Conf file is the trigger for the protractor package execution.

The execution of protractor starts from the conf file; some people also call it as a config file or protractor.config file. Conf file a javascript file, which will invoke the total framework for execution.

We can set different properties in a conf file like Remote machine ips, hubs, and nodes. Local machine configurations.

Conf file helps the user to set pre and post-completion actions for the test suites and for launches

Create Select class for handling dropdowns in protractor

Selenium parameters in Conf file

I have tried to explain important parameters, and I have omitted a few as they are not required.

seleniumServerJar :

The location of the standalone Selenium Server jar file, relative to the location of the webdriver-manager.

If we do not provide this parameter, protractor will search for the Selenium Server jar in the global default location, which is node_modules/protractor/node_modules/webdriver-manager/selenium/<jar file>.

But I do recommend using your own folders for placing the Selenium server jar and provide the relative or full path to the selenium Server Jar location.

Of course, this is not a mandatory parameter, so it is up to you whether to set or not.

seleniumServerJar: 'D:/Eclipse progs/jars/selenium-server-standalone-3.11.0.jar',

seleniumServerStartTimeout

The timeout milliseconds waiting for a local standalone Selenium Server to start.

If the seleniumserver did not start within the given time, then this will stop protractor execution. More precisely, it will not start the protractor execution.

By default protractor waits for 30000ms (30 seconds) for Selenium server to Open

seleniumServerStartTimeout:20000, // 20 seconds
Error Detail :Error: Error: Timed out waiting for the WebDriver server at https://192.168.0.165:65213/wd/hub

localSeleniumStandaloneOpts :

localSeleniumStandaloneOpts provides an option for the user to set the custom configuration like port, args, and JvmArgs.

All these parameters are optional parameters, which means if you do not provide a value, the protractor assigns them the default value.

  • port : The port to start the Selenium Server on; if we do not provide any port, then protractor will find a port itself and will open the Selenium server.
  • args : Additional command-line options to pass to selenium. For example, if you need to change the browser timeout, use seleniumArgs: ['-browserTimeout=60']
  • jvmArgs : Additional command line jvm options to pass to selenium. For example, if you need to change the browser driver location, use below one :
    jvmArgs: ['-Dwebdriver.ie.driver=IEDriverServer_Win32_2.53.1.exe']
    We can assign driver server location without using the above jvmArgs parameter.

Restart browser between tests

chromeDriver :

ChromeDriver location is used to help find the chromedriver.exe file. This will be passed to the Selenium jar as the system property webdriver.chrome.driver.

If the value is not set when launching locally, it will use the default values downloaded from the webdriver-manager.

chromeDriver: 'D:/Eclipse progs/driverserver/chromedriver.exe',

geckoDriver :

geckoDriver location is used to help find the geckodriver.exe file. This will be passed to the Selenium jar as the system property webdriver.gecko.driver.

If the value is not set when launching locally, it will use the default values downloaded from the webdriver-manager.

geckoDriver: 'D:/Eclipse progs/driverserver/geckodriver.exe',

seleniumAddress :

The address of a running Selenium Server. If specified, Protractor will connect to an already running instance of Selenium.

This usually looks like below code:

seleniumAddress: 'http://localhost:4444/wd/hub'


But most of the time, I do not set this parameter because it will throw below error sometimes:

Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:4444

seleniumSessionId :

The selenium session-id allows Protractor to attach to an existing selenium browser session.

The selenium session is maintained after the test has completed. Ignored if seleniumAddress is null.

I did not explore this option much; I would not be able to provide for this.

Element vs ElementFinder in Protrcator

directConnect :

If true, Protractor will connect directly to the browser Drivers at the locations specified by chromeDriver and firefoxPath.

Only Chrome and Firefox are supported for direct connect.

directConnect: false/true,

firefoxPath :

Sometimes the firefox might be installed in some custom path; in those cases, firefoxPath helps us to set the path to the firefox.exe file.

This would be very useful if you are trying to perform version testing.

firefoxPath: "C:/Program Files/Mozilla Firefox/Firefox 54/firefox.exe",

Click Element with JSE

specs

specs parameter is an Arrays, which holds the tests file location for running the files.

You can also provide regular expression inside the specs file to find the test files.

We can provide the locations relative to this conf.js file or full locations like below.

specs: ['D:Protractor Demospecs	est.js']

specs: ['D:Protractor Demospecs*.js'] // will run all the files with js extension

If you do not set any value then, protractor will say no specs found.

exclude :

We can exclude test files using the exclude parameter in the conf.js file. Exclude parameter will be useful when you do not want to run only a few tests or a folder.

Exclude also accepts Array as parameter values, also responds to a regular expression.

exclude: ['D:Protractor Demospecsdummytest.js']

Suites :

We can create suites instead of Specs when we want to categorize the test. When run without a command line parameter, all suites will run.

If you run with --suite=smoke or --suite=smoke, full only the patterns matched by the specified suites will run.

suites: {
  smoke: 'spec/smoketests/*.js',
  sanity: 'spec/sanitytests/*.js',
  full: 'spec/*.js'
}

suite :

If you would like protractor to use a specific suite by default instead of all suites, you can put that in the config file as well.

To use suite parameter, configuring suites parameter is very important.

suite:sanity,

Handle Authentication Pop Up in Protractor

capabilities/Browser Parameters in Conf.js file

Protractor can launch your tests on one or more browsers. If you are testing on a single browser, use the capabilities option.

If you are testing on multiple browsers, use the multiCapabilities array.

browserName :

The name of the browser on which we want to execute tests in Protractor

logName :

The User-defined name for the capability that will display in the results log. Protractor considers the browser name as logName if we do not provide logName.

count :

The Number of times to run this set of capabilities (in parallel, unless limited by maxSessions). The default is 1.

shardTestFiles :

If this is set to be true, specs will be shared by file (i.e., all files to be run by this set of capabilities will run in parallel).

This parameter is used in parallel running to divide the files.

For Example, 3 Browsers running 9 files, if we set this value is true, then 3 browsers divide the files among them. So 3 files will be shared by each browser.

But if we set this parameter to false then, each browser will execute 9 files ( total 27 files)

The Default value of the shardTestFiles value is false.

maxInstances :

The maximum number of browser instances that can run in parallel for this set of capabilities. This is only needed if shardTestFiles is true.

specs :

Additional spec files to be run on this capability only.

exclude :

Spec files to be excluded on this capability only; if there are some tests which you expect to run only in firefox, then you can exclude them for chrome browser capabilities so that the chrome browser will not execute the test related to firefox only.

seleniumAddress :

Optional: override global seleniumAddress on this capability only.

Handle more than Two Browser Windows with the protractor

Multi-Capabilities/Grid Parameters in Conf.js file in Protractor

multiCapabilities :

If you would like to run more than one instance of WebDriver on the same tests, use multiCapabilities, which takes an array of capabilities.

If this is specified, capabilities will be ignored.

getMultiCapabilities :

If you need to resolve multiCapabilities asynchronously (i.e., wait for server/proxy, set firefox profile, etc.), you can specify a function here which will return either `multiCapabilities` or a promise to `multiCapabilities`.

If this returns a promise, it is resolved immediately after `beforeLaunch` is run, and before any driver is set up. If this is specified, both capabilities and multiCapabilities will be ignored.

maxSessions :

The maximum number of total browser sessions to run. Tests are queued in sequence if the number of browser sessions is limited by this parameter. Use a number less than 1 to denote unlimited. The default is unlimited.

verboseMultiSessions :

Whether or not to buffer output when running tests on multiple browsers in parallel. By default, when running multiple browser sessions, the results are buffered and not logged until the test run finishes.

If true, when running multiple sessions in parallel, results will be logged when each test finishes.

Protractor Interview Questions

Global information in Conf.js in Protractor

baseUrl :

A base URL for your application under test. Calls to protractor.get() with relative paths will be resolved against this URL (via url.resolve)

rootElement :

Presently not used, and I would not suggest to use it

A CSS Selector for a DOM element within your Angular application. Protractor will attempt to automatically find your application, but it is necessary to set rootElement in certain cases.

In Angular 1, Protractor will use the element your app bootstrapped to by default. If that doesn't work, it will then search for hooks in `body` or `ng-app` elements (details here: https://git.io/v1b2r).

In later versions of Angular, Protractor will try to hook into all angular apps on the page. Use rootElement to limit the scope of which apps Protractor waits for and searches within.

allScriptsTimeout :

The timeout in milliseconds for each script run on the browser. This should be longer than the maximum time your application needs to stabilize between tasks.

getPageTimeout :

How long to wait for a page to load, if the page does not load within the given time, then the test will be failed.

XPath in Protractor

Hooks in the protractor conf file

beforeLaunch :

A callback function called once configs are read but before any environment setup. This will only run once, and before onPrepare.

You can specify a file containing code to run by setting beforeLaunch to the filename string.

At this point, the global variable protractor object will NOT be set up, and globals from the test framework will NOT be available. The main purpose of this function should be to bring up test dependencies.

onPrepare :

A callback function called once protractor is ready and available, and before the specs are executed.

If multiple capabilities are being run, this will run once per capability.

You can specify a file containing code to run by setting onPrepare to the filename string. onPrepare can optionally return a promise, which Protractor will wait for before continuing execution.

This can be used if the preparation involves any asynchronous calls, e.g., interacting with the browser. Otherwise, Protractor cannot guarantee the order of execution and may start the tests before preparation finishes.

At this point, the global variable protractor object will be set up, and globals from the test framework will be available.

onComplete :

A callback function called once tests are finished. onComplete can optionally return a promise, which Protractor will wait for before shutting down webdriver.

At this point, tests will be done, but global objects will still be available.

onCleanUp :

A callback function called once the tests have finished running, and the WebDriver instance has been shut down. It is passed the exit code (0 if the tests passed). This is called once per capability.

afterLaunch :

A callback function called once all tests have finished running, and the WebDriver instance has been shut down. It is passed the exit code (0 if the tests passed).

afterLaunch must return a promise if you want the asynchronous code to be executed before the program exits.

This is called only once before the program exits (after onCleanUp).

Switch to Default Content

Params in Protractor config.js file

The params object will be passed directly to the Protractor instance and can be accessed from your test as browser.params. It is an arbitrary object and can contain anything you may need in your test.

This can be changed via the command line as: --params.login.user "Joe"

params: {
  login: {
    user: 'Jane',
    password: '1234'
  }
}

Protractor Interview Questions

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions
  • Snehal
    Hi,Can you provide any topic on sorting table ? Validation for sorted data
    Reply
  • Naveen
    HI KarthiQ,
    
    Really its a wonderful job done by you. Frankly speaking your articles are awesome buddy and also it tells how much hardwork you have put up on this. I dont comment normally in any blogs but for the first time i felt this is the genuine articles made with accurate details. i have subscribed your youtube channel as well. Expecting more and more videos from you on Protractor.
    
    My personal suggestions :
    > Please organize the articles as in order from basic and advanced as well , so that would help many people who want to start with and how to proceed from one article to another.
    > Please share the code in github-which you are using in videos - since examples are completely different which are used in videos and your blog articles.
    
    Thanks again for your hard work  - Happy Learning :)
    
    Thanks,
    B.V.Naveen 
    Reply