Skip to content

Commit

Permalink
#50: added scenarioPaths command line argument
Browse files Browse the repository at this point in the history
  • Loading branch information
build-failure committed Sep 22, 2016
1 parent 869d63a commit 00c413b
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Changed
- allowed setting multiple scenario paths as cmd line argument values (#50)

### Fixed
- fixed interpretation of the timeout step criteria value as seconds (#49)

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ java -jar <path to jar> -<argument name> [<argument value> ...]
| Name | Type | Description | Default | Example |
| ------------- | ------------- | ------------- | ------------- | ------------- |
| *scenarioPath* | optional | Scenario path may be a directory or a single scenario file. | `./` |`../path/to/my/scenario` |
| *scenarioPaths* | optional | Scenario paths may be a directory, a single scenario file or a set of both. | |`../path/to/my/scenario` `../path/to/my/another/scenario` |
| *scenarioPattern* | optional | If set, only non fragment scenarios with a name matching the pattern are executed. | `-` | `'^desired-scenario$'` |
| context | optional | Context is a multi value argument that populates the context utilized during expression evaluation. | `-` |`baseUrl=http://www.wikipedia.com language=en` |
| *timeout* | optional | Timeout waiting for conditions to be fulfilled in seconds. Globally overrides timeout settings defined in the scenarios. | `-` | `5` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import static java.text.MessageFormat.format;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import website.automate.jwebrobot.executor.ExecutorOptions.ScreenshotType;
import website.automate.jwebrobot.executor.ExecutorOptions.TakeScreenshots;
Expand All @@ -18,9 +21,12 @@ public class ConfigurationProperties {
DEFAULT_REPORT_PATH = "./report.yaml",
DEFAULT_SCENARIO_PATH = "./",
DEFAULT_BROWSER_LOG_LEVEL = "error";
@Parameter(names = "-scenarioPath", description = "Path to a single WAML scenario or WAML project root directory.", required = true)

@Parameter(names = "-scenarioPath", description = "Path to a single WAML scenario or WAML project root directory.", required = false)
private String scenarioPath = DEFAULT_SCENARIO_PATH;

@Parameter(names = "-scenarioPaths", variableArity = true, description = "Path to a single WAML scenario or WAML project root directory.", required = false)
private List<String> scenarioPaths = new ArrayList<>();

@Parameter(names = "-browser", description = "Browser to use for execution (e.g firefox or chrome).", required = false)
private String browser = "firefox";
Expand Down Expand Up @@ -52,12 +58,12 @@ public class ConfigurationProperties {
@Parameter(names = "-browserLogLevel", description = "Log level at which browser logs are included into the reports.", required = false)
private String browserLogLevel = DEFAULT_BROWSER_LOG_LEVEL;

public String getScenarioPath() {
return scenarioPath;
public List<String> getScenarioPaths() {
return scenarioPaths;
}

public void setScenarioPath(String scenarioPath) {
this.scenarioPath = scenarioPath;
public void setScenarioPaths(List<String> scenarioPaths) {
this.scenarioPaths = scenarioPaths;
}

public String getBrowser() {
Expand Down Expand Up @@ -149,4 +155,22 @@ public String getBrowserLogLevel() {
public void setBrowserLogLevel(String browserLogLevel) {
this.browserLogLevel = browserLogLevel;
}

public String getScenarioPath() {
return scenarioPath;
}

public Collection<String> getAllScenarioPaths(){
Set<String> scenarioPaths = new HashSet<>();
String scenarioPath = getScenarioPath();
if(!ConfigurationProperties.DEFAULT_SCENARIO_PATH.equals(scenarioPath)){
scenarioPaths.add(scenarioPath);
}
scenarioPaths.addAll(getScenarioPaths());
return scenarioPaths;
}

public void setScenarioPath(String scenarioPath) {
this.scenarioPath = scenarioPath;
}
}
2 changes: 1 addition & 1 deletion src/main/java/website/automate/jwebrobot/JWebRobot.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public JWebRobot() {
}

public void run(ConfigurationProperties configurationProperties) {
List<ScenarioFile> scenarioFiles = scenarioLoader.load(configurationProperties.getScenarioPath(),
List<ScenarioFile> scenarioFiles = scenarioLoader.load(configurationProperties.getAllScenarioPaths(),
configurationProperties.getReportPath());
ExecutorOptions executorOptions = ExecutorOptions.of(configurationProperties);
GlobalExecutionContext globalContext = new GlobalExecutionContext(scenarioFiles, executorOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,18 @@ public PatternScenarioLoader(WamlReader wamlReader){
this.wamlReader = wamlReader;
}

public List<ScenarioFile> load(String scenarioPath, String reportPath){
@Override
public List<ScenarioFile> load(Collection<String> scenarioPaths, String reportPath){
List<ScenarioFile> scenarioFiles = new ArrayList<>();

for(String scenarioPath : scenarioPaths){
scenarioFiles.addAll(load(scenarioPath, reportPath));
}

return scenarioFiles;
}

private List<ScenarioFile> load(String scenarioPath, String reportPath){
String currentPath = scenarioPath;
List<ScenarioFile> loadedScenarioFiles = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package website.automate.jwebrobot.loader;

import java.io.InputStream;
import java.util.Collection;
import java.util.List;

import website.automate.waml.io.model.Scenario;

public interface ScenarioLoader {

List<ScenarioFile> load(String scenarioPath, String reportPath);
List<ScenarioFile> load(Collection<String> scenarioPath, String reportPath);

List<Scenario> createFromInputStream(InputStream inputStream);
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private List<ScenarioFile> asScenarioFiles(List<Scenario> scenarios){

private List<Scenario> getScenarios(String scenarioPath) {
return scenarioLoader
.load(scenarioPath, ConfigurationProperties.DEFAULT_REPORT_PATH)
.load(asList(scenarioPath), ConfigurationProperties.DEFAULT_REPORT_PATH)
.get(0)
.getScenarios();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package website.automate.jwebrobot.loader;

import static java.lang.ClassLoader.getSystemResourceAsStream;
import static java.util.Arrays.asList;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
Expand All @@ -26,7 +27,7 @@ public class PatternScenarioLoaderIT extends AbstractTest {

@Test
public void loadScenariosFromTheBaseDirectoryRecursively(){
List<ScenarioFile> scenarioFiles = scenarioLoader.load("./src/test/resources/website/automate/jwebrobot/loader",
List<ScenarioFile> scenarioFiles = scenarioLoader.load(asList("./src/test/resources/website/automate/jwebrobot/loader"),
ConfigurationProperties.DEFAULT_REPORT_PATH);

assertThat(scenarioFiles.size(), is(3));
Expand All @@ -35,7 +36,7 @@ public void loadScenariosFromTheBaseDirectoryRecursively(){

@Test
public void loadSingleScenarioFromPath(){
List<ScenarioFile> scenarioFiles = scenarioLoader.load("./src/test/resources/website/automate/jwebrobot/loader/multi.yaml",
List<ScenarioFile> scenarioFiles = scenarioLoader.load(asList("./src/test/resources/website/automate/jwebrobot/loader/multi.yaml"),
ConfigurationProperties.DEFAULT_REPORT_PATH);

assertThat(scenarioFiles.size(), is(1));
Expand All @@ -44,7 +45,7 @@ public void loadSingleScenarioFromPath(){

@Test(expected=NonReadableFileException.class)
public void failLoadingNonExistingFile(){
scenarioLoader.load("./src/test/resources/website/automate/jwebrobot/loader/non-existent.yaml",
scenarioLoader.load(asList("./src/test/resources/website/automate/jwebrobot/loader/non-existent.yaml"),
ConfigurationProperties.DEFAULT_REPORT_PATH);
}

Expand Down

0 comments on commit 00c413b

Please sign in to comment.