Get the element availability status in boolean using protractor
I am trying to get the element present status of the using 'If' condition but unfortunately i am not able to get the result as either 'true' or 'false' instead i am getting like(when element is available i am getting result as 'true' and when the element is not available i am getting error message like below)
Below is the code i used
describe("test 1", function () {
it("testing", function () {
var userCreationSuccessConfirmationMsg = element(by.className('alert-message ng-binding alert alert-success'));
var userCreationFailureConfirmationMsg = element(by.className('alert-message ng-binding alert alert-danger'));
browser.driver.get(testData.UBETURL);
login.loginToUbet('sysadmin', 'password');
console.log('Somesh');
element(by.linkText('Configuration')).click();
element(by.linkText('Create New User')).click();
element.all(by.id('saveUser')).first().click();
console.log(expect(userCreationSuccessConfirmationMsg.isDisplayed()));
userCreationSuccessConfirmationMsg.isDisplayed().then(function (status) {
if (status) {
console.log(status);
} else {
console.lgo(status);
}
});
});
});
How to get the element availability status in Boolean using if, please guide me here???
You can use isPresent
to determine whether an element is present or not in the page:
userCreationSuccessConfirmationMsg.isPresent().then(function (status) {
if (status) {
console.log('present');
} else {
console.log('not present');
}
});
The doc:
http://www.protractortest.org/#/api?view=ElementFinder.prototype.isPresent
如果你知道成功的时候(并且只有当)返回的状态是'真',那么你可以检查确切的文本是字符串:
userCreationSuccessConfirmationMsg.isDisplayed().then(function (status) {
if (status === 'true') {
...
}
});
Try this, i believe you don't actually need logging when all passing smoothly:
expect(userCreationSuccessConfirmationMsg.isDisplayed()).toBeTruthy('Your message that should be printed when expectation is failed.')
Jasmine can accept optional message for expectations, almost all matchers support it.
Also you can look at my library - it does matching that element visible in smart way - will wait for element, before fail expectation. Useful when your elements appear with delays. Feature requests are welcome.
https://github.com/Xotabu4/jasmine-protractor-matchers
链接地址: http://www.djcxy.com/p/13024.html上一篇: Javascript错误:设置音频对象控件属性True = = False
下一篇: 使用量角器以布尔值获取元素可用性状态