1

How to include World concept of cucumber in site-prism? So that I can include test_site class in World and then no need to instantiate test_site class every time in step functions. Is it possible?

I'm using Ruby with Capybara and site-prism; not rails!!!

My test_site class is:

class TestSite
  def home
    TestHomePage.new
  end
end

Can't I do like this?

module Some
  class TestSite
    def home
      TestHomePage.new
    end
  end
end

World(Some)
Nat Ritmeyer
  • 5,634
  • 8
  • 45
  • 58
Srikanth
  • 265
  • 2
  • 8

3 Answers3

1

The SitePrism readme has a suggestion on how to deal with this, see here:

Nat Ritmeyer
  • 5,634
  • 8
  • 45
  • 58
1

I found an answer to my question.

As Nat suggested, I followed SitePrism readme here:

[http://rdoc.info/gems/site_prism/file/README.md#Epilogue][1]

I changed App class to Module and used World(App) in support file, so that whenever I need to use an element in step definition, I can just give page_name.element_name.click instead of @app.page_name.element_name.click

I changed the below class into Module and included the Module in World as World(App)

class App def home Home.new end end

Modified as

Module App def home Home.new end end

Is there anything wrong if I do change the class into Module?? For me everything seems fine, want to have a confirmation, before I proceed.

Srikanth
  • 265
  • 2
  • 8
0

You can create a module to return all pages that you want. In the support folder create a object_factory.rb in this file you can add:

Module Pages
   def my_page
     MyPage.new 
   end
end

in the file env.rb you can insert:

require_relative 'object_factory'

and

World(Pages)

The objects created in the module Pages will be available to your all step definitions