Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 🎸 Use snapshots or OCR for E2E tests when comparing terminal #2639

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion e2e-tests/desktop/fixtures/baseTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import { mergeTests } from '@playwright/test';
import { electronTest } from './electronTest.js';
import { authenticateTest } from './authenticateTest.js';
import { test as envTest } from '../../global-setup.js';
import { tesseractTest } from './tesseractTest.js';

// The last item in the list will override any previous ones in a fixture name collision
export const test = mergeTests(envTest, authenticateTest, electronTest);
export const test = mergeTests(
envTest,
authenticateTest,
electronTest,
tesseractTest,
);
export { expect } from '@playwright/test';
23 changes: 23 additions & 0 deletions e2e-tests/desktop/fixtures/tesseractTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/

import { test } from '@playwright/test';
import { createWorker } from 'tesseract.js';

export const tesseractTest = test.extend({
textToSearch: ({}, use) => {
use('To run a command as administrator');
},
tesseract: [
async ({}, use) => {
const worker = await createWorker('eng', 1, {
cachePath: './artifacts',
});
await use(worker);
await worker.terminate();
},
{ scope: 'worker' },
],
});
1 change: 1 addition & 0 deletions e2e-tests/desktop/playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default defineConfig({
Authorization: `Bearer ${process.env.E2E_TOKEN}`,
},
},
snapshotPathTemplate: '{testDir}/snapshots/{arg}{ext}',
expect: {
timeout: 10000,
},
Expand Down
21 changes: 15 additions & 6 deletions e2e-tests/desktop/tests/sessions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,16 @@ test.describe('Filtering sessions tests', async () => {
await expect(
authedPage.getByRole('button', { name: 'Clear Filters' }),
).toBeHidden();
for (const cancel of await authedPage.getByLabel('Cancel').all()) {
await cancel.click();
}

await expect(authedPage.getByLabel('Cancel')).toHaveCount(0);
await expect(async () => {
await authedPage.getByRole('button', { name: 'Refresh' }).click();
for (const cancel of await authedPage.getByLabel('Cancel').all()) {
await cancel.click();
}
await expect(
authedPage.getByRole('cell', { name: /(Pending|Active)/ }),
).toHaveCount(0);
}).toPass();
});

test('Filters by target', async ({ authedPage }) => {
Expand All @@ -206,14 +211,18 @@ test.describe('Filtering sessions tests', async () => {
).toBeVisible();
});

test('Filters by status', async ({ authedPage }) => {
test('Filters by status', async ({ authedPage, tesseract, textToSearch }) => {
await authedPage
.getByRole('row', { name: sshTarget.name })
.getByRole('link')
.first()
.click();
await authedPage.getByRole('tab', { name: 'Shell' }).click();
await authedPage.waitForTimeout(3000);
await expect(async () => {
const screenshot = await authedPage.locator('.xterm-screen').screenshot();
const result = await tesseract.recognize(screenshot);
expect(result.data.text).toContain(textToSearch);
}).toPass();
await authedPage.getByRole('link', { name: 'Sessions' }).click();

await authedPage.getByRole('button', { name: 'Clear Filters' }).click();
Expand Down
14 changes: 11 additions & 3 deletions e2e-tests/desktop/tests/targets.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ test.describe('Targets tests', async () => {
});
});

test('Connects to an SSH target', async ({ authedPage }) => {
test('Connects to an SSH target', async ({
authedPage,
tesseract,
textToSearch,
}) => {
await authedPage.getByRole('link', { name: sshTarget.name }).click();
await authedPage.getByRole('button', { name: 'Connect' }).click();

Expand All @@ -224,8 +228,12 @@ test.describe('Targets tests', async () => {
).toBeVisible();

await authedPage.getByRole('tab', { name: 'Shell' }).click();
// TODO: Research a better way to test canvas elements for the shell,
// would it be too brittle to assert a snapshot of an expected image?

await expect(async () => {
const screenshot = await authedPage.locator('.xterm-screen').screenshot();
const result = await tesseract.recognize(screenshot);
expect(result.data.text).toContain(textToSearch);
}).toPass();

await authedPage.getByRole('button', { name: 'End Session' }).click();
await expect(authedPage.getByText('Canceled successfully.')).toBeVisible();
Expand Down
3 changes: 2 additions & 1 deletion e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-n": "^16.3.1",
"nanoid": "^5.0.9",
"prettier": "^3.0.0"
"prettier": "^3.0.0",
"tesseract.js": "^5.1.1"
},
"engines": {
"node": "20.* || 22.*"
Expand Down
76 changes: 73 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3856,7 +3856,7 @@
broccoli-funnel "^3.0.8"
semver "^7.3.8"

"@embroider/macros@^0.50.0 || ^1.0.0", "@embroider/macros@^1.0.0", "@embroider/macros@^1.10.0", "@embroider/macros@^1.12.3", "@embroider/macros@^1.13.0", "@embroider/macros@^1.13.1", "@embroider/macros@^1.13.2", "@embroider/macros@^1.16.1", "@embroider/macros@^1.16.5", "@embroider/macros@^1.16.9", "@embroider/macros@^1.8.1", "@embroider/macros@^1.8.3":
"@embroider/macros@^0.50.0 || ^1.0.0", "@embroider/macros@^1.0.0", "@embroider/macros@^1.10.0", "@embroider/macros@^1.13.0", "@embroider/macros@^1.13.1", "@embroider/macros@^1.13.2", "@embroider/macros@^1.16.1", "@embroider/macros@^1.16.5", "@embroider/macros@^1.16.9", "@embroider/macros@^1.8.1", "@embroider/macros@^1.8.3":
version "1.16.9"
resolved "https://registry.yarnpkg.com/@embroider/macros/-/macros-1.16.9.tgz#d1292105259f53f31a8bf0fde48cf972495f06d1"
integrity sha512-AUrmHQdixczIU3ouv/+HzWxwYVsw/NwssZxAQnXfBDJ3d3/CRtAvGRu3JhY6OT3AAPFwfa2WT66tB5jeAa7r5g==
Expand All @@ -3870,6 +3870,20 @@
resolve "^1.20.0"
semver "^7.3.2"

"@embroider/macros@^1.12.3":
version "1.16.10"
resolved "https://registry.yarnpkg.com/@embroider/macros/-/macros-1.16.10.tgz#4f00c959409ee7327a344c250fc91c4622bf1589"
integrity sha512-G0vCsKgNCX0PMmuVNsTLG7IYXz8VkekQMK4Kcllzqpwb7ivFRDwVx2bD4QSvZ9LCTd4eWQ654RsCqVbW5aviww==
dependencies:
"@embroider/shared-internals" "2.8.1"
assert-never "^1.2.1"
babel-import-util "^2.0.0"
ember-cli-babel "^7.26.6"
find-up "^5.0.0"
lodash "^4.17.21"
resolve "^1.20.0"
semver "^7.3.2"

"@embroider/shared-internals@2.8.1", "@embroider/shared-internals@^2.0.0", "@embroider/shared-internals@^2.1.0", "@embroider/shared-internals@^2.2.3", "@embroider/shared-internals@^2.6.0", "@embroider/shared-internals@^2.8.1":
version "2.8.1"
resolved "https://registry.yarnpkg.com/@embroider/shared-internals/-/shared-internals-2.8.1.tgz#2aecff7324299f1e5fe563be7ee9882ee5566bcc"
Expand Down Expand Up @@ -6196,6 +6210,11 @@ bluebird@^3.1.1, bluebird@^3.4.6, bluebird@^3.7.2:
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==

bmp-js@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/bmp-js/-/bmp-js-0.1.0.tgz#e05a63f796a6c1ff25f4771ec7adadc148c07233"
integrity sha512-vHdS19CnY3hwiNdkaqk93DvjVLfbEcI8mys4UjuWrlX1haDmroo8o4xCzh4wD6DGV6HxRCyauwhHRqMTfERtjw==

body-parser@1.20.3, body-parser@^1.17.0, body-parser@^1.19.0, body-parser@^1.19.1:
version "1.20.3"
resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.20.3.tgz#1953431221c6fb5cd63c4b36d53fab0928e548c6"
Expand Down Expand Up @@ -11756,6 +11775,11 @@ icss-utils@^5.0.0, icss-utils@^5.1.0:
resolved "https://registry.yarnpkg.com/icss-utils/-/icss-utils-5.1.0.tgz#c6be6858abd013d768e98366ae47e25d5887b1ae"
integrity sha512-soFhflCVWLfRNOPU3iv5Z9VUdT44xFRbzjLsEzSr5AQmgqPMTHdU3PMT1Cf1ssx8fLNJDA1juftYl+PUcv3MqA==

idb-keyval@^6.2.0:
version "6.2.1"
resolved "https://registry.yarnpkg.com/idb-keyval/-/idb-keyval-6.2.1.tgz#94516d625346d16f56f3b33855da11bfded2db33"
integrity sha512-8Sb3veuYCyrZL+VBt9LJfZjLUPWVvqn8tG28VqYNFCo43KHcKuq+b4EiXGeuaLAQWL2YmyDgMp2aSpH9JHsEQg==

ieee754@^1.1.13:
version "1.2.1"
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352"
Expand Down Expand Up @@ -12094,6 +12118,11 @@ is-docker@^2.0.0:
resolved "https://registry.yarnpkg.com/is-docker/-/is-docker-2.2.1.tgz#33eeabe23cfe86f14bde4408a02c0cfb853acdaa"
integrity sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==

is-electron@^2.2.2:
version "2.2.2"
resolved "https://registry.yarnpkg.com/is-electron/-/is-electron-2.2.2.tgz#3778902a2044d76de98036f5dc58089ac4d80bb9"
integrity sha512-FO/Rhvz5tuw4MCWkpMzHFKWD2LsfHzIb7i6MdPYZ/KW7AlxawyLkqdy+jPZP1WubqEADE3O4FUENlJHDfQASRg==

is-extglob@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2"
Expand Down Expand Up @@ -12282,6 +12311,11 @@ is-unicode-supported@^0.1.0:
resolved "https://registry.yarnpkg.com/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz#3f26c76a809593b52bfa2ecb5710ed2779b522a7"
integrity sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==

is-url@^1.2.4:
version "1.2.4"
resolved "https://registry.yarnpkg.com/is-url/-/is-url-1.2.4.tgz#04a4df46d28c4cff3d73d01ff06abeb318a1aa52"
integrity sha512-ITvGim8FhRiYe4IQ5uHSkj7pVaPDrCTkNd3yq3cV7iZAcJdHTUMPMEHcqSOy9xZ9qFenQCvi+2wjH9a1nXqHww==

is-utf8@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/is-utf8/-/is-utf8-0.2.1.tgz#4b0da1442104d1b336340e80797e865cf39f7d72"
Expand Down Expand Up @@ -14174,7 +14208,7 @@ node-fetch@^2.6.0, node-fetch@^2.6.1:
dependencies:
whatwg-url "^5.0.0"

node-fetch@^2.6.7:
node-fetch@^2.6.7, node-fetch@^2.6.9:
version "2.7.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
Expand Down Expand Up @@ -14501,6 +14535,11 @@ onetime@^7.0.0:
dependencies:
mimic-function "^5.0.0"

opencollective-postinstall@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/opencollective-postinstall/-/opencollective-postinstall-2.0.3.tgz#7a0fff978f6dbfa4d006238fbac98ed4198c3259"
integrity sha512-8AV/sCtuzUeTo8gQK5qDZzARrulB3egtLzFgteqB2tcT4Mw7B8Kt7JcDHmltjz6FOAHsvTevk70gZEbhM4ZS9Q==

optionator@^0.9.1:
version "0.9.1"
resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.9.1.tgz#4f236a6373dae0566a6d43e1326674f50c291499"
Expand Down Expand Up @@ -15543,7 +15582,7 @@ regenerate@^1.4.0, regenerate@^1.4.2:
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.2.tgz#b9346d8827e8f5a32f7ba29637d398b69014848a"
integrity sha512-zrceR/XhGYU/d/opr2EKO7aRHUeiBI8qjtfHqADTwZd6Szfy16la6kqD0MIUs5z5hx6AaKa+PixpPrR289+I0A==

regenerator-runtime@^0.13.11:
regenerator-runtime@^0.13.11, regenerator-runtime@^0.13.3:
version "0.13.11"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz#f6dca3e7ceec20590d07ada785636a90cdca17f9"
integrity sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==
Expand Down Expand Up @@ -17232,6 +17271,27 @@ terser@^5.3.0:
commander "^2.20.0"
source-map-support "~0.5.20"

tesseract.js-core@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/tesseract.js-core/-/tesseract.js-core-5.1.1.tgz#2b6f3ef28dd109bf4efdbc8fff70bd11adac8b85"
integrity sha512-KX3bYSU5iGcO1XJa+QGPbi+Zjo2qq6eBhNjSGR5E5q0JtzkoipJKOUQD7ph8kFyteCEfEQ0maWLu8MCXtvX5uQ==

tesseract.js@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/tesseract.js/-/tesseract.js-5.1.1.tgz#7bfaca1c103ba0ce3ddf5e101f0692802a01f880"
integrity sha512-lzVl/Ar3P3zhpUT31NjqeCo1f+D5+YfpZ5J62eo2S14QNVOmHBTtbchHm/YAbOOOzCegFnKf4B3Qih9LuldcYQ==
dependencies:
bmp-js "^0.1.0"
idb-keyval "^6.2.0"
is-electron "^2.2.2"
is-url "^1.2.4"
node-fetch "^2.6.9"
opencollective-postinstall "^2.0.3"
regenerator-runtime "^0.13.3"
tesseract.js-core "^5.1.1"
wasm-feature-detect "^1.2.11"
zlibjs "^0.3.1"

test-exclude@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-6.0.0.tgz#04a8698661d805ea6fa293b6cb9e63ac044ef15e"
Expand Down Expand Up @@ -17946,6 +18006,11 @@ walker@~1.0.5:
dependencies:
makeerror "1.0.x"

wasm-feature-detect@^1.2.11:
version "1.8.0"
resolved "https://registry.yarnpkg.com/wasm-feature-detect/-/wasm-feature-detect-1.8.0.tgz#4e9f55b0a64d801f372fbb0324ed11ad3abd0c78"
integrity sha512-zksaLKM2fVlnB5jQQDqKXXwYHLQUVH9es+5TOOHwGOVJOCeRBCiPjwSg+3tN2AdTCzjgli4jijCH290kXb/zWQ==

watch-detector@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/watch-detector/-/watch-detector-1.0.1.tgz#3106a6b489284ec2ecaef0e65cf1b8ec9117296e"
Expand Down Expand Up @@ -18304,6 +18369,11 @@ yoctocolors-cjs@^2.1.2:
resolved "https://registry.yarnpkg.com/yoctocolors-cjs/-/yoctocolors-cjs-2.1.2.tgz#f4b905a840a37506813a7acaa28febe97767a242"
integrity sha512-cYVsTjKl8b+FrnidjibDWskAv7UKOfcwaVZdp/it9n1s9fU3IkgDbhdIRKCW4JDsAlECJY0ytoVPT3sK6kideA==

zlibjs@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/zlibjs/-/zlibjs-0.3.1.tgz#50197edb28a1c42ca659cc8b4e6a9ddd6d444554"
integrity sha512-+J9RrgTKOmlxFSDHo0pI1xM6BLVUv+o0ZT9ANtCxGkjIVCCUdx9alUF8Gm+dGLKbkkkidWIHFDZHDMpfITt4+w==

zwitch@^1.0.0:
version "1.0.5"
resolved "https://registry.yarnpkg.com/zwitch/-/zwitch-1.0.5.tgz#d11d7381ffed16b742f6af7b3f223d5cd9fe9920"
Expand Down
Loading