Skip to content
This repository was archived by the owner on Dec 13, 2023. It is now read-only.

Commit 93686bd

Browse files
author
Warner Johnson
authored
Merge pull request #18 from nickbouldien/add_livetest_example
Add livetest example
2 parents dc4cebf + 6765922 commit 93686bd

File tree

2 files changed

+84
-30
lines changed

2 files changed

+84
-30
lines changed

examples/liveTestResults.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
var cbt = require('cbt_tunnels');
2+
var request = require('request');
3+
4+
var authkey = ""; // Place CBT user credentials here
5+
var username = "";
6+
7+
var configObj = {
8+
authkey: authkey,
9+
username: username,
10+
}
11+
12+
var baseUrl = 'https://' + configObj.username + ':' + configObj.authkey + '@crossbrowsertesting.com/api/v3/';
13+
console.info("baseUrl: ", baseUrl);
14+
15+
// https://crossbrowsertesting.com/apidocs/v3/livetests.html#!/default/get_livetests
16+
17+
cbt.start(configObj, function(err) {
18+
if (err) {
19+
console.error("Error starting: ", err);
20+
return err;
21+
}
22+
var queryUrl = baseUrl + 'livetests?format=json&num=10&active=true&os_type=mac&browser_type=firefox';
23+
request.get({ url: queryUrl }, function(error, response, body) {
24+
if (error) {
25+
console.error("Error posting: ", error);
26+
return error;
27+
}
28+
29+
var livetests = JSON.parse(body).livetests;
30+
console.log("livetest count: ", livetests.length);
31+
32+
for (var test of livetests) {
33+
// do something
34+
}
35+
36+
cbt.stop();
37+
console.log('Exiting!');
38+
process.exit(0);
39+
});
40+
});

examples/screenshot_example.js

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,45 @@
1-
var request = require('request'),
2-
cbt = require('cbt_tunnels'),
3-
username = "", //Place CBT user credentials here
4-
authkey = "",
5-
url = 'https://'+username+':'+authkey+'@crossbrowsertesting.com/api/v3/screenshots?browsers=FF42&check_url=true&hide_fixed_elements=true&url=http:%2F%2Fwhatismyip.com',
6-
running = true;
1+
var cbt = require('cbt_tunnels');
2+
var request = require('request');
73

8-
cbt.start({'username': username,'authkey': authkey},function(err){
9-
if(!err){
10-
request.post({url: url}, function(error,response,body){
11-
if(!error){
12-
var areWeThereYet = setInterval(function(){
13-
request.get({url:'https://'+username+':'+authkey+'@crossbrowsertesting.com/api/v3/screenshots/'+JSON.parse(body).screenshot_test_id+'?format=json'},function(err,r,b){
14-
if(JSON.parse(b).versions[0].active==false){
15-
clearInterval(areWeThereYet);
16-
cbt.stop();
17-
console.log('Took screenshot!');
18-
process.exit(0);
19-
}else{
20-
console.log("Are we there yet?");
21-
}
22-
});
23-
},3000);
24-
}else{
25-
console.log(error);
26-
}
27-
});
28-
}else{
29-
console.log(username);
30-
}
31-
})
4+
var authkey = ""; // Place CBT user credentials here
5+
var username = "";
6+
7+
var configObj = {
8+
authkey: authkey,
9+
username: username,
10+
}
11+
12+
var baseUrl = 'https://' + configObj.username + ':' + configObj.authkey + '@crossbrowsertesting.com/api/v3/';
13+
console.info("baseUrl: ", baseUrl);
14+
15+
cbt.start(configObj, function(err) {
16+
if (err) {
17+
console.error("Error starting: ", err);
18+
return err;
19+
}
20+
var url = baseUrl + 'screenshots?browsers=FF42&check_url=true&hide_fixed_elements=true&url=http:%2F%2Fwhatismyip.com';
21+
request.post({ url: url }, function(error, response, body) {
22+
if (error) {
23+
console.error("Error posting: ", error);
24+
return error;
25+
}
26+
var screenshotTestUrl = baseUrl + 'screenshots/' + JSON.parse(body).screenshot_test_id + '?format=json';
27+
28+
var areWeThereYet = setInterval(function() {
29+
request.get({ url: screenshotTestUrl }, function(err, r, b) {
30+
if (err) {
31+
console.error("Error retrieving screenshot test data: ", err);
32+
return err;
33+
}
34+
if (!JSON.parse(b).versions[0].active) {
35+
clearInterval(areWeThereYet);
36+
cbt.stop();
37+
console.log('Took screenshot!');
38+
process.exit(0);
39+
} else {
40+
console.log("Are we there yet?");
41+
}
42+
});
43+
}, 3000);
44+
});
45+
});

0 commit comments

Comments
 (0)