[Cucumber]: how to set feature path to different module

2,693 views
Skip to first unread message

Chen Sifei

unread,
Dec 29, 2015, 2:24:44 PM12/29/15
to Cukes
Hi,

My current code is:
 @RunWith(CucumberTestRunner.class)
    @CucumberOptions(
            features = "features",
            glue = {"uifunctionaltests.stepdefs.common",
                    "uifunctionaltests.stepdefs.anywhere"},
            tags = {"@all", "~@ignore"},
            strict = true
    )
    public static class All {
        public static void setupFramework() {
            commonSetup();
        }
    }

features directory is in the same module.   But now, I want to move all features to a different modules so that they can be shared by other modules.  Could someone help me how should I set feature path here?

Thanks very much!
Sophie
      

Paolo Ambrosio

unread,
Dec 29, 2015, 3:15:09 PM12/29/15
to cu...@googlegroups.com
Technically if you put your features as resources in a separate module
and import them in the test classpath, you should be able to find them
with @CucumberOptions(features = "classpath:features", ...). Not tried
it though :-)

Apart from the technical bits, I can't really find a good reason why
you would want to do that. Can you explain why you are trying to move
the features out of the module that they define?


Paolo

> Thanks very much!
> Sophie
Message has been deleted

Sophie

unread,
Dec 29, 2015, 5:05:11 PM12/29/15
to Cukes
Thank you Paolo for the answers!   My tests will be running on different platforms.  And the tests implementation on different platforms are built on top of different framework, while these framework have conflicts in dependencies.  But I want to share the same cucumber test cases between different platforms.  So, I need to move cucumber test cases into a separated module for sharing.

Could you help to specific how to put features as resources in a separate module and how to import them in the test classpath?  Below is what i did, but it still cannot find the features:
1.  In UIFunctionalTestCases module which has all cucumber features, from Intellij -> Project Structure -> Source ->  Select features folder and Marks as "Resources"
2.  In test case implementation module, I add it as test dependencies by : from intellij -> Project Structure -> Dependencies -> click green + on the right -> select Module Dependencies ->  select UIFunctionalTestCases and set Scope as Test.

I think that I am wrong about these two steps so it is still not working.  Could you please correct me steps?  Thanks again!

Sophie

On Tuesday, December 29, 2015 at 12:15:09 PM UTC-8, Paolo Ambrosio wrote:

Paolo

Paolo Ambrosio

unread,
Dec 29, 2015, 6:05:46 PM12/29/15
to cu...@googlegroups.com
On Tue, Dec 29, 2015 at 8:43 PM, Sophie <csh...@gmail.com> wrote:
> Thank you Paolo for the answers. My tests needs to be run on different
> platforms. But the automation tests for different platforms are built on
> top of different framework, while these frameworks have dependencies
> conflict. The tests implementation on different platforms needs to be in
> different modules. But, we still want to share the same cucumber test
> cases. This is why i want to move features into a separated modules for
> sharing.

This makes sense :-) I initially thought you meant modules as parts of
the same application, not as different implementations sharing the
same basic behaviour.

> Could I confirm with your suggestions:
> 1. In cucumber test case module (UIFunctionalTestCases), i marked features
> folder as resource from: Intellij -> Project Structure -> Sources -> select
> features folder and Mark as "Resources Folders"
> 2. In my test case implementation module, I import them in test classpath
> by: Intellij -> Project Structure -> Dependencies -> click green "+" ->
> select Module Dependency -> select UIFunctionalTestCases and set scope as
> "Test".
> 3. And change my code as:
> @CucumberOptions(features = "classpath:UIFunctionalTestCases/features"

If you have the feature files in a "features" directory in the
UIFunctionalTestCases resources, you should just use
"classpath:features", without the project name.

If that still does not work, make sure that your JUnit test runner is
in a directory marked as test (i think green folder).

> I tried with these steps, it still shows me that cannot find features in
> UIFunctionalTestCases/features. I guess that I am wrong about import test
> classpath. Could you help to correct me? Thanks a lot!
>
> On Tuesday, December 29, 2015 at 12:15:09 PM UTC-8, Paolo Ambrosio wrote:
>>
> --
> 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.

Sophie

unread,
Dec 29, 2015, 7:12:21 PM12/29/15
to Cukes
Hi Paolo,

It is still not working with no match found.  :(   Could you let me know what is the exact value of "classpath" in @CucumberOptions(features = classpath:features) ?  Because I tried an absolute path to the cucumber test case module :  @CucumberOptions(features =  "/workplace/sophie/mytests/src/UIFunctionalTestCases/features"), it is working.    So I guess that cucumber didn't find out the correct path to "classpath:features".  However,  how can I find out what path was parsed by giving "classpath:features".

BTW - In my test case implementation module: TestsImplementationModule/runners/IPhoneRunner.java:
@RunWith(CucumberTestRunner.
class)
    @CucumberOptions(
            features = "classpath: features",

            glue = {"uifunctionaltests.stepdefs.common",
                    "uifunctionaltests.stepdefs.anywhere"},
            tags = {"@all", "~@ignore"},
            strict = true
    )
    public static class All {
        public static void setupFramework() {
            commonSetup();
        }
    }

Thank you for your patient!




Paolo Ambrosio

unread,
Dec 30, 2015, 2:36:56 AM12/30/15
to cu...@googlegroups.com
On Wed, Dec 30, 2015 at 12:12 AM, Sophie <csh...@gmail.com> wrote:

> Hi Paolo,
>
> It is still not working with no match found. :( Could you let me know
> what is the exact value of "classpath" in @CucumberOptions(features =
> classpath:features) ? Because I tried an absolute path to the cucumber test
> case module : @CucumberOptions(features =
> "/workplace/sophie/mytests/src/UIFunctionalTestCases/features"), it is
> working. So I guess that cucumber didn't find out the correct path to
> "classpath:features". However, how can I find out what path was parsed by
> giving "classpath:features".
>
> BTW - In my test case implementation module:
> TestsImplementationModule/runners/IPhoneRunner.java:
> @RunWith(CucumberTestRunner.
> class)
> @CucumberOptions(
> features = "classpath: features",

I suspect removing the space in "classpath: features" would solve the
problem. In case it does not, I'm attaching a simple project based on
the Cucumber Java skeleton that has feature files and implementation
in two separate projects. It uses Gradle, so you can import it without
manual configuration on the IDE (you should REALLY consider that
option instead of fiddling with IntelliJ settings).
multi-implementation-cukes.zip

Sophie

unread,
Dec 30, 2015, 1:30:08 PM12/30/15
to Cukes
Following your example pattern, after I create a separate folder of "resources" and put "features" in "resources" (and also removed the space), it works now!  We are not using Gradle, but ANT.  So, i need to set these settings into Build.xml file - though I am still not sure how.  But it's already great progress now.  Thank you very much Paolo !!
Reply all
Reply to author
Forward
0 new messages