From 1b4b68213eb4c1e3d0c02c3efaef88af05f5c663 Mon Sep 17 00:00:00 2001 From: Pete Freitag Date: Mon, 2 Oct 2023 15:30:53 -0400 Subject: [PATCH] update puppeteer test --- tests/puppeteer/test.js | 71 ++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/tests/puppeteer/test.js b/tests/puppeteer/test.js index a10b973..2c350dc 100644 --- a/tests/puppeteer/test.js +++ b/tests/puppeteer/test.js @@ -1,41 +1,48 @@ const puppeteer = require('puppeteer'); +const process = require('node:process'); (async() => { - - const browser = await puppeteer.launch(); - - const page = await browser.newPage(); - await page.goto('http://127.0.0.1:8855/', {waitUntil: 'load'}); - console.log(page.url()); - - await page.type('#x', '5'); - await page.type('#y', '3'); - - await page.click('#addButton'); - - setTimeout(async()=> { - const answer = await page.$eval('#z', el => { return el.value } ); - - await page.screenshot({path: 'screenshot.png'}); - if (answer == "8") { - console.log("Value Was 8"); - await browser.close(); - process.exit(0); - } else { - console.log("Value was not 8, it was: " + answer); - await browser.close(); - process.exit(1); - } + console.log('starting puppeteer script'); + try { + const browser = await puppeteer.launch(); + + const page = await browser.newPage(); + await page.goto('http://127.0.0.1:8855/', {waitUntil: 'load'}); + console.log(page.url()); + + await page.type('#x', '5'); + await page.type('#y', '3'); + + await page.click('#addButton'); + + setTimeout(async()=> { + const answer = await page.$eval('#z', el => { return el.value } ); + + await page.screenshot({path: 'screenshot.png'}); + if (answer == "8") { + console.log("Value Was 8"); + await browser.close(); + process.exit(0); + } else { + console.log("Value was not 8, it was: " + answer); + await browser.close(); + process.exit(1); + } + + }, 500); - }, 200); - - setTimeout(()=> { - console.log("15 Second Timeout Reached"); - browser.close(); - process.exit(1); - }, 15000); + setTimeout(()=> { + console.log("15 Second Timeout Reached"); + browser.close(); + process.exit(1); + }, 15000); + } catch (err) { + console.log('Error running puppeteer'); + console.error(err); + process.exit(1); + } })(); \ No newline at end of file