aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorJohannes Zellner <johannes@nebulon.de>2016-03-03 11:00:33 +0100
committerJohannes Zellner <johannes@nebulon.de>2016-03-03 11:00:33 +0100
commit5158ef8387f4c05ba220b75cbfe29adb4dfaf7fe (patch)
treedf7411b39e5515b226e17c2d7cf8163c8e027fbb /test
parent5d6aed10eb7fbec782f621dcd31b4fbc59e95c07 (diff)
downloadSurfer-5158ef8387f4c05ba220b75cbfe29adb4dfaf7fe.tar.gz
Surfer-5158ef8387f4c05ba220b75cbfe29adb4dfaf7fe.tar.zst
Surfer-5158ef8387f4c05ba220b75cbfe29adb4dfaf7fe.zip
Add selenium tests
Diffstat (limited to 'test')
-rw-r--r--[-rwxr-xr-x]test/test.js164
1 files changed, 131 insertions, 33 deletions
diff --git a/test/test.js b/test/test.js
index fe6ff61..8b1bcdc 100755..100644
--- a/test/test.js
+++ b/test/test.js
@@ -4,37 +4,127 @@
4 4
5var execSync = require('child_process').execSync, 5var execSync = require('child_process').execSync,
6 expect = require('expect.js'), 6 expect = require('expect.js'),
7 fs = require('fs'),
8 os = require('os'),
9 path = require('path'), 7 path = require('path'),
10 superagent = require('superagent'); 8 fs = require('fs'),
9 superagent = require('superagent'),
10 webdriver = require('selenium-webdriver');
11
12var by = webdriver.By,
13 Keys = webdriver.Key,
14 until = webdriver.until;
11 15
12process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; 16process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
13 17
18if (!process.env.USERNAME || !process.env.PASSWORD) {
19 console.log('USERNAME and PASSWORD env vars need to be set');
20 process.exit(1);
21}
22
14describe('Application life cycle test', function () { 23describe('Application life cycle test', function () {
15 this.timeout(0); 24 this.timeout(0);
16 var LOCATION = 'surfertest'; 25
17 var app, testFile = os.tmpdir() + '/surfer-test.txt'; 26 var firefox = require('selenium-webdriver/firefox');
18 var username = process.env.USERNAME; 27 var server, browser = new firefox.Driver();
19 var password = process.env.PASSWORD;
20 28
21 before(function (done) { 29 before(function (done) {
22 if (!process.env.USERNAME) return done(new Error('USERNAME env var not set')); 30 var seleniumJar= require('selenium-server-standalone-jar');
23 if (!process.env.PASSWORD) return done(new Error('PASSWORD env var not set')); 31 var SeleniumServer = require('selenium-webdriver/remote').SeleniumServer;
32 server = new SeleniumServer(seleniumJar.path, { port: 4444 });
33 server.start();
24 34
25 done(); 35 done();
26 }); 36 });
27 37
28 after(function (done) { 38 after(function (done) {
39 browser.quit();
40 server.stop();
29 done(); 41 done();
30 }); 42 });
31 43
44 var LOCATION = 'rctest';
45 var TEST_TIMEOUT = 10000;
46 var TEST_FILE_NAME_0 = 'index.html';
47 var TEST_FILE_NAME_1 = 'test.txt';
48 var app;
49
50 // tests which are used more than once
51 function login(done) {
52 browser.manage().deleteAllCookies();
53 browser.get('https://' + app.fqdn + '/_admin');
54
55 browser.wait(until.elementLocated(by.id('inputUsername')), TEST_TIMEOUT).then(function () {
56 browser.wait(until.elementIsVisible(browser.findElement(by.id('inputUsername'))), TEST_TIMEOUT).then(function () {
57 browser.findElement(by.id('inputUsername')).sendKeys(process.env.USERNAME);
58 browser.findElement(by.id('inputPassword')).sendKeys(process.env.PASSWORD);
59 browser.findElement(by.id('loginForm')).submit();
60
61 browser.wait(until.elementIsVisible(browser.findElement(by.id('logoutButton'))), TEST_TIMEOUT).then(function () {
62 done();
63 });
64 });
65 });
66 }
67
68 function logout(done) {
69 browser.get('https://' + app.fqdn + '/_admin');
70
71 browser.wait(until.elementLocated(by.id('logoutButton')), TEST_TIMEOUT).then(function () {
72 browser.wait(until.elementIsVisible(browser.findElement(by.id('logoutButton'))), TEST_TIMEOUT).then(function () {
73 browser.findElement(by.id('logoutButton')).click();
74
75 browser.wait(until.elementIsVisible(browser.findElement(by.id('inputPassword'))), TEST_TIMEOUT).then(function () {
76 done();
77 });
78 });
79 });
80 }
81
82 function checkFileIsListed(name, done) {
83 browser.get('https://' + app.fqdn + '/_admin');
84
85 browser.wait(until.elementLocated(by.xpath('//*[text()="' + name + '"]')), TEST_TIMEOUT).then(function () {
86 done();
87 });
88 }
89
90 function checkFileIsPresent(done) {
91 browser.get('https://' + app.fqdn + '/' + TEST_FILE_NAME_0);
92
93 browser.wait(until.elementLocated(by.xpath('//*[text()="test"]')), TEST_TIMEOUT).then(function () {
94 done();
95 });
96 }
97
98 function checkIndexFileIsServedUp(done) {
99 browser.get('https://' + app.fqdn);
100
101 browser.wait(until.elementLocated(by.xpath('//*[text()="test"]')), TEST_TIMEOUT).then(function () {
102 done();
103 });
104 }
105
106 function checkFileIsGone(name, done) {
107 superagent.get('https://' + app.fqdn + '/' + name).end(function (error, result) {
108 expect(error).to.be.an('object');
109 expect(result.statusCode).to.equal(404);
110 done();
111 });
112 }
113
114 function uploadFile(name, done) {
115 // File upload can't be tested with selenium, since the file input is not visible and thus can't be interacted with :-(
116
117 fs.writeFileSync(process.env.HOME + '/.surfer.json', JSON.stringify({ server: 'https://' + app.fqdn, username: process.env.USERNAME, password: process.env.PASSWORD }));
118 execSync(path.join(__dirname, '/../cli/surfer.js') + ' put ' + path.join(__dirname, name), { stdio: 'inherit' } );
119 done();
120 }
121
32 it('build app', function () { 122 it('build app', function () {
33 execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); 123 execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
34 }); 124 });
35 125
36 it('install app', function () { 126 it('install app', function () {
37 execSync('cloudron install --new --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); 127 execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
38 }); 128 });
39 129
40 it('can get app information', function () { 130 it('can get app information', function () {
@@ -45,25 +135,20 @@ describe('Application life cycle test', function () {
45 expect(app).to.be.an('object'); 135 expect(app).to.be.an('object');
46 }); 136 });
47 137
48 it('can get the main page', function (done) { 138 it('can login', login);
49 superagent.get('https://' + app.fqdn).end(function (error, result) { 139 it('can upload file', uploadFile.bind(null, TEST_FILE_NAME_0));
50 expect(error).to.be(null); 140 it('file is listed', checkFileIsListed.bind(null, TEST_FILE_NAME_0));
51 expect(result.status).to.eql(200); 141 it('file is served up', checkFileIsPresent);
52 142 it('file is served up', checkIndexFileIsServedUp);
53 done(); 143 it('can upload second file', uploadFile.bind(null, TEST_FILE_NAME_1));
54 }); 144 it('file is listed', checkFileIsListed.bind(null, TEST_FILE_NAME_1));
55 }); 145 it('can delete second file with cli', function (done) {
56 146 fs.writeFileSync(process.env.HOME + '/.surfer.json', JSON.stringify({ server: 'https://' + app.fqdn, username: process.env.USERNAME, password: process.env.PASSWORD }));
57 it('can login using cli', function () { 147 execSync(path.join(__dirname, '/../cli/surfer.js') + ' del ' + TEST_FILE_NAME_1, { stdio: 'inherit' } );
58 // execSync(__dirname + '/../cli/surfer.js login https://' + app.fqdn, { input: username + '\n' + password + '\n' });
59 fs.writeFileSync(process.env.HOME + '/.surfer.json', JSON.stringify({ server: 'https://' + app.fqdn, username: username, password: password }));
60 });
61
62 it('can upload file', function (done) {
63 fs.writeFileSync(testFile, 'surfer');
64 execSync(__dirname + '/../cli/surfer.js put ' + testFile, { stdio: 'inherit' } );
65 done(); 148 done();
66 }); 149 });
150 it('second file is gone', checkFileIsGone.bind(null, TEST_FILE_NAME_1));
151 it('can logout', logout);
67 152
68 it('backup app', function () { 153 it('backup app', function () {
69 execSync('cloudron backup --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); 154 execSync('cloudron backup --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
@@ -73,15 +158,28 @@ describe('Application life cycle test', function () {
73 execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); 158 execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
74 }); 159 });
75 160
76 it('can get the uploaded file', function (done) { 161 it('can login', login);
77 var contents = execSync(__dirname + '/../cli/surfer.js get surfer-test.txt').toString('utf8'); 162 it('file is listed', checkFileIsListed.bind(null, TEST_FILE_NAME_0));
78 expect(contents).to.be('surfer'); 163 it('file is served up', checkFileIsPresent);
79 done(); 164 it('file is served up', checkIndexFileIsServedUp);
165 it('second file is still gone', checkFileIsGone.bind(null, TEST_FILE_NAME_1));
166 it('can logout', logout);
167
168 it('move to different location', function () {
169 browser.manage().deleteAllCookies();
170 execSync('cloudron install --location ' + LOCATION + '2', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
171 var inspect = JSON.parse(execSync('cloudron inspect'));
172 app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0];
173 expect(app).to.be.an('object');
80 }); 174 });
81 175
176 it('can login', login);
177 it('file is listed', checkFileIsListed.bind(null, TEST_FILE_NAME_0));
178 it('file is served up', checkFileIsPresent);
179 it('file is served up', checkIndexFileIsServedUp);
180 it('can logout', logout);
181
82 it('uninstall app', function () { 182 it('uninstall app', function () {
83 execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' }); 183 execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
84 fs.unlinkSync(process.env.HOME + '/.surfer.json');
85 fs.unlinkSync(testFile);
86 }); 184 });
87}); 185});