mirror of
https://github.com/keepassxreboot/keepassxc-browser.git
synced 2026-03-11 08:54:43 +00:00
Move tests from Selenium & Mocha to Playwright
This commit is contained in:
parent
97e07b5a62
commit
ecae40a6b6
4 changed files with 48 additions and 76 deletions
|
|
@ -16,7 +16,7 @@
|
|||
},
|
||||
"scripts": {
|
||||
"build": "node build.js",
|
||||
"tests": "npx playwright test tests/tests.js"
|
||||
"tests": "npx playwright test"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ const config = {
|
|||
},
|
||||
},
|
||||
],
|
||||
testMatch: 'content-script-tests.js',
|
||||
};
|
||||
|
||||
module.exports = config;
|
||||
|
|
|
|||
46
tests/content-script-tests.js
Normal file
46
tests/content-script-tests.js
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
'use strict';
|
||||
|
||||
const { test, expect } = require('@playwright/test');
|
||||
const fileUrl = require('file-url');
|
||||
|
||||
const DEST = 'keepassxc-browser/tests';
|
||||
|
||||
let page;
|
||||
|
||||
test.describe('Content script tests', () => {
|
||||
test.beforeAll(async ({ browser }) => {
|
||||
page = await browser.newPage();
|
||||
await page.goto(fileUrl(`${DEST}/tests.html`));
|
||||
});
|
||||
|
||||
test('General tests', async () => {
|
||||
await verifyResults('general-results');
|
||||
});
|
||||
|
||||
test('Input field matching tests', async() => {
|
||||
await verifyResults('input-field-results');
|
||||
});
|
||||
|
||||
test('Search field tests', async () => {
|
||||
await verifyResults('search-field-results');
|
||||
});
|
||||
|
||||
test('TOTP field tests', async () => {
|
||||
await verifyResults('totp-field-results');
|
||||
});
|
||||
|
||||
test('Password change tests', async () => {
|
||||
await verifyResults('password-change-results');
|
||||
});
|
||||
});
|
||||
|
||||
const verifyResults = async(selector) => {
|
||||
const resultCount = await page.locator(`css=#${selector} >> css=.fa`).count();
|
||||
await expect.soft(resultCount).toBeGreaterThan(0);
|
||||
|
||||
for (var i = 0; i < resultCount; i++) {
|
||||
const elem = await page.locator(`css=#${selector} >> css=.fa`).nth(i);
|
||||
const id = await elem.getAttribute('id');
|
||||
await expect.soft(elem, id).toHaveClass('fa fa-check');
|
||||
}
|
||||
};
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
const { test, expect } = require('@playwright/test');
|
||||
const fileUrl = require('file-url');
|
||||
|
||||
const DEST = 'keepassxc-browser/tests';
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto(fileUrl(`${DEST}/tests.html`));
|
||||
});
|
||||
|
||||
test.describe('Content script tests', () => {
|
||||
test('General tests', async ({ page }) => {
|
||||
const resultCount = await page.locator('css=#general-results >> css=.fa').count();
|
||||
await expect.soft(resultCount).toBeGreaterThan(0);
|
||||
|
||||
for (var i = 0; i < resultCount; i++) {
|
||||
const elem = await page.locator('css=#general-results >> css=.fa').nth(i);
|
||||
const id = await elem.getAttribute('id');
|
||||
await expect.soft(elem, id).toHaveClass('fa fa-check');
|
||||
}
|
||||
});
|
||||
|
||||
test('Input field matching tests', async ({ page }) => {
|
||||
const resultCount = await page.locator('css=#input-field-results >> css=.fa').count();
|
||||
await expect.soft(resultCount).toBeGreaterThan(0);
|
||||
|
||||
for (var i = 0; i < resultCount; i++) {
|
||||
const elem = await page.locator('css=#input-field-results >> css=.fa').nth(i);
|
||||
const id = await elem.getAttribute('id');
|
||||
await expect.soft(elem, id).toHaveClass('fa fa-check');
|
||||
}
|
||||
});
|
||||
|
||||
test('Search field tests', async ({ page }) => {
|
||||
const resultCount = await page.locator('css=#search-field-results >> css=.fa').count();
|
||||
await expect.soft(resultCount).toBeGreaterThan(0);
|
||||
|
||||
for (var i = 0; i < resultCount; i++) {
|
||||
const elem = await page.locator('css=#search-field-results >> css=.fa').nth(i);
|
||||
const id = await elem.getAttribute('id');
|
||||
await expect.soft(elem, id).toHaveClass('fa fa-check');
|
||||
}
|
||||
});
|
||||
|
||||
test('TOTP field tests', async ({ page }) => {
|
||||
const resultCount = await page.locator('css=#totp-field-results >> css=.fa').count();
|
||||
await expect.soft(resultCount).toBeGreaterThan(0);
|
||||
|
||||
for (var i = 0; i < resultCount; i++) {
|
||||
const elem = await page.locator('css=#totp-field-results >> css=.fa').nth(i);
|
||||
const id = await elem.getAttribute('id');
|
||||
await expect.soft(elem, id).toHaveClass('fa fa-check');
|
||||
}
|
||||
});
|
||||
|
||||
test('Password change tests', async ({ page }) => {
|
||||
const resultCount = await page.locator('css=#password-change-results >> css=.fa').count();
|
||||
await expect.soft(resultCount).toBeGreaterThan(0);
|
||||
|
||||
for (var i = 0; i < resultCount; i++) {
|
||||
const elem = await page.locator('css=#password-change-results >> css=.fa').nth(i);
|
||||
const id = await elem.getAttribute('id');
|
||||
await expect.soft(elem, id).toHaveClass('fa fa-check');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const verifyResults = async(page, selector) => {
|
||||
const resultCount = await page.locator(`css=#${selector} >> css=.fa`).count();
|
||||
|
||||
const elem = await page.locator(`css=#${selector} >> css=.fa`).nth(0);
|
||||
const id = await elem.getAttribute('id');
|
||||
await expect.soft(elem, id).toHaveClass('fa fa-check');
|
||||
};
|
||||
Loading…
Reference in a new issue