Capbyara/Ruby/Regex

Hi,
Firstly, thanks for the add :slight_smile:

Secondly - I’m self-taught in Ruby/Selenium/Capybara/Regex so still trying to get my head around it all!

I’m hoping someone might be able to help me with my automated test.
I’m using Capybara/Cucumber and the website under test has a CMS, when a user adds a component in the CMS the component is assigned an auto-generated class (eg “StyledTabsSection-dk9iyv-4 gkLKye”) the format is the same, so I have a regex that splits the class into 3 groups - ^(Styled)(\w*)(-\S*\s\S*)$

What I’m not sure about is how I write the ruby/Capybara DSL to expect the class to contain the 2nd group in my regex

I’ve found a code snippet online that I think will be a good start:

  • m = “John 31”.match /\w+ (\d+)/
  • m[1]

I’m guessing I can do something like:

module = displayed_module.match “^(Styled)(\w*)(-\S*\s\S*)$”
module[2]

Then(“I can see the {displayed_module} module on the page”) do |displayed_module|
page.find_by_class(module[2]).tag_name
end

But how do I write expect page.class to contain(module[2])?

Thanks in advance

Have a nice day :smile:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs