Protractor – Good practices

protractor best practices
Reading Time: 3 minutes

        When deciding to implement protractor front-end system tests, it is important to think first how to organize the test suites in a way that permits you to run only selective tests if needed or to easily run different test cases in parallel. What implementation pattern can you use so that future enhancements of the system tests can be done easily and also code duplication is kept at a minimum level?

        I have found out from my own experience that using the Page Object model for implementing front-end system tests works very good. At its core, the Page Object Model (POM) suggests to have basically two files. The first one contains the definitions of web elements and the methods used to interact with these web elements, and the second file contains the test case definitions, which use the methods and web elements definitions (defined in the first file) to interact with the User Interface.

Page objects – These are the .js files where you map the elements and write the functions to perform actions
Test specs – These are the .js files where you write your tests using Jasmine syntax
Exports and Require – This is how you connect your Page Objects to your Test Specs

NodeJS exports and require example

       Your page object file (in this case login.pageObject.js)

       Your test file (in this case login.spec.js)

 

Run selective tests

       To run not all, but only a few selective tests, it is possible to adjust the respective *.spec.js file and to add the f prefix in front of a describe or it definition (in this case f stands for focus).

See the Jasmine documentation for more information.

Adjust browser window size

        It is possible that tests will fail due to a too small browser window. The size of the window can lead to buttons being hidden and not clickable. For this reason the conf.js (protractor configuration file) should either contain the configuration to maximize the browser window or a specific window size.

or

Run tests in parallel

       It is possible to runt tests in parallel by setting up the capabilities (or multiCapabilities) section in the conf.js file (protractor configuration file):

shardTestFiles: if set to true, specs will be sharded by file (all files to be run by this set of capabilities will run in parallel). Default is set to false.

MaxInstances: maximum number of browser instances that can run in parallel for this set of capabilities. Only needed if shardTestFiles is set to true. Default is set to 1.

 

 

3 Comments

  1. JavaScript is the foundation and critical learning block needed to be successful with Protractor testing, and what follows is your roadmap to learn JavaScript, NodeJS, and AngularJS for Protractor testing.

  2. JavaScript is the foundation and critical learning block needed to be successful with Protractor testing, and what follows is your roadmap to learn JavaScript, NodeJS, and AngularJS for Protractor testing.

Leave a Reply

Your email address will not be published.


*