Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit a321c57

Browse files
committed
Update
0 parents  commit a321c57

7 files changed

Lines changed: 583 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea
2+
node_modules
3+
benchmark

Gruntfile.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = function (grunt) {
2+
grunt.initConfig({
3+
nodeunit: {
4+
all: ['./test/*.test.js']
5+
}
6+
});
7+
8+
grunt.loadNpmTasks('grunt-contrib-nodeunit');
9+
};

README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
TestCafe RPC
2+
======
3+
RPC library for the [TestCafé](http://testcafe.devexpress.com/). It allows you to create a single TestCafé instance and then interact with it programmatically from any machine in your network.
4+
5+
6+
Install
7+
-------
8+
```
9+
$ npm install testcafe-rpc
10+
```
11+
12+
Running a server
13+
-------------
14+
```js
15+
var TestCafeRemote = require('testcafe-rpc');
16+
17+
//Options for TestCafé instance
18+
var opt = {
19+
controlPanelPort: 1337,
20+
servicePort: 1338,
21+
testsDir: 'YOUR_TESTS_DIR',
22+
browsers: {
23+
'Mozilla Firefox': {
24+
path: "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe",
25+
icon: "ff",
26+
cmd: "-new-window"
27+
}
28+
}
29+
},
30+
rpcPort = 1339;
31+
32+
//Create TestCafé server instance with given options which can be accessed via RPC on port 1339.
33+
var testCafeServer = new TestCafeRemote.Server(opt, rpcPort);
34+
35+
//Returned object exposes standard TestCafé API, so you can use it as a regular TestCafé instance.
36+
testCafeServer.runTests({ browsers: testCafeServer.listAvailableBrowsers() }, function (errors, taskUid, workers) {
37+
//do smthg...
38+
});
39+
```
40+
41+
Running a client
42+
-------------
43+
```js
44+
var TestCafeRemote = require('testcafe-rpc');
45+
46+
var rpcHostname = 'myhostname',
47+
rpcPort = 1339;
48+
49+
//Connect to the existent TestCafé server (if you running both client and server on the same machine
50+
//hostname-parameter can be ommited).
51+
var testCafeClient = new TestCafeRemote.Client(rpcPort, rpcHostname);
52+
53+
//Client can be used as a regular TestCafé instance with exception that listAvailableBrowsers() and listConnectedWorkers()
54+
//are asynchronous methods.
55+
testCafeClient.listAvailableBrowsers(function(browsers) {
56+
testCafeClient.runTests({ browsers: browsers }, function (errors, taskUid, workers) {
57+
//do smthg...
58+
});
59+
});
60+
```
61+
Need more help to get started?
62+
--------------
63+
Visit TestCafé [Continuous integration guide](http://testcafe.devexpress.com/Documentation/Tutorial/Continuous_Integration) and [Continuous integration API reference](http://testcafe.devexpress.com/Documentation/ApiReference/Continuous_Integration_API_Reference). If you have any additional questions or suggestions don't hesitate to ask using [DevExpress Support Center](http://www.devexpress.com/Support/Center/Question/ChangeFilterSet/1?FavoritesOnly=False&MyItemsOnly=False&MyTeamItemsOnly=False&TechnologyName=Testing+Tools&PlatformName=AllPlatforms&ProductName=AllProducts&TicketType=All).
64+
65+
License
66+
----------
67+
Copyright (c) 2013 DevExpress (www.devexpress.com)
68+
69+
Permission is hereby granted, free of charge, to any person obtaining a copy
70+
of this software and associated documentation files (the "Software"), to deal
71+
in the Software without restriction, including without limitation the rights
72+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
73+
copies of the Software, and to permit persons to whom the Software is
74+
furnished to do so, subject to the following conditions:
75+
76+
The above copyright notice and this permission notice shall be included in
77+
all copies or substantial portions of the Software.
78+
79+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
80+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
81+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
82+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
83+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
84+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
85+
THE SOFTWARE.
86+
87+

index.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
var dnode = require('dnode'),
2+
TestCafe = require('testcafe').TestCafe;
3+
4+
exports.Server = function (cfg, port) {
5+
var testCafe = new TestCafe(cfg);
6+
7+
var d = dnode({
8+
on: function (evtName, callback) {
9+
testCafe.on(evtName, callback);
10+
},
11+
12+
listAvailableBrowsers: function (callback) {
13+
callback(testCafe.listAvailableBrowsers());
14+
},
15+
16+
listConnectedWorkers: function (callback) {
17+
callback(testCafe.listConnectedWorkers());
18+
},
19+
20+
listDirectory: testCafe.listDirectory.bind(testCafe),
21+
runTests: testCafe.runTests.bind(testCafe)
22+
}).listen(port);
23+
24+
d.on('error', function () {
25+
testCafe.emit('remoteError');
26+
});
27+
28+
d.on('fail', function () {
29+
testCafe.emit('remoteFail');
30+
});
31+
32+
var close = testCafe.close;
33+
34+
testCafe.close = function () {
35+
d.close();
36+
close.apply(testCafe);
37+
};
38+
39+
return testCafe;
40+
};
41+
42+
var Client = exports.Client = function (serverPort, serverHostname) {
43+
this.serverPort = serverPort;
44+
this.serverHostname = serverHostname;
45+
};
46+
47+
Client.prototype._rpc = function (methodName, args, callback, isEvent) {
48+
var d = dnode.connect(this.serverPort, this.serverHostname).on('remote', function (remote) {
49+
args.push(function () {
50+
callback.apply(null, arguments);
51+
52+
if (!isEvent)
53+
d.end();
54+
});
55+
56+
remote[methodName].apply(remote, args);
57+
});
58+
};
59+
60+
Client.prototype.listAvailableBrowsers = function (callback) {
61+
this._rpc('listAvailableBrowsers', [], callback, false);
62+
};
63+
64+
Client.prototype.listConnectedWorkers = function (callback) {
65+
this._rpc('listConnectedWorkers', [], callback, false);
66+
};
67+
68+
Client.prototype.listDirectory = function (path, callback) {
69+
this._rpc('listDirectory', [path], callback, false);
70+
};
71+
72+
Client.prototype.runTests = function (options, callback) {
73+
this._rpc('runTests', [options], callback, false);
74+
};
75+
76+
Client.prototype.on = function (evtName, handler) {
77+
this._rpc('on', [evtName], handler, true);
78+
};
79+

package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "testcafe-rpc",
3+
"author": "DevExpress (www.devexpress.com)",
4+
"version": "0.5.0",
5+
"keywords": [
6+
"TestCafe",
7+
"RPC",
8+
"remoting",
9+
"remote",
10+
"testing",
11+
"functional"
12+
],
13+
"main": "./index.js",
14+
15+
"dependencies": {
16+
"dnode": "~1.0.5",
17+
"testcafe": "~13.1.1"
18+
},
19+
"devDependencies": {
20+
"grunt": "~0.4.1",
21+
"grunt-contrib-nodeunit": "~0.2.0",
22+
"node-phantom": "~0.2.3",
23+
"phantomjs": "~1.9.2-0"
24+
}
25+
}

0 commit comments

Comments
 (0)