protractor: testing bootstrap alerts

不问归期 提交于 2019-12-23 02:31:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!