Skip to content

Commit f8222a5

Browse files
authored
Add e2e tests for report attachments (#176)
1 parent 71b5dcc commit f8222a5

File tree

16 files changed

+428
-17
lines changed

16 files changed

+428
-17
lines changed
Lines changed: 332 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,332 @@
1+
import { expect, test } from "@playwright/test";
2+
import { Stage, Status, label } from "allure-js-commons";
3+
import { readFile } from "node:fs/promises";
4+
import { dirname as pathDirname, resolve } from "node:path";
5+
import { fileURLToPath } from "node:url";
6+
import { TestResultPage, TreePage } from "../pageObjects/index.js";
7+
import { type ReportBootstrap, bootstrapReport } from "../utils/index.js";
8+
9+
const dirname = pathDirname(fileURLToPath(import.meta.url));
10+
11+
let bootstrap: ReportBootstrap;
12+
let treePage: TreePage;
13+
let testResultPage: TestResultPage;
14+
15+
test.describe("attachments", () => {
16+
test.beforeEach(async ({ browserName, page }) => {
17+
await label("env", browserName);
18+
19+
treePage = new TreePage(page);
20+
testResultPage = new TestResultPage(page);
21+
});
22+
23+
test.afterAll(async () => {
24+
await bootstrap?.shutdown?.();
25+
});
26+
27+
test.describe("commons", () => {
28+
test.beforeEach(async ({ page }) => {
29+
bootstrap = await bootstrapReport({
30+
reportConfig: {
31+
name: "Allure report with attachments",
32+
appendHistory: true,
33+
history: [],
34+
historyPath: "history.jsonl",
35+
knownIssuesPath: undefined,
36+
},
37+
testResults: [
38+
{
39+
name: "foo",
40+
fullName: "sample.test.js#test with image attachment",
41+
historyId: "",
42+
status: Status.PASSED,
43+
stage: Stage.FINISHED,
44+
start: Date.now(),
45+
stop: Date.now() + 1000,
46+
steps: [
47+
{
48+
name: "bar",
49+
status: Status.PASSED,
50+
stage: Stage.FINISHED,
51+
parameters: [],
52+
steps: [],
53+
statusDetails: {},
54+
attachments: [
55+
{
56+
source: "attachment.txt",
57+
type: "text/plain",
58+
name: "attachment",
59+
},
60+
],
61+
},
62+
],
63+
},
64+
],
65+
attachments: [],
66+
});
67+
68+
await page.goto(bootstrap.url);
69+
});
70+
71+
test('should render "missed" label for attachments which don\'t exist', async ({ page }) => {
72+
await treePage.clickNthLeaf(0);
73+
await testResultPage.toggleStepByTitle("bar");
74+
75+
await expect(testResultPage.testResultAttachmentLocator).toHaveCount(1);
76+
await expect(
77+
testResultPage.testResultAttachmentLocator.nth(0).getByTestId("test-result-attachment-missed"),
78+
).toBeVisible();
79+
80+
await testResultPage.screenshot();
81+
});
82+
});
83+
84+
test.describe("text attachment", () => {
85+
test.beforeEach(async ({ page }) => {
86+
bootstrap = await bootstrapReport({
87+
reportConfig: {
88+
name: "Allure report with attachments",
89+
appendHistory: true,
90+
history: [],
91+
historyPath: "history.jsonl",
92+
knownIssuesPath: undefined,
93+
},
94+
testResults: [
95+
{
96+
name: "foo",
97+
fullName: "sample.test.js#test with image attachment",
98+
historyId: "",
99+
status: Status.PASSED,
100+
stage: Stage.FINISHED,
101+
start: Date.now(),
102+
stop: Date.now() + 1000,
103+
steps: [
104+
{
105+
name: "bar",
106+
status: Status.PASSED,
107+
stage: Stage.FINISHED,
108+
parameters: [],
109+
steps: [],
110+
statusDetails: {},
111+
attachments: [
112+
{
113+
source: "attachment.txt",
114+
type: "text/plain",
115+
name: "attachment",
116+
},
117+
],
118+
},
119+
],
120+
},
121+
],
122+
attachments: [
123+
{
124+
source: "attachment.txt",
125+
content: Buffer.from("attachment content", "utf8"),
126+
},
127+
],
128+
});
129+
130+
await page.goto(bootstrap.url);
131+
});
132+
133+
test("should render attachment in the test result body and allow to preview it", async () => {
134+
await treePage.clickNthLeaf(0);
135+
await testResultPage.toggleStepByTitle("bar");
136+
137+
await expect(testResultPage.testResultAttachmentLocator).toHaveCount(1);
138+
139+
await testResultPage.toggleAttachmentByTitle("attachment");
140+
141+
await expect(testResultPage.codeAttachmentContentLocator).toHaveCount(1);
142+
await expect(testResultPage.codeAttachmentContentLocator.nth(0)).toHaveText("attachment content");
143+
144+
await testResultPage.screenshot();
145+
});
146+
147+
test("should render attachment in the test result attachments tab and allow to preview it", async () => {
148+
await treePage.clickNthLeaf(0);
149+
150+
const attachmentsTab = testResultPage.tabById("attachments");
151+
152+
await expect(attachmentsTab.getByTestId("counter")).toHaveText("1");
153+
154+
await attachmentsTab.click();
155+
156+
await expect(testResultPage.testResultAttachmentLocator).toHaveCount(1);
157+
158+
await testResultPage.toggleAttachmentByTitle("attachment");
159+
160+
await expect(testResultPage.codeAttachmentContentLocator).toHaveCount(1);
161+
await expect(testResultPage.codeAttachmentContentLocator.nth(0)).toHaveText("attachment content");
162+
163+
await testResultPage.screenshot();
164+
});
165+
});
166+
167+
test.describe("image attachment", () => {
168+
test.beforeEach(async ({ page }) => {
169+
const imageAttachment = await readFile(resolve(dirname, "../../fixtures/image.png"));
170+
171+
bootstrap = await bootstrapReport({
172+
reportConfig: {
173+
name: "Allure report with attachments",
174+
appendHistory: true,
175+
history: [],
176+
historyPath: "history.jsonl",
177+
knownIssuesPath: undefined,
178+
},
179+
testResults: [
180+
{
181+
name: "foo",
182+
fullName: "sample.test.js#test with image attachment",
183+
historyId: "",
184+
status: Status.PASSED,
185+
stage: Stage.FINISHED,
186+
start: Date.now(),
187+
stop: Date.now() + 1000,
188+
steps: [
189+
{
190+
name: "bar",
191+
status: Status.PASSED,
192+
stage: Stage.FINISHED,
193+
parameters: [],
194+
steps: [],
195+
statusDetails: {},
196+
attachments: [
197+
{
198+
source: "attachment.png",
199+
type: "image/png",
200+
name: "attachment",
201+
},
202+
],
203+
},
204+
],
205+
},
206+
],
207+
attachments: [
208+
{
209+
source: "attachment.png",
210+
content: imageAttachment,
211+
},
212+
],
213+
});
214+
215+
await page.goto(bootstrap.url);
216+
});
217+
218+
test("should render attachment in the test result body and allow to preview it", async ({ page }) => {
219+
await treePage.clickNthLeaf(0);
220+
await testResultPage.toggleStepByTitle("bar");
221+
222+
await expect(testResultPage.testResultAttachmentLocator).toHaveCount(1);
223+
224+
await testResultPage.toggleAttachmentByTitle("attachment");
225+
226+
await expect(testResultPage.imageAttachmentContentLocator).toHaveCount(1);
227+
228+
await testResultPage.screenshot();
229+
});
230+
231+
test("should render attachment in the test result attachments tab and allow to preview it", async ({ page }) => {
232+
await treePage.clickNthLeaf(0);
233+
234+
const attachmentsTab = testResultPage.tabById("attachments");
235+
236+
await expect(attachmentsTab.getByTestId("counter")).toHaveText("1");
237+
238+
await attachmentsTab.click();
239+
240+
await expect(testResultPage.testResultAttachmentLocator).toHaveCount(1);
241+
242+
await testResultPage.toggleAttachmentByTitle("attachment");
243+
244+
await expect(testResultPage.imageAttachmentContentLocator).toHaveCount(1);
245+
246+
await testResultPage.screenshot();
247+
});
248+
});
249+
250+
test.describe("video attachment", () => {
251+
test.beforeEach(async ({ page }) => {
252+
const videoAttachment = await readFile(resolve(dirname, "../../fixtures/video.mp4"));
253+
254+
bootstrap = await bootstrapReport({
255+
reportConfig: {
256+
name: "Allure report with attachments",
257+
appendHistory: true,
258+
history: [],
259+
historyPath: "history.jsonl",
260+
knownIssuesPath: undefined,
261+
},
262+
testResults: [
263+
{
264+
name: "foo",
265+
fullName: "sample.test.js#test with image attachment",
266+
historyId: "",
267+
status: Status.PASSED,
268+
stage: Stage.FINISHED,
269+
start: Date.now(),
270+
stop: Date.now() + 1000,
271+
steps: [
272+
{
273+
name: "bar",
274+
status: Status.PASSED,
275+
stage: Stage.FINISHED,
276+
parameters: [],
277+
steps: [],
278+
statusDetails: {},
279+
attachments: [
280+
{
281+
source: "attachment.mp4",
282+
type: "video/mp4",
283+
name: "attachment",
284+
},
285+
],
286+
},
287+
],
288+
},
289+
],
290+
attachments: [
291+
{
292+
source: "attachment.mp4",
293+
content: videoAttachment,
294+
},
295+
],
296+
});
297+
298+
await page.goto(bootstrap.url);
299+
});
300+
301+
test("should render attachment in the test result body and allow to preview it", async ({ page }) => {
302+
await treePage.clickNthLeaf(0);
303+
await testResultPage.toggleStepByTitle("bar");
304+
305+
await expect(testResultPage.testResultAttachmentLocator).toHaveCount(1);
306+
307+
await testResultPage.toggleAttachmentByTitle("attachment");
308+
309+
await expect(testResultPage.videoAttachmentContentLocator).toHaveCount(1);
310+
311+
await testResultPage.screenshot();
312+
});
313+
314+
test("should render attachment in the test result attachments tab and allow to preview it", async ({ page }) => {
315+
await treePage.clickNthLeaf(0);
316+
317+
const attachmentsTab = testResultPage.tabById("attachments");
318+
319+
await expect(attachmentsTab.getByTestId("counter")).toHaveText("1");
320+
321+
await attachmentsTab.click();
322+
323+
await expect(testResultPage.testResultAttachmentLocator).toHaveCount(1);
324+
325+
await testResultPage.toggleAttachmentByTitle("attachment");
326+
327+
await expect(testResultPage.videoAttachmentContentLocator).toHaveCount(1);
328+
329+
await testResultPage.screenshot();
330+
});
331+
});
332+
});

packages/e2e/test/allure-awesome/pageObjects/Common.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type Locator, type Page } from "@playwright/test";
2+
import { PageObject } from "./pageObject.js";
23

3-
export class CommonPage {
4+
export class CommonPage extends PageObject {
45
reportTitleLocator: Locator;
56

67
toggleLayoutButtonLocator: Locator;
@@ -11,6 +12,8 @@ export class CommonPage {
1112
envPickerButtonLocator: Locator;
1213

1314
constructor(readonly page: Page) {
15+
super(page);
16+
1417
this.reportTitleLocator = page.getByTestId("report-title");
1518

1619
this.toggleLayoutButtonLocator = page.getByTestId("toggle-layout-button");

0 commit comments

Comments
 (0)