-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
96 lines (73 loc) · 2.34 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
var gulp = require('gulp');
var opine = require('gulp-opine');
var gutil = require('gulp-util');
var webdriver = require('gulp-webdriver');
var del = require('del');
var module = opine.module('browsertest');
var minimist = require('minimist');
var screenshots = require('./screenshots');
var knownOptions = {
string: 'cap',
default: { cap: null }
};
var options = minimist(process.argv.slice(2), knownOptions);
var wdioConfig = module.getConfig('wdio', {});
function loadBrowserstackAuthDetails() {
gutil.log('Loading browsers stack access details');
var browserstackConfig = module.getConfig('browserstack', {
'username': process.env.BROWSERSTACK_USERNAME,
'accesskey': process.env.BROWSERSTACK_ACCESS_KEY
});
process.env.BROWSERSTACK_USERNAME = browserstackConfig.username;
process.env.BROWSERSTACK_ACCESS_KEY = browserstackConfig.accesskey;
gutil.log(
'Usgin browsersstack user',
gutil.colors.magenta(browserstackConfig.username)
);
}
function loadCapabities() {
gutil.log('Loading browsers capabilities');
var capabilities = wdioConfig.capabilities;
if(options.cap) {
// leave in capabilitied only selected
capabilities = capabilities.filter(function(obj){
return obj.browserName.toLowerCase() === options.cap.toLowerCase();
});
}
if(capabilities.length === 0) {
throw new gutil.PluginError({
plugin: 'browsertest',
message: 'Capability "' + options.cap + '" not found'
});
}
process.env.WDIO_CAPABILITIES = JSON.stringify(capabilities);
return capabilities;
}
module.task(function() {
gutil.log('Sit back and relax...');
loadBrowserstackAuthDetails();
loadCapabities();
gutil.log('Clean output folder');
del.sync(module.getConfig('outputPath', './test/output'));
gutil.log(
'Launching tests. Check',
gutil.colors.cyan('https://www.browserstack.com/automate')
);
return gulp
.src('wdio.conf.js')
.pipe(webdriver(wdioConfig));
});
// It integrates with screenshots api. It creates amazing screenshots
// full page with no extra coding
gulp.task('browsertest-screenshots', function() {
loadBrowserstackAuthDetails();
gutil.log('Clean output folder');
del.sync(module.getConfig('outputPath', './test/output'));
return screenshots(
module.getConfig('screenshots', {
'base': null,
'urls': []
}),
loadCapabities()
);
});