|
1 | | -const { chromium } = require('playwright'); |
2 | | -// const { test, expect } = require('@playwright/test'); |
3 | | - |
4 | | -let headless = false, host = 'localhost', port = '8080', mode = false; |
5 | | -process.argv.forEach(a => { |
6 | | - if (/^--headless/.test(a)) { |
7 | | - headless = true; |
8 | | - } else if (/^--port=/.test(a)) { |
9 | | - port = a.split('=')[1]; |
10 | | - } else if (/^--mode=/.test(a)) { |
11 | | - mode = a.split('=')[1]; |
12 | | - } |
13 | | -}); |
| 1 | +const { log, args, createPage, closePage, takeScreenshot, waitForServerReady, dismissDevmode } = require('./test-utils'); |
14 | 2 |
|
15 | 3 | (async () => { |
16 | | - const browser = await chromium.launch({ |
17 | | - headless: headless, |
18 | | - chromiumSandbox: false |
19 | | - }); |
20 | | - const sleep = ms => new Promise(r => setTimeout(r, ms)); |
21 | | - |
22 | | - const context = await browser.newContext(); |
23 | | - |
24 | | - const page = await context.newPage(); |
25 | | - page.on('console', msg => console.log("> CONSOLE:", (msg.text() + ' - ' + msg.location().url).replace(/\s+/g, ' '))); |
26 | | - page.on('pageerror', err => console.log("> PAGEERROR:", ('' + err).replace(/\s+/g, ' '))); |
27 | | - |
28 | | - await page.goto(`http://${host}:${port}/`); |
29 | | - |
30 | | - await page.getByLabel('Input Text').fill('Jose Macias Pajas\t\t\tFactura / Invoice\t\t\nNIF: 111222333-S\t \t\t\tFecha / Date\t25 jul 2021\nEU VAT: FR111222333S\t\t\t\tFact.Núm / Invoice #\t12345\nIrlandeses, 7\t \t\t\t\t\n28800, AH, MAD, ES\t\t\t\t\t\n(+34) 653454512\n\t\t\t\t\t\nPara / Bill for\t\t\t\t\t\nPickup Oy\t\t\t\t\t\nFI3456\nRoad Ji 2-4\t\t\t\t\t\nHelsinki, Finland. FI.\t\t\t\t\t\n\t\t\t\t\t\nDescripción / Description\t\t\tCant. / Q.\tPrecio / Rate\tImporte / Amount\n\t\t\t\t\t\nSoftware Development Services\t\t\t1\t3.000,00 €\t3.000,00 €\n\t\t\t\t\t\nInternet Connection costs\t\t\t1\t13,89 €\t13,89 €\n\t\t\t\t\t\nHealth Insurance costs\t\t\t1\t40,16 €\t40,16 €\n\t\t\t\t\t\nTrips & Extra costs\t\t\t1\t\t50,00 €\n\t\t\t\t\t\n\t\t\t\tVAT\t50 €\n\t\t\t\tTotal\t7.439,05 €\n\t\t\t\t\t\nE-mail: aaa@example.org\t\t\t\t\t'); |
31 | | - await page.getByRole('button', { name: 'Fill the form' }).locator('span').nth(1).click(); |
32 | | - |
33 | | - await new Promise(async (resolve, reject) => { |
34 | | - for (let i=1; i<10; i++) { |
35 | | - const txt = await page.getByLabel('Order total').inputValue(); |
36 | | - if (txt == '7439.05') { |
37 | | - resolve('ok'); |
38 | | - return; |
39 | | - } |
40 | | - await sleep(3000); |
41 | | - } |
42 | | - reject('timeout'); |
43 | | - }); |
44 | | - |
45 | | - await context.close(); |
46 | | - await browser.close(); |
| 4 | + const arg = args(); |
| 5 | + |
| 6 | + const page = await createPage(arg.headless); |
| 7 | + const sleep = ms => new Promise(r => setTimeout(r, ms)); |
| 8 | + |
| 9 | + await waitForServerReady(page, arg.url); |
| 10 | + |
| 11 | + // Dismiss dev mode notification if present |
| 12 | + await dismissDevmode(page); |
| 13 | + await takeScreenshot(page, __filename, 'page-loaded'); |
| 14 | + |
| 15 | + log('Testing AI form filling functionality'); |
| 16 | + await page.getByLabel('Input Text').fill('Jose Macias Pajas\t\t\tFactura / Invoice\t\t\nNIF: 111222333-S\t \t\t\tFecha / Date\t25 jul 2021\nEU VAT: FR111222333S\t\t\t\tFact.Núm / Invoice #\t12345\nIrlandeses, 7\t \t\t\t\t\n28800, AH, MAD, ES\t\t\t\t\t\n(+34) 653454512\n\t\t\t\t\t\nPara / Bill for\t\t\t\t\t\nPickup Oy\t\t\t\t\t\nFI3456\nRoad Ji 2-4\t\t\t\t\t\nHelsinki, Finland. FI.\t\t\t\t\t\n\t\t\t\t\t\nDescripción / Description\t\t\tCant. / Q.\tPrecio / Rate\tImporte / Amount\n\t\t\t\t\t\nSoftware Development Services\t\t\t1\t3.000,00 €\t3.000,00 €\n\t\t\t\t\t\nInternet Connection costs\t\t\t1\t13,89 €\t13,89 €\n\t\t\t\t\t\nHealth Insurance costs\t\t\t1\t40,16 €\t40,16 €\n\t\t\t\t\t\nTrips & Extra costs\t\t\t1\t\t50,00 €\n\t\t\t\t\t\n\t\t\t\tVAT\t50 €\n\t\t\t\tTotal\t7.439,05 €\n\t\t\t\t\t\nE-mail: aaa@example.org\t\t\t\t\t'); |
| 17 | + await takeScreenshot(page, __filename, 'form-text-filled'); |
| 18 | + |
| 19 | + await page.getByRole('button', { name: 'Fill the form' }).locator('span').nth(1).click(); |
| 20 | + await takeScreenshot(page, __filename, 'fill-form-clicked'); |
| 21 | + |
| 22 | + log('Waiting for AI to process and fill the form'); |
| 23 | + await new Promise(async (resolve, reject) => { |
| 24 | + for (let i=1; i<10; i++) { |
| 25 | + const txt = await page.getByLabel('Order total').inputValue(); |
| 26 | + if (txt == '7439.05') { |
| 27 | + log('AI form filling completed successfully'); |
| 28 | + await takeScreenshot(page, __filename, 'ai-form-filled'); |
| 29 | + resolve('ok'); |
| 30 | + return; |
| 31 | + } |
| 32 | + await sleep(3000); |
| 33 | + } |
| 34 | + reject('timeout'); |
| 35 | + }); |
| 36 | + |
| 37 | + log('AI test completed successfully'); |
| 38 | + await closePage(page); |
47 | 39 | })(); |
0 commit comments