问题
I'm new to Protractor testing. Been at it for only a few hours.
I have an angular app, using bootstrap alerts.
How do I test:
- Alert (danger-alert) is not present on page load
- Alert (danger-alert) becomes present on button click
- Alert (success-alert) becomes present on another button click
Thanks!
回答1:
Alert (danger-alert) is not present on page load
You can use isPresent():
expect(element(by.css('.alert-danger')).isPresent()).toBe(false);
Or, if the element is there but invisible, check isDisplayed():
expect(element(by.css('.alert-danger')).isDisplayed()).toBe(false);
Alert (danger-alert) becomes present on button click
Click the button and check if alert is there by using isDisplayed()
:
element(by.id('myButton')).click()
expect(element(by.css('.alert-danger')).isDisplayed()).toBe(true);
Alert (success-alert) becomes present on another button click
Same as above:
element(by.id('myAnotherButton')).click()
expect(element(by.css('.alert-success')).isDisplayed()).toBe(true);
来源:https://stackoverflow.com/questions/27763095/protractor-testing-bootstrap-alerts