Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Se Interpreter is a command-line tool for playing back Selenium 2 .json files created by Builder. Instead of exporting scripts to a specific programming language for playback, you can keep them in their editable .json form and use Interpreter.
The interpreter is currently in beta, with the code here.
Interpreter requires Java to run. Selenium Server 2.35.0 is packaged with the download as a convenience, and is located in the
To play back a script, simply invoke
java -jar SeInterpreter.jar <path_to_script.json> [<path_to_script_2.json>...]
Interpreter will then start executing the script, starting up a local instance of Firefox to do so.
You can choose which Webdriver implementation to use by adding a
--driver=<drivername> argument. Currently, only the following drivers are supported out-of-the-box. (But see below for how to extend Interpreter.)
Note that these names must match exactly, including capitalization.
You can then further configure the driver by adding
--driver.<config_key>=<config_value> arguments. In general, the key/values are passed into the driver as capabilities, with the following exceptions:
- binary: location of the Firefox executable to use
- profile: location of the profile folder to use
- url: remote URL to connect to
Example: Using RemoteWebDriver
java -jar SeInterpreter.jar --driver=Remote --driver.browserName=firefox --driver.url=http://myservr.com/wd/hub/ script.json
The interpreter uses Apache Commons logging and creates logs for
com.sebuilder.interpreter.SeInterpreter. Script success/failure is logged at INFO, details about individual steps being run is logged at DEBUG. Failed verifies are logged at ERROR, and failed asserts and crashes are logged at FATAL. If that's too loud, you should be able to configure logging for the SeInterpreter class to be quieter. For example, for completely silent operation, you could invoke
java -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog -jar SeInterpreter.jar <path_to_script.json>
Using Interpreter as a Java Library
Or you can construct Script objects programmatically:
Script script = new Script(); Script.Step s = new Script.Step(new Get()); s.stringParams.put("url", "http://www.sebuilder.com"); script.steps.add(s); script.run();
See the Javadoc (also part of the download package) for more information.
The interpreter can be extended in two major ways: adding new WebDriver implementation factories, and adding new step types. Both work by implementing interfaces and then making the resulting classes available on the classpath.
To add a new WebDriver implementation, extend WebDriverFactory, and put the resulting class into the
com.sebuilder.interpreter.webdriverfactory package. You can then use this factory from the command-line by setting
driver to its name. Interpreter will instantiate a
com.sebuilder.interpreter.webdriverfactory.<YourFactoryName> object and use it to create drivers.
To add a new step type, extend StepType and put the resulting class into the
com.sebuilder.interpreter.steptype package. You can then use the name of the class in .json files, so a step of type
Foo will result in a Script.Step with a
The run() method of your new step type should perform whatever action the step type consists of. The TestRun
ctx object supplied lets you access the driver object and has convenience functions like Locator locator(String name) to easily get the parameters of the step you're executing.
Note that your StepType objects should be stateless - a step's parameters are stored in the Step objects in the Script, and the playback code works by calling the run function, passing in the state at that time.