ADS

Sunday, December 22, 2013

Handling automation testing of Repeaters using Protractor

AngularJS is becoming popular day by day and thus are the demand of creating automation test suites for AngularJS applications. Protractor is a popular framework for testing AngularJS applications which runs on WebDriver and uses most of its classes.

Protractor uses Jasmine structure to create test suites.
That being the overview, In this post, I will cover the handling the automation test scenarios of the Repeaters of AngularJS.
Repeaters are just like tables in any normal applications.
In a repeater, there are following things which we might need to verify:
  • Fetching the text from a particular row
  • Click on an element in a row
  • Checking the check-box in a particular row
Now for any of the above cases, there will be a particular row in which you will need to perform some of the tasks and lets say you need to find the particular row using the text present in it, then you can handle mostly everything using the following code:

Repeater : 
  1. <ul class="phones">
  2. <li ng-repeat="phone in phones | filter:query">
  3. {{phone.name}}
  4. <p> Text </p>
  5. </li>
  6. </ul>

TableLocator : This will be the locator of the table which holds all the element in the repeater. So this will return an Array.
ElementLocator : This will be the locator of the element on which you want to perform the some action.
TextLocator : This will be the locator which will hold the text on basis of which you need to perform the task.
Text : This is the text which we need to find to perform some operations.

So based on that lets see the code
Not just repeaters, all the table like structure can be handled in this way.

TableLocator()
.then(function(ElementList){
ElementList.map(function(element, index){
element.findElement(TextLocator).getText().then(function(retrievedText){
if(text == retrievedText)
{
/* Perform actions on the element like clicking on element, checking the checkbox, etc. */
element.findElement(ElementLocator).click();
}
})
})
})

1 comment:

  1. Is data driven testing possible with protractor?

    I saw,we can use browser.params to read custom test data.

    To read from a JSON file simply add params to your config file

    exports.config = {
    params: require('./your-params-file.json'),
    };
    NodeJS will automatically convert the JSON file to a Javascript object that is easily accessible from any of your tests through browser.params.whateverYourJSONHas.

    I am looking for the data driven framework

    ReplyDelete