Wednesday, September 28, 2016

Protractor - Getting non-angular iframe inside an angular application

If you have an Angular App that loads another Non-Angular App inside an iframe, getting objects inside iframe may be difficult.



Here is the solution I used:

describe('Inside non-angular iframe', function () {
        it('you can access iframe objects.', function () {
             ...
            _form.goToIFrame();
            //work with iframe objects
            _form.goToDefault();
});


where _form.goToIFrame(); and _form.goToDefault(); means:

    goToIFrame: function () {
        browser.switchTo().frame(browser.driver.findElement(by.tagName('iframe')));
        browser.ignoreSynchronization = true;
    },

    goToDefault: function () {
        browser.driver.switchTo().defaultContent();
        browser.ignoreSynchronization = false;
        browser.waitForAngular();
    }


That's all.


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

No comments:

Post a Comment

Popular Posts