I'm new to RSpec and Capybara and I am trying to test if page has a time on it. 12:00 or 14:24 or 08:12 are good examples of what I am trying to test for.
I am using the following regex:
/^\d{2}:\d{2}/
I am not sure how to "phrase it" in capybara to test if the page contains this regex.
Click Test Expression. Pega Platform generates a table that lists the results of each match of regular expressions found in the source text. Did you find this content helpful? Have a question?
Click ActionsRun. The system displays a test input form. On the test input form, in the Page list, click Empty test page. Leave the parameter values blank. Click Run. Enter a regular expression to use, using syntax conforming to the Java implementation of regular expressions ( Java.util.regex.Pattern ).
Use the Application Explorer to open the Code-Pega-Parse.RegExpTester standard activity. Click ActionsRun. The system displays a test input form. On the test input form, in the Page list, click Empty test page. Leave the parameter values blank. Click Run.
Enter a regular expression to use, using syntax conforming to the Java implementation of regular expressions ( Java.util.regex.Pattern ). Enter source text to use to search for matches to the regular expression.
I'd suppose something like
page.text.should match(/^\d{2}:\d{2}/)
or, with the new RSpec syntax
expect(page.text).to match(/^\d{2}:\d{2}/)
Or you can test not the whole page but some element, e.g.
find("span.time").text.should match(/^\d{2}:\d{2}/)
I don't know if this is new behavior, but you can just use has_content?
:
page.has_content?(/do not have permission/i)
In rspec, that would be something like this:
expect(page).to have_content(/do not have permission/i)
I found this in the online documentation for capybara, but it's under has_text?
since has_content?
is just an alias.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With