1

I'm a newbie on ruby language... Currently, I am using POM (page objects model) with Selenium webdriver.

This is my trouble:

  • As I'm using selenium with POM, I have 3 classes (register.br, login.br and log_out.br) and in my main class I'm calling the objects and methods for executing the Test (test.br)

  • How each class has @driver=Selenium::WebDriver.for :firefox the problem is when I execute my main class (test.br), every class called with this ' @driver` open a new browser...

My question is: How can I do for instantiating each class my selenium webdriver, realizing all the process just in one browser (the process is register, login and logout).

Currently, the process is completed but in three firefox browsers and I need just all the process in the same browser.

PD: I used $driver=Selenium::WebDriver.for :firefox with the $ in the test.br class and called in every class with the require relative but doesn't work

1
  • It's hard to know exactly what you're doing without seeing more of the code, but you shouldn't be creating a new driver in your page objects. That should be handled as part of your test logic, and then the driver is passed to or accessible to your page objects. While there is an argument for keeping selenium dependencies out of the test scripts, if that's your concern the solution would not be to create a new driver in all of your page objects. – mrfreester Sep 18 '17 at 16:24
0

It's hard to understand without a code to see what's wrong.

You can create your browser object outside of each class file, like in your test.rb file.

Then you can have an initialize on each page class where you pass browser object

class LoginPage
  def initialize(browser)
    @browser = browser
  end
end

class LogOut
  def initialize(browser)
    @browser = browser
  end
end

So your test.rb file would look like this:

browser = Selenium::WebDriver.for :firefox
page = LoginPage.new(browser)
page.user= "some@email.com"
page.login
page = LogOut.new(browser)
page.logout

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.