forked from keepassxreboot/keepassxc-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests.js
65 lines (53 loc) · 2.06 KB
/
run_tests.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
const firefox = require('selenium-webdriver/firefox'),
webdriver = require('selenium-webdriver'),
By = require('selenium-webdriver').By,
test = require('selenium-webdriver/testing'),
assert = require('selenium-webdriver/testing/assert'),
fileUrl = require('file-url'),
softAssert = require('soft-assert'),
fs = require('fs-extra');
const DEST = 'keepassxc-browser/tests';
let browser;
test.before(async function(done) {
// Create a temporary directory and copy tests/* to keepassxc-browser/tests
await fs.ensureDir(DEST);
await fs.copy('./tests', DEST);
const options = new firefox.Options();
options.addArguments('--headless');
browser = await new webdriver.Builder().forBrowser('firefox').setFirefoxOptions(options).build();
browser.get(fileUrl(`${DEST}/tests.html`));
done();
});
test.after(async function() {
softAssert.softAssertAll();
browser.quit();
// Delete previously created temporary directory. Comment for re-running tests manually inside the extension.
await fs.remove(DEST);
});
test.describe('Content script tests', function() {
test.it('General tests', function() {
test.verifyResults('#general-results .fa');
});
test.it('Input field matching tests', function() {
test.verifyResults('#input-field-results .fa');
});
test.it('Search field tests', function() {
test.verifyResults('#search-field-results .fa');
});
test.it('TOTP field tests', function() {
test.verifyResults('#totp-field-results .fa');
});
test.it('Password change tests', function() {
test.verifyResults('#password-change-results .fa');
});
test.verifyResults = function(selector) {
browser.findElements(By.css(selector)).then(elems => {
elems.forEach(e => {
e.getAttribute('class').then(async c => {
const next = await e.findElements(By.xpath('./following::span'));
assert(c).contains('fa-check', await next[0].getText());
});
});
});
};
});