diff --git a/package.json b/package.json index 6b679bb..5d211f0 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ }, "scripts": { "build": "node build.js", - "tests": "npx playwright test tests/tests.js" + "tests": "npx playwright test" }, "repository": { "type": "git", diff --git a/playwright.config.js b/playwright.config.js index 012b7ff..6dd711d 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -30,6 +30,7 @@ const config = { }, }, ], + testMatch: 'content-script-tests.js', }; module.exports = config; diff --git a/tests/content-script-tests.js b/tests/content-script-tests.js new file mode 100644 index 0000000..7bb8e89 --- /dev/null +++ b/tests/content-script-tests.js @@ -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'); + } +}; diff --git a/tests/example.spec.js b/tests/example.spec.js deleted file mode 100644 index 7e89283..0000000 --- a/tests/example.spec.js +++ /dev/null @@ -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'); -};