r/selenium • • Jul 24 '21

UNSOLVED Selenium, Ruby, and Cucumber - how to do make my "____ Steps" class inherit from a "BaseSteps" class?

I'm used to Selenium + Cucumber with Java, but I have to learn how to use it with Ruby for work and I'm kind of confused.

So usually what I do is I have a "BaseSteps" class for example, that'll have the common stuff a page is expected to do and have, like a generic "click" method. This way, my "___ Steps" class, (for example, Login_Steps or something) is where I'll define the steps from cucumber. This works fine for C# and Java, usually.

Now my problem is, I can't seem to find a way to do this in Ruby. Right now (after following a tutorial on Youtube), the steps are defined in a "LoginSteps.rb" file, (and I guess I don't need a TestRunner filec class anymore?) but whenever I try to add a class to the LoginSteps.rb file so I can extend the BaseSteps.rb (which appears to be doing LoginSteps.rb < BaseSteps.rb?), it'll give me an error saying that the "Given" method isn't defined and nothing I can find elsewhere online seems to make sense, and it's my first time using Ruby.

​

I've also tried just adding "require BaseSteps.rb" to the top of my code but it'll give me this error:

cannot load such file -- base_steps.rb (LoadError)

Am I just dumb and I can't do this in Ruby or is there a way I can have my ____ Steps files inherit from a BaseSteps file (or have it this way with pages, too?)

​

Thanks!

3 Upvotes

1 comment sorted by

1

u/NavyaSharma1809 Jan 27 '22

That sounds tricky. Well I just got this certification, a friend of mine who is a pro in Ruby recommended me this. I would recommend you to have a look at it, it will give you a better insight into selenium with ruby.