javascript - 当我在量角器的单个测试中使用具有不同浏览器实例的页面对象时,我收到两条不同的错误消息
问题描述
当我尝试使用用两个浏览器实例创建的页面对象时,我得到了两种不同语法的两个不同错误。
1.将浏览器实例添加到页面对象
页面对象文件
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)
2.不向页面对象添加浏览器实例
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
..如果有人遇到这种情况,请帮助我。
解决方案
推荐阅读
- python - 使用远程操作系统分隔符的路径连接
- wordpress-theming - 如何在 html5blank_nav() 的 ul 和 li 中添加类?
- sql - 带有破折号和下划线的 SQL Server 通配符语句 问题
- qt - 使用键盘快捷键切换可见性
- laravel - 以真实姓名下载数据库文件附件
- python - Python中具有复杂指数元素的矩阵
- json - 作为将 WCF 调用为 REST 服务的一部分,类型字典的属性之一没有被序列化
- kendo-grid - 自定义删除命令也不会在 MVC Kendo.Grid 中标记要删除的每一行
- webpack - 找不到模块:错误:无法解析“index.scss”
- c# - 为 Microsoft Azure 查找两个字符串