问题描述
按照怎样断言元素集中线程,你可以检查元素是否被转换到侧重 activeElement()
,并断言这就是你预期有焦点的相同元素:
在我的情况下,目前主要集中的元素没有一个 ID
属性即可。
我应该做的,而不是检查一个的id是什么
?
奖金的问题:此外,你可以看到从我试图解决它,它看起来像我不能指望/断言元素(或网页元素)作为一个完整的对象。为什么呢?
我试过:
预期(page.element).toEqual(browser.driver.switchTo()activeElement());
但与一个错误我甚至无法理解失败 - 有一个巨大的回溯(这是约10分钟在控制台滚动),但里面没有用户友好的错误
我也试过用 getWebElement()
:
预期(page.element.getWebElement())toEqual(browser.driver.switchTo()activeElement()。)。
但是,这将导致以下错误:
Using the latest protractor development version.
In my answer I'm going to assume activeElem
and pageElem
are both protractor element finders, and are pointing to the same web element.
First to answer your question about why
expect(activeElem).toEqual(pageElem);
Gets into an infinite loop, it's because protractor patched jasmine's expect
to resolve the promise before asserting, so that things like expect(activeElem.getText()).toEqual('text');
works without having to do
activeElem.getText().then(function(text) {
expect(text).toEqual('text');
})
You could say, why not just resolve the promise once? But then there are nested promises.
So now you might be thinking this is an issue, but it really isn't because you would never compare two elementFinders in a real use case. Jasmine's toEqual does a reference check, and not a deep compare, so expect(activeElem).toEqual(pageElem)
, is just the same as a simple reference comparison: (activeElem === pageElem).toToTruthy()
, and there's really no point doing that. (Note element(by.css('html')) === element(by.css('html'))
is false because it's not the same reference.)
So, to answer the real question for this thread: how to see if two elementFinders have the same underlying webelements:
expect(activeElem.getId()).toEqual(pageElem.getId());
这篇关于主张的元件被聚焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!