1
votes

Im looking for a good way to expect a certain text from an "alert" that fades out after 5 seconds.

This is for a basic login test (im pretty new to automation). I've been using cucumber/capybara and im using it with poltergeist for headless test (mainly for CI).

Im using chrome dev tools to try and find info about the element itself (the alert). It's not a popup alert, it's sort of a fade-in alert on the top of the screen. But all chrome returns is the class it belongs too (this is a rails web app) and the text contained within the alert.

Im not super familiar with rails, so is there some way to just search by the text? That seems to be the easiest way?

edit: Apparently they are rails alerts using :flash, they are just faded in and out using jquery.

1

1 Answers

1
votes

Assuming the element that is the "alert" has a class of 'alert', something like

expect(page).to have_selector('.alert', text: 'The text in the alert') 

should do what you want. You could also just do

expect(page).to have_text('The text in the alert')

which would be less targeted and just verify the text shows up on the page but not that it's actually in the 'alert'