Skip to content
This repository was archived by the owner on Feb 25, 2026. It is now read-only.

Commit ede7e83

Browse files
committed
Merge pull request #427 from isabelrios/ui_app_test
first try for test to open the webapp
2 parents ecc92fa + 4440a33 commit ede7e83

12 files changed

Lines changed: 239 additions & 3 deletions

File tree

test/selenium/app_test.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use strict';
2+
3+
var Prepper = require('./lib/testPrepperSelenium.js');
4+
var webdriver = require('selenium-webdriver');
5+
6+
var HOST_URL = 'https://fxbox.github.io/app';
7+
8+
var SetUpWebapp = require('./lib/setup_webapp.js');
9+
var webAppMainPage;
10+
var setUpWebapp;
11+
12+
Prepper.makeSuite('Test to open web app', function() {
13+
14+
describe('UI app', function() {
15+
var driver;
16+
this.timeout(10000);
17+
18+
const PASSWORD = '12345678';
19+
20+
before(function() {
21+
driver = new webdriver.Builder().
22+
forBrowser('firefox').
23+
build();
24+
});
25+
26+
beforeEach(function() {
27+
driver.get(HOST_URL);
28+
});
29+
30+
after(function() {
31+
driver.quit();
32+
});
33+
34+
describe('open the web app', function() {
35+
36+
beforeEach(function() {
37+
setUpWebapp = new SetUpWebapp(driver);
38+
webAppMainPage = setUpWebapp.getAppMainView();
39+
return webAppMainPage;
40+
});
41+
42+
it('should log in from web app', function() {
43+
return webAppMainPage.connectToFoxBox().then((setUpView) => {
44+
setUpView.successSignUpFromApp(PASSWORD);
45+
});
46+
});
47+
});
48+
});
49+
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict';
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
const spawn = require('child_process').spawn;
6+
7+
var FOXBOX_STARTUP_WAIT_TIME_IN_MS = 5000;
8+
var foxboxInstance;
9+
10+
var helper = (function() {
11+
12+
function _removeFileIfItExists(filename,errMsg) {
13+
try {
14+
fs.unlinkSync(path.join(process.env.HOME,
15+
filename));
16+
} catch (e) {
17+
if (e.code === 'ENOENT') {
18+
console.log(errMsg);
19+
}
20+
}
21+
}
22+
23+
function removeUsersDB() {
24+
_removeFileIfItExists('/.local/share/foxbox-debug/users_db.sqlite',
25+
'User DB not found!');
26+
}
27+
28+
function fullOptionStart(callback) {
29+
foxboxInstance = spawn('./target/debug/foxbox',
30+
['-c',
31+
'--disable-tls']);
32+
setTimeout(callback, FOXBOX_STARTUP_WAIT_TIME_IN_MS);
33+
}
34+
35+
function killFoxBox() {
36+
foxboxInstance.kill('SIGINT');
37+
}
38+
39+
return {
40+
removeUsersDB, fullOptionStart, killFoxBox,
41+
};
42+
})();
43+
44+
module.exports = helper;

test/selenium/lib/setup_webapp.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,23 @@
22

33
var SignedInPageView = require('./view/signed_in/view.js');
44
var SetUpView = require('./view/sign_up/view.js');
5+
var MainView = require('./view/app_main/view.js');
56

67
function SetUpWebapp(driver) {
78
this.driver = driver;
89
}
910

1011
SetUpWebapp.prototype = {
1112
getSignInPage : function() {
12-
return new SignedInPageView(this.driver);
13+
return new SignedInPageView(this.driver);
1314
},
1415

1516
getSetUpView : function() {
16-
return new SetUpView(this.driver);
17+
return new SetUpView(this.driver);
18+
},
19+
20+
getAppMainView : function() {
21+
return new MainView(this.driver);
1722
}
1823
};
1924

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
var foxboxManager = require('./foxboxHelperSelenium.js');
4+
5+
var testPrepperSelenium = (function() {
6+
7+
function beforeTest(done) {
8+
9+
console.log('test started');
10+
foxboxManager.fullOptionStart(done);
11+
}
12+
13+
function makeSuite(desc, test) {
14+
describe(desc, function () {
15+
this.timeout(5000000);
16+
before(beforeTest);
17+
test();
18+
after(function() {
19+
foxboxManager.killFoxBox();
20+
foxboxManager.removeUsersDB();
21+
});
22+
});
23+
}
24+
25+
return { makeSuite, foxboxManager};
26+
})();
27+
28+
module.exports = testPrepperSelenium;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var until = require('selenium-webdriver').until;
2+
3+
function Accessors(driver) {
4+
this.driver = driver;
5+
}
6+
7+
Accessors.prototype = {
8+
waitForElement: function(locator) {
9+
var element = this.driver.wait(until.elementLocated(locator));
10+
return this.driver.wait(until.elementIsVisible(element));
11+
}
12+
13+
};
14+
15+
module.exports = Accessors;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var By = require('selenium-webdriver').By;
2+
var Accessors = require('../accessors');
3+
4+
5+
function MainAccessors() {
6+
Accessors.apply(this, arguments);
7+
}
8+
9+
MainAccessors.prototype = Object.assign({
10+
11+
get connectToFoxBoxButton() {
12+
return this.waitForElement(By.css('.user-login__login-button'));
13+
}
14+
15+
}, Accessors.prototype);
16+
17+
module.exports = MainAccessors;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var View = require('../view');
2+
var MainAccessors = require('./accessors');
3+
4+
5+
function MainView() {
6+
[].push.call(arguments, MainAccessors);
7+
View.apply(this, arguments);
8+
9+
this.accessors.connectToFoxBoxButton;
10+
}
11+
12+
MainView.prototype = Object.assign({
13+
14+
connectToFoxBox: function() {
15+
return this.accessors.connectToFoxBoxButton.click().then(() => {
16+
var SetUpView = require('../sign_up/view');
17+
return new SetUpView(this.driver);
18+
});
19+
}
20+
21+
}, View.prototype);
22+
23+
module.exports = MainView;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var By = require('selenium-webdriver').By;
2+
var Accessors = require('../accessors');
3+
4+
function ServicesAccessors() {
5+
Accessors.apply(this, arguments);
6+
}
7+
8+
ServicesAccessors.prototype = Object.assign({
9+
10+
get logOutButton() {
11+
return this.waitForElement(By.css('.user-logout-button'));
12+
},
13+
14+
}, Accessors.prototype);
15+
16+
module.exports = ServicesAccessors;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var View = require('../view');
2+
var ServicesAccessors = require('./accessors');
3+
4+
5+
function ServicesView() {
6+
[].push.call(arguments, ServicesAccessors);
7+
View.apply(this, arguments);
8+
9+
this.accessors.logOutButton; // Wait until it appears
10+
}
11+
12+
ServicesView.prototype = Object.assign({
13+
14+
// To add functions here
15+
16+
}, View.prototype);
17+
module.exports = ServicesView;

test/selenium/lib/view/sign_up/view.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ SetUpView.prototype = {
4949
});
5050
},
5151

52+
successSignUpFromApp: function(password) {
53+
return this.accessors.insertPassword.sendKeys(password)
54+
.then(() => {
55+
return this.accessors.confirmPassword.sendKeys(password);
56+
}).then(() => {
57+
return this.accessors.submitButton.click();
58+
}).then(() => {
59+
var ServicesView = require('../services/view');
60+
return new ServicesView(this.driver);
61+
});
62+
},
63+
5264
failureLogin: function(password, confirmPassword) {
5365
return this.accessors.insertPassword.sendKeys(password)
5466
.then(() => {

0 commit comments

Comments
 (0)