Roy de Kleijn | 4 Aug 2012 10:53

use steps from multiple step definition class for a single story

I like to organize my steps in multiple class files. (because we have many steps in our application)

Question is: how can we use the steps from multiple step definition classes to execute a single story.

I use webdriver, I tried the following:

BaseClass.java
Instantiates the driver and opens the browser.

LoginSteps.java inherit from BaseClass.java
steps to login in application

SearchSteps.java inherit from BaseClass.java
Verify is elements is present.
BUT here is my driver instance suddenly null.

I think it has something to do with the way I execute my tests:
<at> Override
public InjectableStepsFactory stepsFactory() { return new InstanceStepsFactory(configuration(), new LoginSteps(), new searchPageSteps()); }

Please tell what other information you need or what I have to do differently.
Thanks

 

Mauro Talevi | 4 Aug 2012 14:24

Re: use steps from multiple step definition class for a single story

Hi Roy,

this information is not sufficient for us to help you.

As already noted in https://jira.codehaus.org/browse/JBEHAVE-810 there is a working tutorial available at

http://jbehave.org/tutorials.html

and an archetype that you can use

http://jbehave.org/reference/web/stable/archetypes.html

Note that JBehave Web provides the WebDriverProvider interface to instantiate the WebDriver and is typically per scenario, story or stories, e.g.

org.jbehave.web.selenium.PerStoryWebDriverSteps

On 04/08/2012 10:53, Roy de Kleijn wrote:

I like to organize my steps in multiple class files. (because we have many steps in our application)

Question is: how can we use the steps from multiple step definition classes to execute a single story.

I use webdriver, I tried the following:

BaseClass.java
Instantiates the driver and opens the browser.

LoginSteps.java inherit from BaseClass.java
steps to login in application

SearchSteps.java inherit from BaseClass.java
Verify is elements is present.
BUT here is my driver instance suddenly null.

I think it has something to do with the way I execute my tests:
<at> Override
public InjectableStepsFactory stepsFactory() { return new InstanceStepsFactory(configuration(), new LoginSteps(), new searchPageSteps()); }

Please tell what other information you need or what I have to do differently.
Thanks

 


Mauro Talevi | 4 Aug 2012 14:57

Re: use steps from multiple step definition class for a single story

To answer your question more specifically:  there is no problem in using as many steps classes you want for a single story, as a matter of fact is a recommended practice to not have a single class or a class hierarchy.

In your case, it should suffice to add the PerStoryWebDriverSteps to your steps factory to have the WebDriver initialised before each story.

Then you define your other steps independently - i.e. no need to inherit from it.

On 04/08/2012 14:24, Mauro Talevi wrote:

Hi Roy,

this information is not sufficient for us to help you.

As already noted in https://jira.codehaus.org/browse/JBEHAVE-810 there is a working tutorial available at

http://jbehave.org/tutorials.html

and an archetype that you can use

http://jbehave.org/reference/web/stable/archetypes.html

Note that JBehave Web provides the WebDriverProvider interface to instantiate the WebDriver and is typically per scenario, story or stories, e.g.

org.jbehave.web.selenium.PerStoryWebDriverSteps

On 04/08/2012 10:53, Roy de Kleijn wrote:

I like to organize my steps in multiple class files. (because we have many steps in our application)

Question is: how can we use the steps from multiple step definition classes to execute a single story.

I use webdriver, I tried the following:

BaseClass.java
Instantiates the driver and opens the browser.

LoginSteps.java inherit from BaseClass.java
steps to login in application

SearchSteps.java inherit from BaseClass.java
Verify is elements is present.
BUT here is my driver instance suddenly null.

I think it has something to do with the way I execute my tests:
<at> Override
public InjectableStepsFactory stepsFactory() { return new InstanceStepsFactory(configuration(), new LoginSteps(), new searchPageSteps()); }

Please tell what other information you need or what I have to do differently.
Thanks

 



Roy de Kleijn | 4 Aug 2012 15:55

RE: use steps from multiple step definition class for a single story

Ok, but I need the webdriver instance in all stepDefinition classes, that’s why I inherit a baseclass.

 

Can you point me to the correct example where multiple stepsclasses are used for the same scenario. (And where they share the same instance of an object.)

 

 

Thanks

 

 

Mauro Talevi | 4 Aug 2012 16:01

Re: use steps from multiple step definition class for a single story

What you share is the WebDriverProvider instance, not the WebDriver.

And an example that shows multiple steps classes being used can be found in the Etsy tutorial.

https://github.com/jbehave/jbehave-tutorial/tree/master/etsy-selenium/java-spring

On 04/08/2012 15:55, Roy de Kleijn wrote:

Ok, but I need the webdriver instance in all stepDefinition classes, that’s why I inherit a baseclass.

 

Can you point me to the correct example where multiple stepsclasses are used for the same scenario. (And where they share the same instance of an object.)

 

 

Thanks

 

 


Roy de Kleijn | 4 Aug 2012 16:04

RE: use steps from multiple step definition class for a single story

I see what you mean! I will try to run this example.

 

Thanks for the quick response,

 

Roy de Kleijn | 4 Aug 2012 16:15

RE: use steps from multiple step definition class for a single story

How to execute the tests ?

 

I did: ‘clean install -Pweb-runner,stable’ on /etsy/pom.xml

 

 

Did I made a mistake?

Mauro Talevi | 4 Aug 2012 16:20

Re: use steps from multiple step definition class for a single story

How to execute the tests ?

 

I did: ‘clean install -Pweb-runner,stable’ on /etsy/pom.xml

 

 

Did I made a mistake?


Alexander Lehmann | 6 Aug 2012 19:25
Picon

Re: use steps from multiple step definition class for a single story

The suggested way to implement web testing steps in to abstract from the 
actual web implementation and use steps classes and another set of 
classes called page classes, the examples on the reference guide 
describe how to do that 
http://jbehave.org/reference/web/stable/page-objects.html (WebDriver API)

The actual work is done inside the page classes that all inherit from a 
class called WebDriverPage, which provides the usual WebDriver methods 
like get from Selenium.

If you are constructing the objects yourself, you have to pass a 
WebDriverProvider between the classes, if you are using dependency 
injection (guice, spring), this will happen automatically. The whole 
thing has to be run in a single thread executor unless you use a per 
story web driver.

You can use steps classes (plain classes not inheriting from anything) 
using different page classes (inheriting from the WebDriverPage class), 
so you can organize your classes (plus if you have different step 
classes using the same page classes you can refactor step implementations)

On 04.08.2012 10:53, Roy de Kleijn wrote:
> I like to organize my steps in multiple class files. (because we have
> many steps in our application)
>
> Question is: how can we use the steps from multiple step definition
> classes to execute a single story.
>
> I use webdriver, I tried the following:
>
> BaseClass.java
> Instantiates the driver and opens the browser.
>
> LoginSteps.java inherit from BaseClass.java
> steps to login in application
>
> SearchSteps.java inherit from BaseClass.java
> Verify is elements is present.
> BUT here is my driver instance suddenly null.
>
> I think it has something to do with the way I execute my tests:
>  <at> Override
> public InjectableStepsFactory stepsFactory() { return new
> InstanceStepsFactory(configuration(), new LoginSteps(), new
> searchPageSteps()); }
>
> Please tell what other information you need or what I have to do
> differently.
> Thanks
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Jorge Pombar | 6 Aug 2012 21:02
Favicon

RE: Re: use steps from multiple step definition class for a single story

I don't have much to add since everyone already did a great job answering. I'll share our solution which is
based on the jbehave-spring-archetype available.

We have a PageObject package (all of our PageObjects representing pages on our application go here). Here
we also have a BasePage which extends org.jbehave.web.selenium.WebDriverPage (this page contains
WebDriverProvider). All of our pagesObjects extend BasePage. This way none of our pages handle the
WebDriverProvider, they all just have a call to the super ctor passing the WebDriverProvider and we get
all of those WebDriver methods findElement, etc.

In this package we also have a PageFactory class which provided the entry point where we pass the
WebDriverProvider we initialize on our spring beans.xml file.

We then have a Steps package which contains all of our steps logically combined in classes (for example
LoginSteps.java). Here we also have a BaseSteps which contain some common steps and all steps extend this
class. The constructor of this class uses PageFactory to return an instance of the relevant page object.
For example, SignIn page

Finally we initialize all of the step classes at the beginning of our run since they are defined in out spring
beans.xml file

Again, we just expanded on the jbehave-spring-archetype, so that's a great starting point

Thanks,
Enrique

-----Original Message-----
From: Alexander Lehmann [mailto:alexlehm@...] 
Sent: Monday, August 06, 2012 10:25 AM
To: user@...
Subject: [jbehave-user] Re: use steps from multiple step definition class for a single story

The suggested way to implement web testing steps in to abstract from the 
actual web implementation and use steps classes and another set of 
classes called page classes, the examples on the reference guide 
describe how to do that 
http://jbehave.org/reference/web/stable/page-objects.html (WebDriver API)

The actual work is done inside the page classes that all inherit from a 
class called WebDriverPage, which provides the usual WebDriver methods 
like get from Selenium.

If you are constructing the objects yourself, you have to pass a 
WebDriverProvider between the classes, if you are using dependency 
injection (guice, spring), this will happen automatically. The whole 
thing has to be run in a single thread executor unless you use a per 
story web driver.

You can use steps classes (plain classes not inheriting from anything) 
using different page classes (inheriting from the WebDriverPage class), 
so you can organize your classes (plus if you have different step 
classes using the same page classes you can refactor step implementations)

On 04.08.2012 10:53, Roy de Kleijn wrote:
> I like to organize my steps in multiple class files. (because we have
> many steps in our application)
>
> Question is: how can we use the steps from multiple step definition
> classes to execute a single story.
>
> I use webdriver, I tried the following:
>
> BaseClass.java
> Instantiates the driver and opens the browser.
>
> LoginSteps.java inherit from BaseClass.java
> steps to login in application
>
> SearchSteps.java inherit from BaseClass.java
> Verify is elements is present.
> BUT here is my driver instance suddenly null.
>
> I think it has something to do with the way I execute my tests:
>  <at> Override
> public InjectableStepsFactory stepsFactory() { return new
> InstanceStepsFactory(configuration(), new LoginSteps(), new
> searchPageSteps()); }
>
> Please tell what other information you need or what I have to do
> differently.
> Thanks
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Gmane