2017-11-15 3 views
0

こんにちは私は「角度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> 

私の分度器のテストスクリプトは以下の通りです。

ページオブジェクトコード:

//to return login page heading 
    getLoginPageMainHeading(){ 
       return element(by.css('div[class="bynndTitleClass"]')).getText(); 
    } 

仕様コード:

//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'); 
    }); 

実行後、エラーメッセージの下に表示されています。

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'. 

W は、誰もがこの問題に

答えて

1

を解決するためにどのように私を助けることができるexpect()が約束自体を解決しているので、あなたはあなたのPageObject内return element.getText()への正しい道にしています。

.toString()を追加したため、expectコマンドは、約束を解決するのではなく、要素をStringに置きます。

私はこの要素を返却し、expect明細書にgetText()を適用することをお勧めします。それはより意味をなさないし、あなたのpageObject関数を他のテストでもうまく再利用できるようにします。

だからここに私の提案:

のPageObject(getText()せずに、単に要素を返す):

//to return login page heading 
getLoginPageMainHeading(){ 
      return element(by.css('div[class="bynndTitleClass"]')); 
} 

とスペック(getText()代わりのtoString()):

//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'); 
}); 
+0

@Emstツウィングリはあなたの返事に感謝します。 SpecとPoのファイルコードに変更しましたが、それでも同じエラーが表示されています。 コメントに記載されている上記のコードを使用して解決します。 – vasundhara

0

この解きます私の問題

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

jasmine expectを使用して明示的に約束を解決する必要はありません。 'expect(page.getLoginPageMainHeading()。getText())。toEqual( 'Bynddあなたの情報を一緒に、そして効率的に世界に結びつける')'うまくいくはずです! –

関連する問題