-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnew_feature_public.js
110 lines (91 loc) · 4.03 KB
/
new_feature_public.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var helper = require('./module/helper.js');
var cst = require('./module/utils.js');
var paramSingleBuild = require('./data/single_build.json');
var paramBuilds = require('./data/builds.json');
describe('New feature public', function () {
var reportFolder = 'target/new-feature-public-builds/';
var screenshots;
var countPassed = 0;
var countFailed = 0;
var builds = 'https://g-staging.codefresh.io/public/{0}/{1}/{2}/builds';
var singleBuild = 'https://g-staging.codefresh.io/public/{0}/{1}/{2}/builds/build/{3}';
beforeEach(function() {
constant = new cst.Constant();
browser.driver.ignoreSynchronization = true;
});
afterEach(function () {
});
afterAll(function () {
console.log('TOTAL: PASSED = '+ countPassed +'; FAILED = ' + countFailed);
});
it('Check single build', function () {
console.log('########### ########## Start test ########### ##########');
var accounts = paramSingleBuild.accounts;
var urlTemplate = singleBuild;
screenshots = reportFolder + 'single_build/';
accounts.forEach(function (item, i, items) {
checkSingleBuild(item.accountName, item.repositories, urlTemplate);
});
// console.log('########### ########## End test ########### ##########');
});
it('Check builds', function () {
console.log('########### ########## Start test ########### ##########');
var accounts = paramBuilds.accounts;
var urlTemplate = builds;
screenshots = reportFolder + 'builds/';
accounts.forEach(function (item, i, items) {
checkPublicRepositories(item.accountName, item.repositories, urlTemplate);
});
});
var checkSingleBuild = function (accountName, repos, urlTemplate) {
repos.forEach(function (item, i, items) {
var url = helper.format(urlTemplate, accountName, item.repoOwner, item.repoName, item.buildid);
var scrFilename = accountName + '_' + item.repoName + '_' + item.buildid + '.png';
loadPage(accountName, item, url, scrFilename, i, constant.XPATH_PUBLIC_SINGLE_BUILD);
});
};
var checkPublicRepositories = function (accountName, repos, urlTemplate) {
repos.forEach(function (item, i, items) {
var url = helper.format(urlTemplate, accountName, item.repoOwner, item.repoName);
var scrFilename = accountName+'_' + item.repoName + '.png';
loadPage(accountName, item, url, scrFilename, i, constant.XPATH_PUBLIC_BUILD);
});
};
var loadPage = function (accountName, item, url, scrFilename, indexTest, xpathEl) {
browser.driver.get(url).then(function() {
browser.driver.wait(function() {
return browser.driver.isElementPresent(by.xpath(xpathEl));
}, 10000).then(
function () {
helper.sleep(1000);
helper.takeScreenshot(scrFilename, screenshots);
var result = 'FAILED';
if(item.status == 1) {
result = 'PASSED';
countPassed++;
} else {
result = 'FAILED';
countFailed++;
}
printTestResult(indexTest, result, url);
}, function() {
helper.sleep(1000);
helper.takeScreenshot(scrFilename, screenshots);
var result = 'FAILED';
if(item.status == 1) {
result = 'FAILED';
countFailed++;
} else {
result = 'PASSED';
countPassed++;
}
printTestResult(indexTest, result, url);
});
});
};
var printTestResult = function (indexTest, result, message) {
console.log('------ Test ' + indexTest + ' ' + result + ' -----');
console.log(message);
console.log('');
};
});