Skip to content

Commit

Permalink
Take screenshots when playwright test fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfgang Ginolas committed Nov 27, 2024
1 parent 54b9665 commit 72daa6c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ and find the result here: `bazel-bin/onlyoffice-editor.tar.gz`
bazel test --test_output=errors //...
```

Screenshots of failed playwright tests are taken and put here: `bazel-testlogs/e2etests/playwright-test/test.outputs/outputs.zip`

# Updating npm dependencies
After changing a `pachage.json` file you have to run this command to update the bazel dependencies:

Expand Down
1 change: 0 additions & 1 deletion e2etests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ js_binary(
js_test(
name = "playwright-test",
entry_point = "playwright-test.mjs",
args = ["test"],
include_npm = True,
env = {
#"BROWSERS_PATH": "@(location :cache-ms-playwright)",
Expand Down
12 changes: 7 additions & 5 deletions e2etests/playwright-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ import { join } from 'node:path';
import assert from 'node:assert/strict';
import { GenericContainer } from "testcontainers";
import { spawnSync } from 'node:child_process';
import { readdirSync } from 'node:fs';
import { readdirSync, cpSync } from 'node:fs';

async function main() {
let httpPort;
const playwrightCommand = process.argv[2];
const browserCache = join(process.cwd(), 'e2etests', 'ms-playwright');

process.chdir('e2etests');

// console.log('XXX ls .', readdirSync('.'));
// console.log('XXX ls ms-playwright', readdirSync('ms-playwright'));
console.log('XXX ls .', readdirSync('.'));
console.log('XXX ls ms-playwright', readdirSync('ms-playwright'));


const dockerInfo = spawnSync("docker", ["load", "-i", "../docker/load/tarball.tar"], {
Expand All @@ -36,10 +35,13 @@ async function main() {
]);
assert.equal(exitCode, 0)

const npmInfo = spawnSync('npm', ['--cache', '.', 'exec', '--', 'playwright', playwrightCommand], {
const npmInfo = spawnSync('npm', ['--cache', '.', 'exec', '--', 'playwright', 'test'], {
stdio: 'inherit',
env: { ...process.env, PLAYWRIGHT_BROWSERS_PATH: browserCache }
});
console.log('XXX ls .', readdirSync('.'));
console.log('XXX ls test-results', readdirSync('test-results'));
cpSync('test-results', process.env['TEST_UNDECLARED_OUTPUTS_DIR'], {recursive: true});
assert.equal(npmInfo.status, 0, 'Error while calling playwright ' + npmInfo.stdout + ' ' + npmInfo.stderr);
} finally {
await container.stop();
Expand Down
1 change: 1 addition & 0 deletions e2etests/playwright.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = defineConfig({

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
screenshot: 'only-on-failure',
},
timeout: 50000,
expect: {
Expand Down
8 changes: 8 additions & 0 deletions e2etests/tests/example.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ test('welcome page', async ({ page }) => {

await expect(page.getByText("GO TO TEST EXAMPLE")).toBeVisible();
});

test('open docx', async ({ page }) => {
await page.goto('http://localhost/example/editor?fileExt=docx');

// await expect(page.locator('#id_target_cursor')).toBeAttached();
await expect(page.locator('.asc-loadmask')).toBeAttached();

});

0 comments on commit 72daa6c

Please sign in to comment.