Handling module namespace using @current_page
pgundlupetvenkatesh opened this issue · 6 comments
I have been using page-object for a while now, recently our automation team had to restructure the framework to qualify each page object model class within module which made @current_page stop working for calling objects. Does PageObject support @current_page on classes qualified with module?
# Ruby class file
module MyModule
class MyClass
include PageObject
include PageFactory
text_field(:first_name, id: ‘firstName’)
button(:click_save_button, id: ‘save_button’)
end
end
# Cucumber step file
When /^I save record$/ do
on(MyModule::MyCLass).first_name = ‘Pratik’
@current_page.click_save_button # This doesn’t work
end
One alternative I found was to have all actions of the page in a block. But, using @current_page was way better to use.
When /^I save record$/ do
on MyModule::MyClass do |page|
page.first_name = 'Pratik'
page.click_save_button # This worked
end
end
:/
This does not work ?!
module Pages
module UCP
class Base
.
.
.
#in the step
visit Pages::UCP::Base
@vveliev visit()
and on()
works just fine, the problem is when I use @current_page
after on()
where class is qualified with module namespace.
This works.
class MyCLass1
include PageObject
include PageFactory
text_field(:first_name, id: 'firstName')
button(:save, id: 'saveButton')
end
module MyModule
class MyCLass2
include PageObject
include PageFactory
text_field(:last_name, id: 'LastName')
text_field(:age, id: 'Age')
end
end
# Cucumber step file
When /^I enter details and save the record$/ do
on(MyCLass1).first_name = ‘Pratik’
@current_page.save # This works just fine
on(MyModule::MyCLass2).last_name = 'G V'
@current_page.age = '20' # This doesn't work. Here @current_page has MyClass1 instance
end
Here is the behavior on how @current_page works
https://github.com/cheezy/page-object/wiki/Creating-and-using-page-objects#pagefactory
I'm using cucumber and it's working just fine for me, never had any issues.
Will need more info.
Thanks @vveliev and @thamilton2014
I did a sample test on a setup and it's working now. I have to test it on the production code which would take a week or two to kick off. Please do not close this issue, I will get back.
@pgundlupetvenkatesh I'm going to close this issue since you have it working. Please reopen if you find that this is happening in your production code.