Wednesday, May 25, 2016

Protractor : How to implement suites in protractor

We write many scripts in order to automate functional or regression test cases using protractor but all are scattered and not in order. Sometimes we need to run a group of test cases dedicated to test a specific functionality. In that case we need to group protractor script named suite. Using suite we can make a set of scripts.

In this post we will use our sample projects that was built in our previous post.

Step 1 : Open the project and add two new folders named “addition” and “multiplication” by right clicking on project name and go to New->Directory.

image

image

Step 2 : Add a JavaScript file names “testadd1.js” at “addition” folder by right clicking on folder and go New->JavaScript File.

image

image

Now add another file named “testadd2.js”.

image

Step 3 : Now open testadd1.js and add the following script.

image

Open testadd2.js and add the following script.

image

Step 4 : In the same way, add two JS files “testmul1.js” and testmul2.js” on multiplication folder.

image 

Step 5 : Open “testmul1.js” file and add the following scripts.

image

And Open “testmul2.js” file and add the following scripts,

image

Step 6 : Now open conf.js file and add suites options like the following,

image

Here, addition and multiplication are suites name and we use these name during running scripts.

'addition/*.js' means run all .js files located in addition folder.

'multiplication/*.js' means run all .js files located in multiplication folder.

In this way we can run either any of the suites.

Step 7 : Now open terminal window and run selenium server.

[image71.png] 

Step 8 : Now open another terminal window and run all the script located in addition folder by using addition suite. The command will be

protractor conf.js --suite addition

image

Common format of this command,

protractor conf.js –suite {suite name}

Pressing enter key will run the script located in addition folder. Please do not merge folder name and suite name. These two are different.

You can run any suite by using the suite name.

Now run the multiplication suite.

image

We can create more suites by using different files from different folders like the following,

cal: ['addition/*.js','multiplication/*.js']

image

Here we use different script location separated by comma.

Now run the suite,

image

That’s all for now.

We will see more in future.

Happy end to end testing using Protractor!!!

No comments:

Post a Comment

Cypress: How to handle browser-based authentication pop up dialog in Cypress

Five years ago I have written a blog on how to handle browser-based authentication for selenium webdriver.   Now it is for cypress. Cypress...