Discussion:
[wtr-general] Running 2 cucumber feature file in one web session
江南
2017-12-06 14:32:35 UTC
Permalink
Hi,

I am using Watir Ruby + Cucumber for my testing.

Can you tell me how to run two feature files in one web session?

Thanks
--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.

watir-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Arik Jones
2017-12-06 18:19:09 UTC
Permalink
You could create a browser session in `features/support/env.rb` and assign
it to an instance variable
and then use that session in your feature files. Its basically a global
hook, but you'll need to end that session properly with an `at_exit` method.

More info here: https://github.com/cucumber/cucumber/wiki/Hooks#global-hooks

Personally I don't recommend running your features that way. Can I ask why
you need to do it this way?
Post by 江南
Hi,
I am using Watir Ruby + Cucumber for my testing.
Can you tell me how to run two feature files in one web session?
Thanks
--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.

watir-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Chuck van der Linden
2017-12-07 17:27:00 UTC
Permalink
Post by Arik Jones
You could create a browser session in `features/support/env.rb` and assign
it to an instance variable
and then use that session in your feature files. Its basically a global
hook, but you'll need to end that session properly with an `at_exit` method.
https://github.com/cucumber/cucumber/wiki/Hooks#global-hooks
Personally I don't recommend running your features that way. Can I ask
why you need to do it this way?
Post by 江南
Hi,
I am using Watir Ruby + Cucumber for my testing.
Can you tell me how to run two feature files in one web session?
Thanks
That's where (in the env.rb file) I normally create the browser object when
using Cucumber..

Performance wise that is highly preferable to creating and destroying a
browser instance for each scenario, which can add quite a bit of overhead
to your tests. You may want a step that clears cookies, or loads a
standard cookie for tests where that can matter, then include that as
needed to simulate a 'clean-start' on the browser when required.

Unless you want to type out a really long command line with each feature
file specified, using Tags is generally the easiest way I have found to
have cucumber execute multiple scenarios from multiple feature files.
--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.

watir-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Arik Jones
2017-12-07 18:23:16 UTC
Permalink
I've always treated each scenario as its own session. It eliminates some of
the complication with session tear-down/cleanup since every session is
brand new. The only thing I have to worry about is closing the browser at
the end of each of scenario.

On Thursday, December 7, 2017 at 11:27:01 AM UTC-6, Chuck van der Linden
Post by Chuck van der Linden
Post by Arik Jones
You could create a browser session in `features/support/env.rb` and
assign it to an instance variable
and then use that session in your feature files. Its basically a global
hook, but you'll need to end that session properly with an `at_exit` method.
https://github.com/cucumber/cucumber/wiki/Hooks#global-hooks
Personally I don't recommend running your features that way. Can I ask
why you need to do it this way?
Post by 江南
Hi,
I am using Watir Ruby + Cucumber for my testing.
Can you tell me how to run two feature files in one web session?
Thanks
That's where (in the env.rb file) I normally create the browser object
when using Cucumber..
Performance wise that is highly preferable to creating and destroying a
browser instance for each scenario, which can add quite a bit of overhead
to your tests. You may want a step that clears cookies, or loads a
standard cookie for tests where that can matter, then include that as
needed to simulate a 'clean-start' on the browser when required.
Unless you want to type out a really long command line with each feature
file specified, using Tags is generally the easiest way I have found to
have cucumber execute multiple scenarios from multiple feature files.
--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.

watir-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
江南
2017-12-08 09:54:15 UTC
Permalink
Thanks for your suggestion.

I'm testing a website and I have various data to test but I don't want to
create duplicate steps in different feature files so I want to do is put
the test steps e.g. Login page in one feature file and Account page in
another then pull the input data from a spreadsheet.
I think this way will make easier to maintain the feature file that is
all.
Post by Arik Jones
You could create a browser session in `features/support/env.rb` and assign
it to an instance variable
and then use that session in your feature files. Its basically a global
hook, but you'll need to end that session properly with an `at_exit` method.
https://github.com/cucumber/cucumber/wiki/Hooks#global-hooks
Personally I don't recommend running your features that way. Can I ask
why you need to do it this way?
Post by 江南
Hi,
I am using Watir Ruby + Cucumber for my testing.
Can you tell me how to run two feature files in one web session?
Thanks
--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.

watir-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Chuck van der Linden
2017-12-08 17:35:05 UTC
Permalink
Post by 江南
Thanks for your suggestion.
I'm testing a website and I have various data to test but I don't want to
create duplicate steps in different feature files so I want to do is put
the test steps e.g. Login page in one feature file and Account page in
another then pull the input data from a spreadsheet.
I think this way will make easier to maintain the feature file that is
all.
While well intentioned you are heading in a direction that doesn't work
very well.. Also your question seems to tell me you don't understand the
basic concepts of how cucumber works (or you are not good at expressing
your understanding)

By design, steps are re-usable so it is completely normal to see the same
steps used in multiple feature files.
By design, there is only a single definition for a given step.. you can't
have two steps with the same phrasing such as "When I login as xxxx" that
do different things, that will result in an error.
Feature files should be created in a way that documents and describes the
operation of the product. Think of it like portions of a book that tells
what your product does.
Step files, where steps are defined do not have to (and usually should not)
parallel your feature files. Rather the most common thing is to group
common steps together. For example a login_steps.rb file might have steps
to login, self-register a new user, logout, etc. You might have another
step file that deals with steps that navigate around your site "when I
click the xxx tab" for example

For anyone new to Cucumber I strongly recommend reading "the Cucumber
Book" it's the best way to gain an understanding of what cucumber is for,
and how to best use it most effectively.
--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.

watir-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Chuck van der Linden
2017-12-08 17:47:10 UTC
Permalink
one other thing (see below
Post by 江南
Thanks for your suggestion.
I'm testing a website and I have various data to test but I don't want to
create duplicate steps in different feature files so I want to do is put
the test steps e.g. Login page in one feature file and Account page in
another then pull the input data from a spreadsheet.
I think this way will make easier to maintain the feature file that is
all.
Dangit, hit send too quickly on prior response. I also meant to add this
regarding spreadsheet use with cucumber.

If you are working with cucumber but want to pull in data from a
spreadsheet, that is most often a sign that cucumber may not be the right
tool for you. When using cucumber your test data should be defined in
the feature files. There are a number of ways that cucumber supports
this, from steps that can take a table to process, to using scenario
outlines where the scenario is defined with replaceable parameters that are
pulled from a table of 'examples' and the scenario is repeated for each
row in the table.

Putting test data in a spreadsheet obscures it from view, making it harder
to understand what tests are doing when reading feature files, which
defeats the main purpose (common understanding) of using feature files in
the first place. If 'it doesn't matter because nobody else reads the
feature files' then you should not be using cucumber, use instead rspec and
just code the test steps directly in code, not in a feature file. Then if
you want to have data files in spreadsheets, you can just make use of some
of the common gems for reading and writing common spreadsheet format files.

Cucumber is a great tool, but it is also primarily a collaboration tool,
not a test tool. Yes testing is a part of what cucumber does, but that is
not its primary purpose. Suggested
reading: https://cucumber.io/blog/2014/03/03/the-worlds-most-misunderstood-collaboration-tool
--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.

watir-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
江南
2017-12-11 09:15:38 UTC
Permalink
Thanks for all your information they are very helpful.

I do understand the concept of Cucumber.

I'm working directly with a Developer, I personally have not come up with
this idea but my Developer has asked me about writing the script this way
and I have explained to him about Page Object but I also want to get an
outside opinion just to be a supporting evidence that this is not the way
to use Cucumber.
Post by Chuck van der Linden
one other thing (see below
Post by 江南
Thanks for your suggestion.
I'm testing a website and I have various data to test but I don't want to
create duplicate steps in different feature files so I want to do is put
the test steps e.g. Login page in one feature file and Account page in
another then pull the input data from a spreadsheet.
I think this way will make easier to maintain the feature file that is
all.
Dangit, hit send too quickly on prior response. I also meant to add this
regarding spreadsheet use with cucumber.
If you are working with cucumber but want to pull in data from a
spreadsheet, that is most often a sign that cucumber may not be the right
tool for you. When using cucumber your test data should be defined in
the feature files. There are a number of ways that cucumber supports
this, from steps that can take a table to process, to using scenario
outlines where the scenario is defined with replaceable parameters that are
pulled from a table of 'examples' and the scenario is repeated for each
row in the table.
Putting test data in a spreadsheet obscures it from view, making it harder
to understand what tests are doing when reading feature files, which
defeats the main purpose (common understanding) of using feature files in
the first place. If 'it doesn't matter because nobody else reads the
feature files' then you should not be using cucumber, use instead rspec and
just code the test steps directly in code, not in a feature file. Then if
you want to have data files in spreadsheets, you can just make use of some
of the common gems for reading and writing common spreadsheet format files.
Cucumber is a great tool, but it is also primarily a collaboration tool,
not a test tool. Yes testing is a part of what cucumber does, but that is
https://cucumber.io/blog/2014/03/03/the-worlds-most-misunderstood-collaboration-tool
--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.

watir-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Chuck van der Linden
2017-12-11 20:02:24 UTC
Permalink
Post by 江南
Thanks for all your information they are very helpful.
I do understand the concept of Cucumber.
I'm working directly with a Developer, I personally have not come up with
this idea but my Developer has asked me about writing the script this way
and I have explained to him about Page Object but I also want to get an
outside opinion just to be a supporting evidence that this is not the way
to use Cucumber.
So if you are using Feature files as a way to gain understanding of what
the product should do, and working with a developer (and hopefuly PO) to
create and review feature files, then it sounds like you have at least one
other person on the team that knows about BDD and why you want to use tools
like Cucumber. As long as some collaboration benefit is accruing, then I
would say proceed with Cucumber. If you are the only person that ever
looks at a feature file, then there is little benefit to using Cucumber
over something like Rspec. (FYI if you and the developer like the idea of
using cucumber, but the PO is hesitant, I'd suggest you see if you can get
them to have a look at the book 'Specification By Example" The first two
chapters can be downloaded from the publisher for free, and do a good job
of laying out the benefits of this approach.

The 'Page Objects' Pattern is not an alternative to Cucumber, nor something
to use instead of Cucumber. Page Objects is an abstraction layer to make
it easier to maintain the identifiers of webpage elements in test code that
is testing a Web UI. The idea is that if a developer does something like
change the UI such that you need to update identifiers, that you just have
to do that in one single place, instead of updating 50 scripts or step
files. You can use Page Objects in just about any testing framework, be it
inside the steps of cucumber tests, or inside test methods in Rspec or
another testing library.
--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.

watir-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...