当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Protractor unable to compare variable to web element due to promise

问题描述:

My plan for this test was to store the inner text of an element, make a change then check the element against the variable and confirm that it had changed

var fixedValue= element(by.xpath('/html/body/section/div/section/section[2]/div[1]/ul/li[4]/a/span[2]')).getText();

var totalValue = element(by.xpath('/html/body/section/div/section/section[2]/div[1]/ul/li[1]/a/span[2]')).getText();

var progressValue = element(by.xpath('/html/body/section/div/section/section[2]/div[1]/ul/li[3]/a/span[2]')).getText();

make a change then expect

expect(element(by.xpath('/html/body/section/div/section/section[2]/div[1]/ul/li[3]/a/span[2]')).getText()).toEqual(progressValue);

However in my console I get the failed assertion

Expected '17' to equal NaN

It seems like this is because the promise of the first variable hasn't been fulfilled so there is nothing to compare too.

So my question is how can I get the expect to check the first variable.

网友答案:

One of the ideas behind protractor is to make things like this easier. For example, you could find the text using by.binding() or by.model(). These do the work of waiting for promises/server request/etc. to be completed.

Take a look at this tutorial page, in particular what they describe in step 1.

If you've tried this and it didn't work, or it doesn't quite address your situation, you might want to edit your question and provide more details. In general, try to avoid writing tests as you've shown above, they tend to be brittle (test breaks when you refactor your view). I've found using page objects to be very helpful.

分享给朋友:
您可能感兴趣的文章:
随机阅读: