【发布时间】:2021-04-22 21:02:17
【问题描述】:
在量角器端到端测试中,我想使用 element(by.css(...)) 检查元素是否存在,我的代码:
var myElement = element(by.css('.elementClass'));
expect(myElement).toBeUndefined;
这个测试失败了,它说:
Expected { locator_ : { using : 'css selector', value : 'div[ng-switch-
when="resultNav"]' }, parentElementFinder_ : null, opt_actionResult_ :
undefined, opt_index_ : undefined, click : Function, sendKeys : Function,
getTagName : Function, getCssValue : Function, getAttribute : Function, getText
: Function, getSize : Function, getLocation : Function, isEnabled : Function,
isSelected : Function, submit : Function, clear : Function, isDisplayed :
Function, getOuterHtml : Function, getInnerHtml : Function, toWireValue :
Function } to be undefined.
之后我尝试使用承诺:
element(by.css('.elementClass')).then( functtion(data) {
expect(data.getText()).toBeUndefined();
});
这会导致错误:
错误:使用定位器 By.CssSelector(...) 找不到元素
是的,我知道找不到任何元素,但是如何使用 element(by.css(...)) 创建工作测试?
有谁知道如何做到这一点?还是element(by.css()) 不是这里使用的方法?
【问题讨论】:
标签: angularjs protractor e2e-testing