I am completely new to protractor, and I came across the async/await.
Using:
- node version 8.9.4
- protractor version 5.3.0. Is it necessary to use async/await in all your script? And how to use with page object.
Here's the code I tried
test1.js
describe("first protractor test",function(){
var originalTimeout;
async beforeEach(function(){
await browser.waitForAngularEnabled(false); //false to remove error for angular page not found
await browser.get("https://54.75.182.9/ems",5000); //34.22.196.20 another url
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
});
afterEach(function(){
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});
var home_page=require('./home_page.js');
it("first test- login test",function(){
home_page.enterUser();
home_page.enterPwd();
var transact=home_page.clickLoginfunction(); // that ref is used here
transact.clickReport();
transact.clickTransact();
transact.selectOption();
transact.clickSearch();
transact.clickViewDetails();
transact.getNGtext();
});
});
transact.js
var transact_page= function(){
//browser.pause();
this.clickReport=function(){
await element(by.xpath("//a[contains(.,'Reports')]")).click();
};
this.clickTransact=function(){
await element(by.xpath("//a[contains(.,'Transaction History')]")).click();
};
this.selectOption=function(){
await element(by.model("searchTypeEntity")).$('[value="Contact"]').click();
};
this.clickSearch=function(){
await element(by.id("searchTransBtn")).click();
};
this.clickViewDetails=function(){
await element(by.xpath("//a[contains(.,'View Details')]")).click();
};
this.getNGtext=function(){
return await element(by.model("val")).getText();
};
};
module.exports=new transact_page();
**homepage.js**
require('./transact.js'); // mentioning beforehand
var home_page=function(){
this.enterUser=function(){
await element(by.id("username")).sendKeys("admin");
};
this.enterPwd=function(){
await element(by.id("password")).sendKeys("admin");
};
this.clickLoginfunction=function(){
await element(by.id("login")).click();
await browser.driver.sleep(10000);
return require('./transact.js'); // this will return a ref to that particular page
};
};
module.exports=new home_page // need this so that its object can be used in other classes eg. main