Element.getText() in Protractor [duplicate]

强颜欢笑 提交于 2019-12-23 05:07:57

问题


I want to write a test case in which I compare the value of an element clicked in previous page to that of an element's value in the current page.

I am using the following code -

validateText = SoftwaresUnmappedPage_POM.checkFirstSoftwareName.getText();

expect(validateText+"*").toBe(SoftwareSummary_POM.softwareName.getText());

For example - If I click on a button (ABC), then it loads a page. This page has elements indicating the element i clicked. But it displays the name as ABC*. So i want to verify if the element I clicked on and the page I am landing at is the same.

Error being caused - Expected '[object Object]' to be 'ABC'.

Can someone please help me resolve this problem? Thanks.


回答1:


This won't work because Protractor works with promisses. You will first need to resolve the promise to be able to do what you want to test.

This will work

SoftwaresUnmappedPage_POM.checkFirstSoftwareName.getText()
  // Get the resolved text from the promise
  .then(function (validateText){
    // Compare the result
    expect(validateText+"*").toBe(SoftwareSummary_POM.softwareName.getText());
  });

Hope this helps




回答2:


In addition to above answer, you can also do something like below,

 var validateText = SoftwaresUnmappedPage_POM.checkFirstSoftwareName.getText().then(function(validateText){
    return validateText+"*";
});
 expect(validateText).toBe(SoftwareSummary_POM.softwareName.getText());


来源:https://stackoverflow.com/questions/44195225/element-gettext-in-protractor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!