Angular 无法获取“";“文本”;";“元素”;使用;量角器“;

Angular 无法获取“";“文本”;";“元素”;使用;量角器“;,angular,jasmine,protractor,Angular,Jasmine,Protractor,嗨,我正在为“Angular 4”应用程序编写量角器自动化脚本 开发代码如下 <!--Byndd Title div--> <div class="ui-g-12 ui-md-8 ui-lg-10"> <div class="bynndTitleClass" i18n="@@introductionBynddHeader"> BynddYour Informati

嗨,我正在为“Angular 4”应用程序编写量角器自动化脚本

开发代码如下

<!--Byndd Title div-->
            <div class="ui-g-12 ui-md-8 ui-lg-10">
                <div class="bynndTitleClass"  i18n="@@introductionBynddHeader">
                    BynddYour Information Together And CONNECT to the world  in an EFFICIENT way
                </div>
            </div>   
规格代码:

 //Testcase1 : To open the "Login page" of the application 
    it('should open the Login page' , ()=>{
        //To open the Login page
        page.loginPageDisplay();

        // to verify whether the Current page is Login page or not by comparing with Login page Main heading
        expect(page.getLoginPageMainHeading().toString()).toBe('BynddYour Information Together And CONNECT to the world  in an EFFICIENT way');
    });
执行后,它将显示以下错误消息。 W

有人能帮我解决这个问题吗?

因为
expect()
本身就解决了一个承诺,所以您在pageObject中找到了
return element.getText()
的正确路径

但是,由于添加了
.toString()
,因此
expect
命令现在将元素放入字符串,而不是解析承诺

我建议只返回元素,并在
expect
语句中应用
getText()
。它更有意义,并使您的pageObject功能更好地用于其他测试

我的建议是:

PageObject(只返回不带
getText()
的元素):

和规范(
getText()
而不是
toString()
):

这解决了我的问题

page.getLoginPageMainHeading().getText().then(function(value){
            expect(value).toEqual('BynddYour Information Together And CONNECT to the world in an EFFICIENT way');
        })

@谢谢您的回复。我改变了我的规格和采购订单文件代码,但它仍然显示相同的错误。它是通过使用上面的代码来解决的,在评论中提到了这一点,当与jasmine expect一起使用时,您不必显式地解决承诺
expect(page.getLoginPageMainHeading().getText()).toEqual('bynddy将您的信息收集在一起并以高效的方式连接到世界上')
应该可以工作!
1) should test certificate tab should open the Login page
  - Expected '[object Object]' to be 'BynddYour Information Together And CONNECT to the world  in an EFFICIENT way'.
//to return login page heading 
getLoginPageMainHeading(){
          return element(by.css('div[class="bynndTitleClass"]'));
}
//Testcase1 : To open the "Login page" of the application 
it('should open the Login page' , ()=>{
    //To open the Login page
    page.loginPageDisplay();

    // to verify whether the Current page is Login page or not by comparing with Login page Main heading
    expect(page.getLoginPageMainHeading().getText()).toBe('BynddYour Information Together And CONNECT to the world  in an EFFICIENT way');
});
page.getLoginPageMainHeading().getText().then(function(value){
            expect(value).toEqual('BynddYour Information Together And CONNECT to the world in an EFFICIENT way');
        })