[cucumber-jvm] Is there a way to use JUnit parameterized runner?

923 views
Skip to first unread message

Max Ch

unread,
Apr 4, 2012, 11:23:45 PM4/4/12
to cu...@googlegroups.com
Hi there,
I'm trying to use cucumber-jvm to run my Selenium test in the selenium grid. So as you can imagine I have same exact feature, which i want to run on multiple configurations (ff on XP, chrome on Linux and so on). But i also want to implement it flexible enough to run it locally on the developer machine depend on parameters passed to the test (such as list of the Grid configurations or just one WebDriver). I thought that the JUnit parameterized runner will work for that, but to run it i should @RunWith(Parameterized.class) and it's not possible since I @RunWith(Cucumber.class). 
Is there any other elegant solution for my problem (don't want to create bunch of same stepDef classes with different capabilities for RemoteDriver), or is that possible to @RunWith(Parameterized.class) and then in @Before method do what @RunWith(Cucumber.class) usually do for me?
Thanks in advanced for any help.

Matthew

unread,
Apr 10, 2012, 3:45:53 PM4/10/12
to cu...@googlegroups.com
I think with JUnit you're stuck with one @RunWith option, and you'll need the Cucumber one I think.  So maybe we can figure out a different way to parametrise it.  How are you running your build?  I ask because we use maven, and use profiles to run different configurations on different machines.  Basically what we do is that each developer is using a dev profile, and when maven runs it sets up a config file which our @Before code picks up and runs Selenium locally on our machine.  On the build server the config file gets set up so that it runs in Hub mode.  Would something like that help?

Max Ch

unread,
Apr 11, 2012, 11:39:52 PM4/11/12
to cu...@googlegroups.com
Matthew
Thanks for reply, but i still didn't get how profiles can help me to run same set of tests with different parameters (different webdrivers in this case). Can you provide example of your profile? I'm running my build as JUnit through maven as well.
Thanks for help

Matthew

unread,
Apr 12, 2012, 2:50:29 PM4/12/12
to cu...@googlegroups.com
So what we're really talking about here is maven filtering and profiles.  I had a quick skim, and this looks like a reasonable example blog of how it works:


(we do something similar here - but slightly different, we wrote a custom maven plugin to help us deal with properties, but the effect is the same).

In this instance we use a separate config file to tell the runner how to run (local or hub):

String testSetup = getProperties().getProperty("test.setup");

WebDriver driver = null;
if (testSetup == null || testSetup.equals("local") || "${test.setup}".equals(testSetup)) {
logger.info("running locally due to conf: " + testSetup);
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("app.update.enabled", false);
// AUM Set to: Minor Releases: Major Releases:
// 0 download no prompt download no prompt
// 1 download no prompt download no prompt if no incompatibilities
// 2 download no prompt prompt
firefoxProfile.setPreference("app.update.mode", 2);
firefoxProfile.setEnableNativeEvents(true);
driver = new FirefoxDriver(firefoxProfile);
} else {
logger.info("running on hub due to conf: " + testSetup);
DesiredCapabilities capability = DesiredCapabilities.firefox();
try {
      driver = new RemoteWebDriver(new URL("http://machinename:4444/wd/hub"), capability);
} catch (MalformedURLException e) {
driver = null;
e.printStackTrace();
}
}

Where the test.setup property comes from a config file that has been replaced with the correct property for our environment.

Does that help provide a path? it would mean multiple maven runs to run the different configurations (with a different property set each time), but hopefully this helps?

Cheers,

Matt

Aslak Hellesøy

unread,
Apr 11, 2013, 7:50:15 PM4/11/13
to cu...@googlegroups.com


On Thursday, April 5, 2012 4:23:45 AM UTC+1, Max Ch wrote:
Hi there,
I'm trying to use cucumber-jvm to run my Selenium test in the selenium grid. So as you can imagine I have same exact feature, which i want to run on multiple configurations (ff on XP, chrome on Linux and so on).

We're currently discussing this feature.

Aslak
Reply all
Reply to author
Forward
0 new messages