Skip to content

Instantly share code, notes, and snippets.

@jaxzin
Created January 13, 2014 02:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaxzin/8393988 to your computer and use it in GitHub Desktop.
Save jaxzin/8393988 to your computer and use it in GitHub Desktop.
Cucumber-JVM, hacking Scenario object to get the scenario name.
@Before
public void initSelenium(Scenario scenario) throws Exception {
// TODO: Find the scenario name
String scenarioName = ((ExecutionUnitRunner)getPrivateField(getPrivateField(scenario, "reporter"), "executionUnitRunner")).getName();
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("version", "5");
capabilities.setCapability("platform", Platform.XP);
capabilities.setCapability("name", scenarioName);
this.driver = new RemoteWebDriver(
new URL("http://"+authentication.getUsername()+":"+authentication.getAccessKey()+"@ondemand.saucelabs.com:80/wd/hub"),
capabilities);
}
private static Object getPrivateField(Object subject, String fieldName) throws NoSuchFieldException, IllegalAccessException {
Field f = subject.getClass().getDeclaredField(fieldName);
f.setAccessible(true);
return f.get(subject);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment