Reputation: 185
when i click a link in our angular page,it open's a new tab. In that I need to compare the heading and few texts. below are the my code snippets.
this.getSupportPageTitle = async function(){
browser.ignoreSynchronization = true;
await browser.getAllWindowHandles().then(async function(handles){
await browser.switchTo().window(handles[1]).then(async function(){
console.log('focus switched to new Tab');
var title = await actions.getElementText(element(supportPageDiscription),'check support page title');
console.log('title : ' +title);
return title;
});
});
};
and have a spec
it('Display Support Page',async function(){
browser.ignoreSynchronization = true;
var supportPageTitle = await manageSupportPage.getSupportPageTitle();
if (await manageSupportPage.getSupportPageTitle()){
console.log('true');
}
else{
console.log('false');
}
console.log('Title from page :' +supportPageTitle);
await expect(supportPageTitle).toEqual(expected_result.expectedSupportPageDiscription);
});
In page, i can print the title.But when it returns to spec it saying undefind. Any help can be appreciated. Thank you.
Upvotes: 0
Views: 83
Reputation: 13722
Because you missed return
for the function. And you can write your function body as Sync programming
as following with using async/await
:
this.getSupportPageTitle = async function(){
browser.ignoreSynchronization = true;
var handles = await browser.getAllWindowHandles();
await browser.switchTo().window(handles[1]);
console.log('focus switched to new Tab');
var title = await actions.getElementText(element(supportPageDiscription),'check support page title');
console.log('title : ' +title);
return title;
};
Upvotes: 1