How to switch between Angular page and Iframe in Protractor

1 comments
To switch to an Iframe in Protractor, there is a method to serve the purpose. Use switchTo().frame() method to switch focus to Iframe. To get back the focus from Iframe to Angular paga, use switchTo().defaultContent() method.

Below is the sample code to explain this case. Assuming there is an Iframe and need to click an element in Iframe. Once the element is clicked, Iframe disappears automatically, then swith the focus to Angular page.

browser.driver.switchTo().frame('Frame');
browser.driver.findElement(By.className("insert-btn")).click();
browser.switchTo().defaultContent().then(function() {
   var elm=element.all(by.repeater('data in Data.items')).filter(function(elem, index) {
       return elem.getText().then(function(text) {
           return (text.indexOf("HTML")>-1);
});
}).then(function(filteredElements){
    filteredElements[0].click();
      });
});


How to select an item in a list in Protractor

0 comments
When we need to select an element in the list of element, we need to filter them out with the required criteria like visible text and then perform the action (click).

We use filter method to get the array of required elements and then perform the action on the array of elements in a callback function.

See the following sample code to understand better.

var editTemplateByName = function(templateName) {
    element.all(by.repeater('template in templates')).filter(function(elem, index) {
        return elem.getText().then(function(text) {
            return (text.indexOf(templateName)>-1);
        });
    }).then(function(filteredElements){
       element(by.buttonText('or Edit')).click();
    });
};

call the method: editTemplateByName('HTML');

Capybara brief introduction

0 comments
First of all, its open source ruby language based framework which uses selenium web-driver internally to interact with web application controls.
It's designed specifically for testing a web application through the UI, so it has useful methods for asserting that the page is correct.
It has the built-in mechanism for handling synchronization issues that we run into while testing web applications.

It has a very good API support to interact with the application controls. I see there is a discussion forum to discuss the issues/solutions.

We can integrate BDD frameworks like Cucumber and RSpec with Capybary for better acceptance test results.

Links:
API Support
Discussion Forum
Sample Code

Default Test Frameworks in Protractor v3

0 comments
By default, Protractor v3 supports Jasmine and Mocha test frameworks. Cucumber is no longer included by default as of version 3.0. However, you can integrate Cucumber with Protractor with the custom framework option. For more details, see the Protractor Cucumber Framework site or the Cucumber GitHub site.

Jasmine:

Protractor v3 default test framework is Jasmine 2.x. If you want to upgrade to Jasmine 2.x from 1.3, follow the Jasmine upgrade guide.


Mocha:

If you would like to use Mocha as test framework, you need to use BDD interface and Chai assertion libraries with Chai As Promised.

Note: Limited support for Mocha is available as of December 2013. For more information, see the Mocha documentation site.