Tuesday, May 31, 2016

Protractor : How to implement XMLreports in protractor

In the post on how to automate web application using protractor we see that we ran the application and it just print test result at terminal window.

Here we see how we can implement Jasmine reporters. We will use xml reports.

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

Step 1 : Open the project.

Step 2 :  Open Terminal window and install jasmine-reporters package using the following command.

npm install jasmine-reporters

 image

It installs two packages jasmine-reporters@2.1.1 and  mkdirp@0.3.5.

image

Step 3 : Now open config.js file and write the following script in onPrepare() function,

image

Here,

jasmine.getEnv().addReporter(): It create report after executing the script.

JUnitXmlReporter() : It generate XML report.

consolidateAll : Aggregate all the results. 

savePath: Report folder where report is generated. Use can define his own path.
filePrefix: Generated file name.

Step 4 : Now config.js file will look like the following,

image

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

 image

Step 6 : Open another terminal window and run the script.

image

Step 7 : Note that script executes and report file is created at ‘testreport’ folder.

image

Now double click  to open the XML report and see the result. You can also open it through a browser.

image

That’s all for now.

In the next post we will see how we can generate HTML report.

Happy end to end testing using Protractor!!!

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!!!

Sunday, May 1, 2016

Protractor : How to maximize browser window using protractor

In our post on How to automate AngularJS application using protractor we see that browser window is not maximized.

Sometimes we need to maximize our browser window at the time of automation. Protractor has given us a nice command to execute such instruction.

In protractor we write script in our conf.js file using onPrepare  function. 

The script will be,

browser.manage().window().maximize();

In our example we use our project that we develop for one of our previous post.

Step 1 : Open the project and open conf.js file and write the above code in onPrepare function like the following.

image

Note that onPrepare is a function that fires at the time of executing script. So when browser window opens and it first maximize its browser window and then start navigate to the url.

Step 2 : Now conf.js file look like the following.

image

Step 3 : Run selenium server and then run the script using the following command.

image

image

Note that when browser window opens it first shows a relatively smaller window and then it become maximize to show full screen.

That’s all for now. More new things are coming.

Wish you a happy e2e testing!!!