Hubik
v0.0.1
Published
Cross-platform automated test engine for web app.
Downloads
2
Readme
Automated test engine for web apps in Chrome.
Hubik is an automated test engine for web apps.It provides the basic ability to execute custom javascript logic and fire key events in the web runtime of Chrome.This ability is based on Chrome Remote Debugging Protocol.
It separates the whole automated process into three periods.
- Initialization (Launching the platform.)
- Navigation (Loading the url of the web app.)
- Automation (Running the automated test.Automation is an ordered chain of automated actions.)
Hubik will set up a hook point at the start and end time of each period and each automated action.By using these hook points, Hubik can create an advanced flexable hook system which will be used by Hubik-Plugin.
Hubik-Plugin is the constructor of Hubik's plugin which should be created by the user to implement their own logic apart from the automated logic. The plugins can register some hooks to Hubik's hook system to run its logic in some specific time. For example,the ability to collect memory usage data(https://github.com/ycinfinity/Hubik-Plugin-Memory).
Requirement
- Mac OSX
- Nodejs > 5.0.0
Installation
npm install hubik
Usage
var Hubik = require("hubik"),
hubik = new Hubik(); //Create a Hubik instance.
//Create a hubik test suite.
hubik.suite(function($platform,$plugin,$task,$action){
$platform.launch("chrome") //Launch Chrome.
.load("http://www.google.com"); //Load the url of your web app.
$task.wait(200) //wait 200 ms before runing this automated task.
.execute( //Execute a List of automated actions in order.
[
$action.RUNTIME.execute({ // Execute a snippet of custom javascript logic in the web runtime of Chrome
script: "window.location.href",
callback: function(res){ // Receive the result of the custom javascript logic.
//res.type == "string"
//res.value == "http://www.google.com"
}
}).end() //Finish this action.
,
...
]
)
.repeat(5) // Repeat the automated task 5 times.
.end(); //Finish this task.
}).run(function(data){ //Run this test suite.
//data from plugins
});
Documentation
var Hubik = require("hubik"),
hubik = new Hubik();
hubik.install(plugins = Array)
Install an array of plugins which will be used in the hubik test suite.
var memoryPlugin = require("hubik-plugin-memory"),
renderingPlugin = require("hubik-plugin-rendering")
hubik.install([memoryPlugin,renderingPlugin])
var testSuite = hubik.suite(function($platform,$plugin,$task,$action){})
Create a hubik test suite which includes the main logic of the test.The only param of hubik.suite is a callback function. Hubik will inject some useful dependency objects into the callback function.
###$platform
1. $platform.launch(platformName = String,chromiumCommands = Array)
Launch the platform. The first param is platformName which is the name of the platform.Now only support "chrome". The second param is an array of chromium commands
2. $platform.load(url = String)
Load the url of the web app. The only param is the url of the web app.
$platform.launch("chrome")
$platform.load("http://www.google.com")
###$plugin
1. $plugin.enable(pluginName = String)
Enable a plugin you want to use in this test suite.The plugin should have already be installed by hubik.install. The only param is the name of the specific plugin.
2. $plugin.setArgs(pluginName = String, pluginArgs = Object)
Sometime the plugin needs some information from the test suite.(For example, user account and user password) This first param is this name of the specific plugin. The second param is an object of information which will be passed to the plugin.
$plugin.enable(customLoginPlugin.name)
$plugin.setArgs(customLoginPlugin.name, {
username: "test",
password: "111111"
})
###$task One test suite consists of several tasks.
1. $task.wait(millisecond = Int)
Make the task wait for some millisecond. The only param is the wait millisecond time.
2. $task.execute(actions = Array)
The task consists of several actions. The only param is an array of $actions.
3. $task.repeat(times = Int)
The only param is the repeat time of the task.
4. $task.end()
The end of the task.(required)
$task.wait(3000)
.execute([])
.repeat(3)
.end()
###$action One task consists of several actions.$action can only be used in $task.execute.
1. $action.KEY
Trigger key event in the web runtime of the platform.
$action.KEY.up({wait: millisecond = Int,repeat: times = Int})
This method will trigger 'up' key event. The only param is an object which consists of action wait time and action repeat time.
$action.KEY.down({wait: millisecond = Int,repeat: times = Int})
$action.KEY.left({wait: millisecond = Int,repeat: times = Int})
$action.KEY.right({wait: millisecond = Int,repeat: times = Int})
$action.KEY.enter({wait: millisecond = Int,repeat: times = Int})
$action.KEY.esc({wait: millisecond = Int,repeat: times = Int})
$action.KEY.input({name: keyName = String,code: keyCode: keyCode = String,wait: millisecond = Int,repeat: times = Int})
The only param is an object consists of action key name, action key code, action wait time and action repeat time.
$action.KEY.end()
The end of the key action.(required)
2. $action.RUNTIME
$action.RUNTIME.execute({script: javascriptSnippet = String,callback: callbackFunction = Function})
Execute a snippet of javascript code in the web runtime of the platform. The only param is an object which consists of the javascript snippet, the callback function, wait time and repeat times. The javascript snippet can be 'dom operation' and other operation.The callback function will receive the result of javascript snippet.It can only receive the results with String,Int format.
$action.RUNTIME.end()
The end of the runtime action.(required)
$task.execute([
$action.KEY
.up({
wait: 2000,
repeat: 2
})
.input({
name: "A",
code: 65
wait: 2000,
repeat: 2
})
.end(),
$action.RUNTIME
.execute({
wait: 2000,
repeat: 2,
script: "document.body.innerHTML('<div>Hello World</div>')",
callback: function(res){}
})
.end()
])
testSuite.run(function(results){})
Run the test suite. The only param is a callback function which will receive the results from the plugins
testSuite.run(function(results){
console.log(results)
/*{
"Initialization": [],
"Navigation": [],
"Automation": []
}*/
})
Demo
Repositories
Hubik-Plugin Hubik-Plugin-Memory Hubik-Plugin-Rendering Hubik-Plugin-Network