量角器中的Element.getText() [英] Element.getText() in Protractor
问题描述
我想编写一个测试用例,在其中我将前一页中单击的元素的值与当前页面中元素值的值进行比较。
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我使用以下代码 -
I am using the following code -
validateText = SoftwaresUnmappedPage_POM.checkFirstSoftwareName.getText();
expect(validateText+"*").toBe(SoftwareSummary_POM.softwareName.getText());
例如 - 如果我点击一个按钮(ABC),它就会加载一个页面。此页面包含指示我单击的元素的元素。但它将名称显示为ABC *。所以我想验证我点击的元素和我登陆的页面是否相同。
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.
导致错误 - 预期'[object Object] '成为'ABC '。
Error being caused - Expected '[object Object]' to be 'ABC'.
有人可以帮我解决这个问题吗?谢谢。
Can someone please help me resolve this problem? Thanks.
推荐答案
这不起作用,因为量角器使用promisses。您首先需要解决承诺,以便能够执行您想要测试的内容。
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.
这将起作用
SoftwaresUnmappedPage_POM.checkFirstSoftwareName.getText()
// Get the resolved text from the promise
.then(function (validateText){
// Compare the result
expect(validateText+"*").toBe(SoftwareSummary_POM.softwareName.getText());
});
希望这有助于
这篇关于量角器中的Element.getText()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!