Created
January 13, 2014 02:51
-
-
Save jaxzin/8393988 to your computer and use it in GitHub Desktop.
Cucumber-JVM, hacking Scenario object to get the scenario name.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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