Skip to content

Commit d3fbd05

Browse files
author
Wenjun Che
committed
RUN-633: init check-in
0 parents  commit d3fbd05

File tree

7 files changed

+515
-0
lines changed

7 files changed

+515
-0
lines changed

.gitignore

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Created by .gitignore support plugin (hsz.mobi)
2+
### Node template
3+
# Logs
4+
logs
5+
*.log
6+
7+
# Runtime data
8+
pids
9+
*.pid
10+
*.seed
11+
12+
# Directory for instrumented libs generated by jscoverage/JSCover
13+
lib-cov
14+
15+
# Coverage directory used by tools like istanbul
16+
coverage
17+
18+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
19+
.grunt
20+
21+
# Compiled binary addons (http://nodejs.org/api/addons.html)
22+
build/Release
23+
24+
# Dependency directory
25+
# Commenting this out is preferred by some people, see
26+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
27+
node_modules
28+
29+
# Users Environment Variables
30+
.lock-wscript
31+
32+
# IDEA
33+
*.iml
34+
.idea/**
35+

Gruntfile.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Before running, make sure to do:
3+
* - npm install
4+
* - npm install -g grunt-cli
5+
*
6+
* TASKS:
7+
* grunt - runs Mocha tests (default task)
8+
*/
9+
10+
'use strict';
11+
12+
module.exports = function(grunt) {
13+
var tests = ['test/**/*.js'];
14+
15+
require('load-grunt-tasks')(grunt); // load all grunt modules
16+
17+
grunt.initConfig({
18+
watch: {
19+
files: tests,
20+
options: {
21+
spawn: false,
22+
event: ['added', 'changed']
23+
}
24+
},
25+
mochaTest: {
26+
test: {
27+
options: {
28+
reporter: 'spec',
29+
clearRequireCache: true
30+
},
31+
src: tests
32+
}
33+
}
34+
});
35+
36+
grunt.registerTask('default', 'mochaTest');
37+
38+
};

package.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "hello-openfin-selenium",
3+
"version": "0.0.0",
4+
"private": true,
5+
"scripts": {
6+
"start": "node ./bin/www"
7+
},
8+
"dependencies": {
9+
"express": "~4.9.0",
10+
"body-parser": "~1.8.1",
11+
"cookie-parser": "~1.3.3",
12+
"morgan": "~1.3.0",
13+
"serve-favicon": "~2.1.3",
14+
"debug": "~2.0.0",
15+
"jade": "~1.6.0"
16+
}
17+
}

test/WD/Mocha/hello-openfin.js

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
*
3+
* Example test script for Hello OpenFin App using Mocha, CHAI and Wd (http://admc.io/wd/)
4+
*
5+
*/
6+
7+
"use strict";
8+
9+
var url = require('url');
10+
var chaiAsPromised = require("chai-as-promised");
11+
var chai = require('chai');
12+
chai.use(chaiAsPromised);
13+
var should = chai.should();
14+
15+
var wd = require('wd');
16+
// enables chai assertion chaining
17+
chaiAsPromised.transferPromiseness = wd.transferPromiseness;
18+
19+
var config = require("../../tests_config");
20+
21+
22+
describe('Hello OpenFin App testing', function() {
23+
var client, notificationButton, cpuInfoButton, cpuInfoExitButton;
24+
25+
this.timeout(config.testTimeout);
26+
27+
before(function() {
28+
client = wd.promiseChainRemote(url.parse("http://10.211.55.4:9515"));
29+
30+
// client = wd.remote(url.parse(config.driverServerUrl));
31+
return client.init({
32+
browserName: 'chrome',
33+
'chromeOptions': {
34+
args: [],
35+
extensions: [],
36+
debuggerAddress: 'localhost:9090'
37+
}
38+
});
39+
});
40+
41+
after(function(done) {
42+
// needs "done" here to give time to run .quit()
43+
setTimeout(function() {
44+
client.quit(function() {
45+
done();
46+
});
47+
}, 2000);
48+
});
49+
50+
function switchWindow(windowHandle, callback) {
51+
client.window(windowHandle, function(err) {
52+
should.not.exist(err);
53+
client.title(function (err, result) {
54+
should.not.exist(err);
55+
callback(result);
56+
});
57+
});
58+
}
59+
60+
function switchWindowByTitle(windowTitle, done) {
61+
client.windowHandles(function(err, handles) {
62+
should.not.exist(err);
63+
var handleIndex = 0;
64+
var checkTitle = function (title) {
65+
if (title === windowTitle) {
66+
done();
67+
} else {
68+
handleIndex++;
69+
if (handleIndex < handles.length) {
70+
switchWindow(handles[handleIndex], checkTitle);
71+
} else {
72+
throw new Error("Window not found " + title);
73+
}
74+
}
75+
};
76+
switchWindow(handles[handleIndex], checkTitle);
77+
});
78+
}
79+
80+
it('Switch to Hello OpenFin Main window', function(done) {
81+
should.exist(client);
82+
switchWindowByTitle("Hello OpenFin", done);
83+
});
84+
85+
86+
it("Click notification button", function() {
87+
should.exist(client);
88+
client.elementByCss("#desktop-notification").click();
89+
});
90+
91+
it("Click CPU Info button", function(done) {
92+
should.exist(client);
93+
client.elementByCss("#cpu-info").click();
94+
client.sleep(3000, function(err) {
95+
done();
96+
});
97+
});
98+
99+
100+
it('Switch to CPU Info window', function(done) {
101+
should.exist(client);
102+
switchWindowByTitle("Hello OpenFin CPU Info", done);
103+
});
104+
105+
106+
it("Click CPU Info Exit button", function() {
107+
should.exist(client);
108+
client.elementByCss("#close-app").click();
109+
});
110+
111+
112+
});
+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/**
2+
*
3+
* Example test script for Hello OpenFin App using Mocha, CHAI and WebdriverIO (http://webdriver.io)
4+
*
5+
* wedriver.io assumes server URL is /wd/hub. So if testing with chromedriver directly, it needs to run as
6+
* chromedriver --url-base=/wd/hub
7+
*
8+
*/
9+
10+
"use strict";
11+
12+
var should = require('chai').should(),
13+
webdriver = require('webdriverio'),
14+
assert = require("assert"),
15+
config = require("../../tests_config");
16+
17+
18+
describe('Hello OpenFin App testing', function() {
19+
var client, notificationButton, cpuInfoButton, cpuInfoExitButton;
20+
21+
this.timeout(config.testTimeout);
22+
23+
before(function() {
24+
var driverOptions = {
25+
desiredCapabilities: {
26+
browserName: 'chrome',
27+
'chromeOptions': {
28+
args: [],
29+
extensions: [],
30+
debuggerAddress: 'localhost:9090'
31+
}
32+
},
33+
host: '10.211.55.4',
34+
port: 9515,
35+
logLevel: 'debug'
36+
};
37+
client = webdriver.remote(driverOptions).init();
38+
});
39+
40+
after(function(done) {
41+
// needs "done" here to give time to run .end()
42+
client.end(function() {
43+
done();
44+
});
45+
});
46+
47+
it('Switch to Hello OpenFin Main window', function(done) {
48+
should.exist(client);
49+
client.getTabIds(function(result) {
50+
done();
51+
});
52+
});
53+
54+
55+
function switchWindow(windowHandle, callback) {
56+
client.switchTab(windowHandle, function(err) {
57+
should.not.exist(err);
58+
client.title(function (err, result) {
59+
should.not.exist(err);
60+
callback(result.value);
61+
});
62+
});
63+
}
64+
65+
function switchWindowByTitle(windowTitle, done) {
66+
client.getTabIds(function(err, handles) {
67+
should.not.exist(err);
68+
var handleIndex = 0;
69+
var checkTitle = function (title) {
70+
if (title === windowTitle) {
71+
done();
72+
} else {
73+
handleIndex++;
74+
if (handleIndex < handles.length) {
75+
switchWindow(handles[handleIndex], checkTitle);
76+
} else {
77+
throw new Error("Window not found " + title);
78+
}
79+
}
80+
};
81+
switchWindow(handles[handleIndex], checkTitle);
82+
});
83+
}
84+
85+
it('Switch to Hello OpenFin Main window', function(done) {
86+
should.exist(client);
87+
switchWindowByTitle("Hello OpenFin", done);
88+
});
89+
90+
91+
it("Find notification button", function(done) {
92+
should.exist(client);
93+
client.element("#desktop-notification", function(err, result) {
94+
should.not.exist(err);
95+
should.exist(result.value);
96+
notificationButton = result.value;
97+
done();
98+
});
99+
});
100+
101+
it("Click notification button", function(done) {
102+
should.exist(client);
103+
should.exist(notificationButton);
104+
client.elementIdClick(notificationButton.ELEMENT, function(err, result) {
105+
should.not.exist(err);
106+
done();
107+
});
108+
});
109+
110+
111+
it("Find CPU Info button", function(done) {
112+
should.exist(client);
113+
client.element("#cpu-info", function(err, result) {
114+
should.not.exist(err);
115+
should.exist(result.value);
116+
cpuInfoButton = result.value;
117+
done();
118+
});
119+
});
120+
121+
it("Click CPU Info button", function(done) {
122+
should.exist(client);
123+
should.exist(cpuInfoButton);
124+
client.elementIdClick(cpuInfoButton.ELEMENT, function(err, result) {
125+
should.not.exist(err);
126+
client.pause(3000, function() {
127+
done();
128+
});
129+
})
130+
});
131+
132+
it('Switch to CPU Info window', function(done) {
133+
should.exist(client);
134+
switchWindowByTitle("Hello OpenFin CPU Info", done);
135+
});
136+
137+
138+
it("Find Exit button for CPU Info window", function(done) {
139+
should.exist(client);
140+
client.element("#close-app", function(err, result) {
141+
should.not.exist(err);
142+
should.exist(result.value);
143+
cpuInfoExitButton = result.value;
144+
done();
145+
});
146+
147+
148+
});
149+
150+
it("Click CPU Info Exit button", function(done) {
151+
should.exist(client);
152+
should.exist(cpuInfoExitButton);
153+
client.elementIdClick(cpuInfoExitButton.ELEMENT, function(err, result) {
154+
should.not.exist(err);
155+
done();
156+
})
157+
});
158+
159+
160+
161+
});

0 commit comments

Comments
 (0)