2016-10-03 6 views
0

は、私は私のサイト(マイプロファイル)に要素のテキストが必要ですが、作業やジャスミン上のコードを実行されるコードイマイチは私にここにのgetText()

enter image description here

は次のエラーを与える作業ありえない私コード

describe("login to CA", function() { 
    it("returns successful", function() { 
    driver.get(url); 
    driver.findElement(By.xpath('//*[@id="input-username"]')).sendKeys(username); 
    driver.findElement(By.xpath('//*[@id="input-password"]')).sendKeys(pw); 
    driver.findElement(By.xpath('//*[@id="submit"]')).click(); 
    myProfile = driver.findElement(By.css('#bs-example-navbar-collapse-1 > ul > li:nth-child(5) > a')); 
    expect(myProfile.getText()).toEqual('My profile'); 
    }); 
}); 

どうすればよいですか?

答えて

3

問題は、getText()約束を返します。

Protractorを使用する場合は、この方法でアサーションすることができます(アーチファクトを行う前に暗黙のうちに約束を解決することができるように、ジャッジマインのパッチバージョンを使用します)。expect()

または、分度器を使用していない場合は、明示的に約束を解決する必要があります。

myProfile.getText().then(function (actualText) { 
    expect(actualText).toEqual('My profile'); 
});