首页 > 解决方案 > 当我在量角器的单个测试中使用具有不同浏览器实例的页面对象时,我收到两条不同的错误消息

问题描述

当我尝试使用用两个浏览器实例创建的页面对象时,我得到了两种不同语法的两个不同错误。

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..如果有人遇到这种情况,请帮助我。

标签: javascriptangularjsselenium-webdriverprotractor

解决方案


推荐阅读