Skip to content

Commit

Permalink
Add support for handling suite files, fixes #51
Browse files Browse the repository at this point in the history
  • Loading branch information
rossrowe committed Jul 6, 2013
1 parent ea1c8f0 commit 26e687d
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 33 deletions.
9 changes: 9 additions & 0 deletions se-builder.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

2 changes: 1 addition & 1 deletion tools/seinterpreter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>sebuilder-interpreter</artifactId>
<groupId>com.saucelabs</groupId>
<version>1.0.0</version>
<version>1.0.1</version>
<packaging>jar</packaging>
<name>sebuilder-interpreter</name>
<description></description>
Expand Down
44 changes: 22 additions & 22 deletions tools/seinterpreter/sebuilder-interpreter.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
Expand All @@ -13,44 +13,44 @@
<orderEntry type="library" name="Maven: org.json:json:20080701" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-java:2.30.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-android-driver:2.30.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-remote-driver:2.30.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-java:2.32.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-android-driver:2.32.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-remote-driver:2.32.0" level="project" />
<orderEntry type="library" name="Maven: cglib:cglib-nodep:2.1_3" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-api:2.30.0" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:14.0-rc1" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-api:2.32.0" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:14.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.2.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.2.1" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.7" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-exec:1.1" level="project" />
<orderEntry type="library" name="Maven: net.java.dev.jna:jna:3.4.0" level="project" />
<orderEntry type="library" name="Maven: net.java.dev.jna:platform:3.4.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-chrome-driver:2.30.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-htmlunit-driver:2.30.0" level="project" />
<orderEntry type="library" name="Maven: net.sourceforge.htmlunit:htmlunit:2.11" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-chrome-driver:2.32.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-htmlunit-driver:2.32.0" level="project" />
<orderEntry type="library" name="Maven: net.sourceforge.htmlunit:htmlunit:2.12" level="project" />
<orderEntry type="library" name="Maven: xalan:xalan:2.7.1" level="project" />
<orderEntry type="library" name="Maven: xalan:serializer:2.7.1" level="project" />
<orderEntry type="library" name="Maven: xml-apis:xml-apis:1.4.01" level="project" />
<orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpmime:4.2.2" level="project" />
<orderEntry type="library" name="Maven: net.sourceforge.htmlunit:htmlunit-core-js:2.11" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpmime:4.2.3" level="project" />
<orderEntry type="library" name="Maven: net.sourceforge.htmlunit:htmlunit-core-js:2.12" level="project" />
<orderEntry type="library" name="Maven: xerces:xercesImpl:2.10.0" level="project" />
<orderEntry type="library" name="Maven: net.sourceforge.nekohtml:nekohtml:1.9.17" level="project" />
<orderEntry type="library" name="Maven: net.sourceforge.cssparser:cssparser:0.9.8" level="project" />
<orderEntry type="library" name="Maven: net.sourceforge.nekohtml:nekohtml:1.9.18" level="project" />
<orderEntry type="library" name="Maven: net.sourceforge.cssparser:cssparser:0.9.9" level="project" />
<orderEntry type="library" name="Maven: org.w3c.css:sac:1.3" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.2" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-websocket:8.1.7.v20120910" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-util:8.1.7.v20120910" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-io:8.1.7.v20120910" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-http:8.1.7.v20120910" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-firefox-driver:2.30.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-ie-driver:2.30.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-iphone-driver:2.30.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-safari-driver:2.30.0" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-websocket:8.1.9.v20130131" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-util:8.1.9.v20130131" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-io:8.1.9.v20130131" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-http:8.1.9.v20130131" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-firefox-driver:2.32.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-ie-driver:2.32.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-iphone-driver:2.32.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-safari-driver:2.32.0" level="project" />
<orderEntry type="library" name="Maven: org.webbitserver:webbit:0.4.14" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty:3.5.2.Final" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-support:2.30.0" level="project" />
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-support:2.32.0" level="project" />
</component>
</module>

12 changes: 12 additions & 0 deletions tools/seinterpreter/seinterpreter.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

59 changes: 53 additions & 6 deletions tools/seinterpreter/src/com/sebuilder/interpreter/IO.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@

package com.sebuilder.interpreter;

import java.io.IOException;
import java.io.Reader;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
* Utilities for reading scripts.
* @author zarkonnen
Expand All @@ -34,24 +37,32 @@ public class IO {
* @return A script, ready to run.
* @throws IOException If anything goes wrong with interpreting the JSON, or with the Reader.
* @throws JSONException If the JSON can't be parsed.
* @throws SuiteException If the script is of type 'suite', so that each script referenced by the suite can be processed
*/
public static Script read(Reader r) throws IOException, JSONException {
public static Script read(Reader r) throws IOException, JSONException, SuiteException {
return parse(new JSONObject(new JSONTokener(r)));
}

/**
* @param scriptO A JSONObject describing a script.
* @return A script, ready to run.
* @throws IOException If anything goes wrong with interpreting the JSON.
* @throws SuiteException If the script is of type 'suite', so that each script referenced by the suite can be processed
*/
public static Script parse(JSONObject scriptO) throws IOException {
public static Script parse(JSONObject scriptO) throws IOException, SuiteException {
try {
if (!scriptO.get("seleniumVersion").equals("2")) {
throw new IOException("Unsupported Selenium version: \"" + scriptO.get("seleniumVersion") + "\".");
}
if (scriptO.getInt("formatVersion") != 1) {
throw new IOException("Unsupported Selenium script format version: \"" + scriptO.get("formatVersion") + "\".");
}
if (scriptO.has("type")) {
String type = scriptO.getString("type");
if (type.equals("suite")) {
throw new SuiteException(scriptO);
}
}
Script script = new Script();
JSONArray stepsA = scriptO.getJSONArray("steps");
for (int i = 0; i < stepsA.length(); i++) {
Expand All @@ -74,7 +85,11 @@ public static Script parse(JSONObject scriptO) throws IOException {
}
}
return script;
} catch (Exception e) {
}
catch (SuiteException e) {
throw e;
}
catch (Exception e) {
throw new IOException("Could not parse script.", e);
}
}
Expand Down Expand Up @@ -146,4 +161,36 @@ public static StepType getStepTypeOfName(String name) {
throw new RuntimeException("Step type \"" + name + "\" is not implemented.", e);
}
}
/**
* Exception which is thrown when the {@link IO#parse(org.json.JSONObject)} method detects that a Script file
* is a suite.
*
* @author Ross Rowe
*/
public static class SuiteException extends Exception {

private List<String> paths = new ArrayList<String>();

/**
* Constructs the exception, and populates the {@link #paths} by parsing the jsonObject.
*
* @param jsonObject A JSONObject describing a script.
* @throws org.json.JSONException if any errors occur retrieving the attributes from the jsonObject
*/
public SuiteException(JSONObject jsonObject) throws JSONException {

JSONArray scriptLocations = jsonObject.getJSONArray("scripts");
for (int i = 0; i < scriptLocations.length(); i++) {
JSONObject script = scriptLocations.getJSONObject(i);
String where = script.getString("where");
//TODO handle 'where' types other than 'local'
String path = script.getString("path");
paths.add(path);
}
}

public List<String> getPaths() {
return paths;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@

import com.sebuilder.interpreter.webdriverfactory.Firefox;
import com.sebuilder.interpreter.webdriverfactory.WebDriverFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.PriorityQueue;

/**
* An interpreter for Builder JSON tests. Given one or more JSON script files, it plays them back
Expand Down Expand Up @@ -77,7 +79,10 @@ public static void main(String[] args) {
}

try {
for (String s : paths) {
//use a queue instead of iterating over the paths, as we may be adding to the paths if the script file is of type 'suite'
PriorityQueue<String> queue = new PriorityQueue<String>(paths);
while (queue.size() != 0) {
String s = queue.remove();
File f = new File(s);
if (!f.exists() || f.isDirectory()) {
throw new RuntimeException("The file " + f + " does not exist!");
Expand All @@ -98,7 +103,10 @@ public static void main(String[] args) {
} catch (Exception e) {
log.info(s + " failed", e);
}
} finally {
} catch (IO.SuiteException e) {
queue.addAll(e.getPaths());
}
finally {
if (br != null) { br.close(); }
}
}
Expand Down

0 comments on commit 26e687d

Please sign in to comment.