Friday, January 27, 2017

Protractor Test Run Results - Jasmine2-html-reporter

One way to see protractor test run results, is to use an existing package, called jasmine2-html-reporter that will help you see a reporter in html format for Jasmine and Protractor. The big advantage of this is that it's able to generate a screenshot every time a test test fails.

In order to use it you need to npm install it and to add it in your protractor config.js file, in onprepare function

$ npm install protractor-jasmine2-html-reporter

var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');

exports.config = {
   // ...
   onPrepare: function() {
      jasmine.getEnv().addReporter(
        new Jasmine2HtmlReporter({
          savePath: './protractor/reports/logs/htmlReports',
          takeScreenshots: true,
          takeScreenshotsOnlyOnFailures: true
        })
      );
   }
}

There are other options that you can use, like FixedScreenshotName, CleanDestination, showPassed, etc.

The test results will show
- 'passed' for every 'expect' inside a spec ('it' statement)
if there is no 'expect' inside 'it', it will be marked with 'skipped'
- if an error occurs, it will show an error + a screenshot


Later, you can use test results files in a CI system, like Jenkins and attach the screenshots for failed tests as artifacts.

Happy testing and... make it green, becomes a dream :).

Wednesday, January 25, 2017

Protractor - Show test run time in your logs

In this short article we will see how can we show the test run duration in a log file, displayed in hours, minutes, seconds.

There are some moments when we can add data in a log file: 
- jasmine started, meaning that we will add info in a log file when we started to run tests
- suite startedinside a .spec file we can have different suites (describe); we can add logs for each describe
- spec started; inside a suite we can have multiple specifications (it); we can add logs for each it
- spec done
- suite done
- jasmine done

To add the elapsed time, we need to capture start time in jasmine started and end time in jasmine done.


Happy testing and... make it green, becomes a dream :).

Monday, January 9, 2017

Postman - Extracting login token and using it in requests

Introduction


Postman is a powerful GUI platform to make your API development faster & easier, from building API requests through testing, documentation and sharing. In this article we'll show you how to:

- take the token from your login post and use it later for authorization in later requests
- define environment variables and use them in requests
- test your API by testing response code, response time, response body content, etc.
As example, we are going to test this workflow: 
- login to https://www.pincello.com
- create a new timeline

* Pincello is a beta web application that allows you to make professional timelines quickly that is the Web  version of a PowerPoint addin (for more details visit https://www.officetimeline.com/).

Extract token data from login
Postman gives the possibility to extract values from the response and saving it inside an environment or a global variable. Environment and global variables let you keep track of everything that affects API state. Some examples of common variables you would use with an API are session tokens, user IDs, file IDs.
What are the steps for taking the token from login:

1. Launch Postman Chrome Extension
2. Create a new collection (from the top left part)


3. Name it, for example Pincello Testing


4. Open Manage Environments (from the top right part)


5. Add a new environment, e.g. Pincello and add a new key, e.g. token. Leave the value empty.


6. Set this environment (Pincello) to the current collection (Pincello Testing)


6. Post login data and extract via Test tab the access_token and then place it in the environment variable.
In this case we need to create a new request with
- url = {{url}}/token, where {{url}} is another environemnt variable that represents your url that you want to test
- type POST
- body, in this case of type x-www-form-urlencoded with some inputs, those values are stored also as environment variable


*every call to an environment variable is made by using environment key value with {{}}


- you then need to go to Test tab and place the result of post response in token environment variable. To do this, white this javascript code in your Test tab



7. Write tests for login request, e.g. response time, response status code = 200. To do this add tests to your Test tab from Code list


8. Every request after login, will require an authorization, thus, we should add Authorization header for the next requests like in the image below, by using the token previously extracted.


9. Continue with your API testing. Here are some examples:




10. Run the tests


11. Check your tests results



Happy testing and... make it green, becomes a dream :)

Thursday, January 5, 2017

Web Performance Testing with Visual Studio - Replacing Context Parameter Value with a Data Source Value

Introduction

Visual Studio Enterprise 2015 or Visual Studio Ultimate 2013, gives you the possibility to test the performance of your application. In this article we'll show you how to replace the value of a context parameter with a value from a data source. Why do we need this? Instead using a context parameter in each web test, we can take the value from a .csv, value that can be later changed, in case we want to run tests on a different environment (e.g. site value).



Adding Data Source

It seems that binding values to Form Post parameters it is possible, but for context parameters this is not. In this case, a solution would be to:
- add a data source for your .csv file
- replace all occurrences of the context parameter with the data source
- remove the context parameter

In the example above:
- add a new data source to you .csv file (right click on webtest name + Add Data Source...), in the example this will have the name FormInputs
- replace all occurrences of {{URL}} with {{FormInputs.FormValues#csv.Site}} (right click on webtest name + Find and Replace in Request...)
- delete context parameter {{URL}}

The result should be like in the image below:


Happy testing and... make it green, becomes a dream :)

Popular Posts