|
8 | 8 | * 4. Wstrzykuje lib/validateEAN.js (definicja funkcji walidacji) |
9 | 9 | * 5. Wstrzykuje content_scripts/pola.js (logika skanowania) |
10 | 10 | * 6. Sprawdza czy content script znalazł oczekiwany kod EAN |
11 | | - * |
12 | | - * UWAGA: Te testy odpytują prawdziwe strony internetowe, więc: |
13 | | - * - Mogą być wolniejsze (zależą od sieci) |
14 | | - * - Mogą się "zepsuć" jeśli sklep zmieni stronę (wtedy trzeba zaktualizować test) |
15 | | - * - W CI uruchamiamy je z retry=1 i osobnym jobem (allow-failure) |
16 | 11 | */ |
17 | 12 |
|
18 | 13 | const { test, expect } = require('@playwright/test'); |
@@ -54,32 +49,60 @@ async function injectContentScript(page) { |
54 | 49 | // TESTY |
55 | 50 | // ============================================================================ |
56 | 51 |
|
| 52 | +const productPages = [ |
| 53 | + { |
| 54 | + store: 'frisco.pl', |
| 55 | + product: 'Makłowicz i Synowie oliwa z oliwek extra virgin', |
| 56 | + ean: '5905644030022', |
| 57 | + url: 'https://www.frisco.pl/pid,145610/n,maklowicz-i-synowie-oliwa-z-oliwek-extra-vergine/stn,product', |
| 58 | + }, |
| 59 | + { |
| 60 | + store: 'erli.pl', |
| 61 | + product: 'Szklany dzbanek filtrujący Dafi CRYSTAL 2l biały', |
| 62 | + ean: '5900950928254', |
| 63 | + url: 'https://erli.pl/produkt/szklany-dzbanek-filtrujacy-dafi-crystal-2l-bialy,159105253', |
| 64 | + }, |
| 65 | + { |
| 66 | + store: 'dodomku.pl', |
| 67 | + product: 'Maluta Masło ekstra', |
| 68 | + ean: '5904467191316', |
| 69 | + url: 'https://dodomku.pl/Maluta_Maslo_ekstra/61218_2435341_552.html', |
| 70 | + }, |
| 71 | + { |
| 72 | + store: 'megasam24.pl', |
| 73 | + product: 'Baton mango bez dodatku cukru 35 g', |
| 74 | + ean: '4820287102619', |
| 75 | + url: 'https://megasam24.pl/baton-mango-bez-dodatku-cukru-35-g', |
| 76 | + }, |
| 77 | + { |
| 78 | + store: 'leclerc-online.pl', |
| 79 | + product: 'Dolina Noteci Premium Sterilised Danie z kaczki dla kota 85g', |
| 80 | + ean: '5902921303213', |
| 81 | + url: 'https://leclerc-online.pl/dolina-noteci-premium-sterilised-danie-z-kaczki-dla-kota-85g', |
| 82 | + } |
| 83 | +]; |
| 84 | + |
57 | 85 | test.describe('EAN detection on real product pages', () => { |
58 | 86 |
|
59 | | - test('frisco.pl — Makłowicz oliwa z oliwek → EAN 5905644030022', async ({ page }) => { |
60 | | - await page.goto( |
61 | | - 'https://www.frisco.pl/pid,145610/n,maklowicz-i-synowie-oliwa-z-oliwek-extra-vergine/stn,product', |
62 | | - { waitUntil: 'domcontentloaded' } |
63 | | - ); |
| 87 | + for (const { store, product, ean, url } of productPages) { |
| 88 | + test(`${store} — ${product} → EAN ${ean}`, async ({ page }) => { |
| 89 | + await page.goto(url, { waitUntil: 'domcontentloaded' }); |
64 | 90 |
|
65 | | - const messages = await injectContentScript(page); |
| 91 | + const messages = await injectContentScript(page); |
66 | 92 |
|
67 | | - // Content script powinien znaleźć dokładnie 1 EAN i wysłać { type: 'ean', result: '...' } |
68 | | - // LUB znaleźć wiele i wysłać { type: 'multiple', result: [...] } |
69 | | - const eanMessage = messages.find(m => m.type === 'ean'); |
70 | | - const multipleMessage = messages.find(m => m.type === 'multiple'); |
71 | | - |
72 | | - if (eanMessage) { |
73 | | - expect(eanMessage.result).toBe('5905644030022'); |
74 | | - } else if (multipleMessage) { |
75 | | - expect(multipleMessage.result).toContain('5905644030022'); |
76 | | - } else { |
77 | | - // Jeśli nie znaleziono — test powinien sfailować z czytelnym komunikatem |
78 | | - throw new Error( |
79 | | - `Content script nie znalazł EAN 5905644030022 na stronie frisco.pl. ` + |
80 | | - `Przechwycone wiadomości: ${JSON.stringify(messages)}` |
81 | | - ); |
82 | | - } |
83 | | - }); |
| 93 | + const eanMessage = messages.find(m => m.type === 'ean'); |
| 94 | + const multipleMessage = messages.find(m => m.type === 'multiple'); |
84 | 95 |
|
| 96 | + if (eanMessage) { |
| 97 | + expect(eanMessage.result).toBe(ean); |
| 98 | + } else if (multipleMessage) { |
| 99 | + expect(multipleMessage.result).toContain(ean); |
| 100 | + } else { |
| 101 | + throw new Error( |
| 102 | + `Content script nie znalazł EAN ${ean} na stronie ${store}. ` + |
| 103 | + `Przechwycone wiadomości: ${JSON.stringify(messages)}` |
| 104 | + ); |
| 105 | + } |
| 106 | + }); |
| 107 | + } |
85 | 108 | }); |
0 commit comments