当我尝试使用由两个浏览器实例创建的页面对象时,对于两种不同的语法,我遇到了两个不同的错误。
var facebook=function(browserInstance){
browser=browserInstance ? browserInstance : browser;
element=browser.element;
this.email=function(){
return element(By.id("email"));
}
this.password=function(){
return element(By.id("pass"));
}
this.submit=function(){
return element(By.xpath("//input[@aria-label='Log In']"));
}
this.search=function(){
return element(By.name('q'));
}
}
module.exports=facebook;
var page1,page2,utilityInit;
module.exports=function(){
this.Given(/^Open the browser and Load the URL$/,async function(){
await browser.get("https://facebook.com");
browser.logger.info("Title of the window is :"+await browser.getTitle());
//screenshots.takesScreenshot("filename");
});
//this function is for first browser instance and facebook pageobject accepts the browser instance as a parameter and based on parameter it will shift the browser instance
this.When(/^User entered the text in the search box$/,async function(){
browser.sleep(3000);
page1=new facebook(browser);
await page1.email().sendKeys(testData.Login.CM[0].Username);
browser.sleep(3000);
await page1.password().sendKeys(testData.Login.CM[0].Password);
});
this.Then(/^User tried to open in new browser instance$/,async function(){
browser2=await newBrowser.openNewBrowser(browser);
utilityInit=new utility(browser2);
utilityInit.ignoreSync(browser2);
browser2.get("https://google.com");
page2=new facebook(browser2);
console.log(await browser2.getTitle()+" title");
browser2.sleep(5000);
});
this.When(/^User entered the text in the email field$/,async function(){
await browser2.page2.search().sendKeys("test");
browser2.sleep(3000);
})
}
TypeError: Cannot read property 'search' of undefined
at World.(anonymous) (H:\workspace\Framework\src\test\java\com\learnFramework\TestCases\spec.js:34:24)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
this.When(/^User entered the text in the email field$/,async function(){
await page2.search().sendKeys("test");
browser2.sleep(3000);
})
Error while waiting for Protractor to sync with the page: "both angularJS testability and angular testability are undefined. This could be either because this is a non-angular page or because your test involves client-side navigation, which can interfere with Protractor's bootstrapping. See http://git.io/v4gXM for details"
一次说Undefine
,一次说angular not found related error
..如果有人遇到这种情况,请在这方面帮助我。