我正在使用量角器(在非 - 矩形页面上)并且希望不会出现特定的警告消息。
所以我需要检查元素的存在,然后执行toMatch()检查...
警告我很快就会自己回答 - 但如果你是一名枪式量角器测试作家,你可以帮助我: - )
我需要将这两者结合起来:
// utility to test expection of an element to match a regex:
this.expectByCssToMatch = function(css, pattern) {
browser.driver.findElement(
by.css(css)).getText().then(function(text) {
expect(text).toMatch(pattern);
});
};
// utility to test expection an element is missing:
this.expectByCssToBeAbsent = function(css) {
browser.driver.isElementPresent(
by.css(css)).then(function(present) {
expect(present).toBeFalsy();
});
};
答案 0 :(得分:1)
// utility to test expection of an element to not match a regex:
this.expectByCssNotToMatch = function(css, pattern) {
browser.driver.isElementPresent(by.css(css)).
then(function(present) {
if (present) {
browser.driver.findElement(by.css(css)).getText().
then(function(text) {
expect(text).not.toMatch(pattern);
});
}
else { // element absent so we have no match (pass)
expect(present).toBeFalsy();
}
})
};