Protractor Cheat Sheet
Page Object Model
let homepage=function(){
let firstNumber=element(by.model('first'));
let secondNumber=element(by.model('second'));
let goButton=element(by.className('btn'));
this.enter_firstNumber=function(firstNo){
firstNumber.sendKeys(firstNo);
}
this.enter_secondNumber=function(secondNo){
secondNumber.sendKeys(secondNo);
}
this.clickgoButton=function(){
goButton.click();
}
this.verifyResult=function(result){
let text=element(by.className('ng-binding')).getText();
expect(text).toBe(result);
};
this.get=function(url){
browser.get(url);
};
};
module.exports=new homepage();// this line is required as we will be exporting this class and using in other classes
Sample Test case for Website using POM
let homepage = require('../pages/homepage');
describe('Test Sample App',function(){
it('Launch Test',function(){
homepage.get('https://juliemr.github.io/protractor-demo/');
homepage.enter_firstNumber('2');
homepage.enter_secondNumber('3');
homepage.clickgoButton();
homepage.verifyResult('5');
browser.sleep(5000);
});
});
Run the Test cases using below command
PS C:\Users\T460\Desktop\Projects\ProtractorSample> protractor .\conf\conf.js
Note: Make sure you pass specs name correct in conf.js i.e. name of your test case file
No comments:
Post a Comment