Multiple Stepdefinations with page objects

88 views
Skip to first unread message

Rajeshwari Sudhakar

unread,
Feb 13, 2015, 10:43:31 AM2/13/15
to cu...@googlegroups.com
Hi all,

Would like to know how to implement multiple stepdefinations java file  with page objects . I dont understand where should i define the page objects for multiple step definations and how will cucumber find out which step defination file to use under these circumstances.
Kindly help. 

Thank you,
  1. Rajee

George Dinwiddie

unread,
Feb 13, 2015, 11:54:25 AM2/13/15
to cu...@googlegroups.com
Rajee,

Step definitions are global. They are all available all the time.

I would suggest putting the appropriate page object into scope when
navigating to the page. E.g.,

Given /^(.*) visits the "(.*)" page$/ do |user, pagename|
@user_name = user
@current_page = create_page_object_for_name(pagename)
end

Then other step definitions can use @current_page for interactions. If
multiple pages need to support interactions using the same step
definition, then those pages should support the same methods needed for
those interactions. E.g.,

When /^(.*) enters their address$/ do |user|
@current_page.enter_address(lookup_address_for_user(user)
end

where multiple page objects would implement the enter_address() method.

- George
> 1. Rajee

--
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------

Selenium Framework

unread,
Feb 16, 2015, 8:12:19 PM2/16/15
to cu...@googlegroups.com

rajee sudh

unread,
Feb 17, 2015, 5:43:07 AM2/17/15
to cu...@googlegroups.com
Thanks Geaorge, can that be done in java too i.e cucumber jvm ?? if so how??

Thank you Selenium Framework , helped me sort out few of my complications ...


--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

George Dinwiddie

unread,
Feb 17, 2015, 10:07:00 PM2/17/15
to cu...@googlegroups.com
Rajee,

On 2/17/15 5:43 AM, rajee sudh wrote:
> Thanks Geaorge, can that be done in java too i.e cucumber jvm ?? if so how??

Sure. Have the relevant page objects implement an interface, e.g.,
AddressForm, that contains the methods for entering the address.

@When("^(.*) enters their address$")
public void EntersTheirAddress(String user) {
(AddressForm)currentPage.
enterAddress(TestData.lookupAddressForUser(user);
}

- George

>
> Thank you Selenium Framework , helped me sort out few of my
> complications ...
>
>
> On Tue, Feb 17, 2015 at 1:12 AM, Selenium Framework
> <seleniu...@gmail.com <mailto:seleniu...@gmail.com>> wrote:
>
> An example repo for you -
> https://github.com/machzqcq/cucumber-jvm-template
> Explanation -
> http://www.seleniumframework.com/cucumber-jvm-3/cucumber-jvm-and-page-object/
>
> The project repo uses selenium for GUI testing
>
> cheers,
> www.seleniumframework.com <http://www.seleniumframework.com>
>
>
> On Friday, February 13, 2015 at 10:24:25 PM UTC+5:30, George
> Dinwiddie wrote:
>
> Rajee,
>
> Step definitions are global. They are all available all the time.
>
> I would suggest putting the appropriate page object into scope when
> navigating to the page. E.g.,
>
> Given /^(.*) visits the "(.*)" page$/ do |user, pagename|
> @user_name = user
> @current_page = create_page_object_for_name(__pagename)
> end
>
> Then other step definitions can use @current_page for
> interactions. If
> multiple pages need to support interactions using the same step
> definition, then those pages should support the same methods
> needed for
> those interactions. E.g.,
>
> When /^(.*) enters their address$/ do |user|
> @current_page.enter_address(__lookup_address_for_user(user)
> end
>
> where multiple page objects would implement the enter_address()
> method.
>
> - George
>
> On 2/13/15 10:43 AM, Rajeshwari Sudhakar wrote:
> > Hi all,
> >
> > Would like to know how to implement multiple stepdefinations
> java file
> > with page objects . I dont understand where should i define
> the page
> > objects for multiple step definations and how will cucumber
> find out
> > which step defination file to use under these circumstances.
> > Kindly help.
> >
> > Thank you,
> >
> > 1. Rajee
>
> --
>
> ------------------------------__------------------------------__----------
>
> * George Dinwiddie * http://blog.gdinwiddie.com
> Software Development http://www.idiacomputing.com
> Consultant and Coach http://www.agilemaryland.org
>
> ------------------------------__------------------------------__----------
>
>
> --
> Posting rules: http://cukes.info/posting-rules.html
> ---
> You received this message because you are subscribed to the Google
> Groups "Cukes" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to cukes+un...@googlegroups.com
> <mailto:cukes+un...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> Posting rules: http://cukes.info/posting-rules.html
> ---
> You received this message because you are subscribed to the Google
> Groups "Cukes" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to cukes+un...@googlegroups.com
> <mailto:cukes+un...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages