我有一个成功的测试
browser
.url(testURL)
.waitForElementPresent('body', 1000)
.verify.attributeContains('someElement', 'someAttribute', 'foo')
但出于我的目的," someattribute"包含" foo"或" bar"是可以接受的。我想知道我如何编写这种测试,以免通过夜间观看测试失败。
您可以在两个步骤中测试属性是否包含'foo'或'bar':
- 使用
getAttribute()
或attribute()
获取属性值 - 匹配正则值与值
使用getAttribute()
,使用regex.test()
:
browser.getAttribute('someElement', 'someAttribute', function(result) {
this.assert.value(/foo|bar/.test(result.value), true);
};
使用attribute()
,使用matches()
断言:
browser.expect.element('someElement').to.have.attribute('someAttribute')
.which.matches(/foo|bar/);
使用.elements()并获得元素结果的长度以避免失败消息。
.elements('css selector','someElement[yourattribute="foo"]',function(result){
if(result.value.length>0){ //element exists
console.log('somelement is here')
}
else{
console.log('not here')
}
});