As you know Protractor is known as the best compatible automation framework for angular sites, since it awaits for angular to do his work and you don’t need to use waits methods. But what if you have an angular site that has some non angular pages ? How can you proceed ?
Protractor provides the means to test angularjs and non angularjs out of the box. The DSL is not the same for angular and non angular sites.
AngularJS:
element.find(By.model('details'))
The element keyword is exposed via the global, so you can use in any js file without need to require it. You can check on your runner.js that you are exporting all the necessary keywords.
// Export protractor to the global namespace to be used in tests.
global.protractor = protractor;
global.browser = browser;
global.$ = browser.$;
global.$$ = browser.$$;
global.element = browser.element;
NonAngularJS: You may access the wrapped webDriver instance directly by using browser.driver.
browser.driver.find(By.model('details'))
You can also create an alias for this browser.driver. This will allow you to use elem.find(by.css(‘.details’)) instead of using browser.driver. for example:
onPrepare: function(){
global.elem = browser.driver;
}
So, how can you use the same DSL for non-angular and angular pages ? You will need to ignore the sync, keep in mind that once you set this value, it will run for the entire suite. This will allow you to start using the same DSL.
onPrepare:function(){ global.isAngularSite = function(flag) { browser.ignoreSynchronization = !flag; }; }
You can add a Before for each angular/non angular scenario, you just need to tag each scenario indicating which one will run on an angular page, example:
this.Before({tags: ['~@angular'] }, function(features, callback) { isAngularSite(false); callback(); });
this.Before({tags: ['@angular'] }, function(features, callback) { isAngularSite(true); callback(); });
Hope this helps you guys !