From 4c08724f78775afdb54110171c15a24ce4ab8d7e Mon Sep 17 00:00:00 2001 From: Paul Bauer Date: Fri, 1 May 2020 20:40:35 +1000 Subject: [PATCH] added hacks to work with AC --- package.json | 2 +- src/Engine.js | 2 ++ src/Searcher.js | 11 ++++++++++- src/engines/ac/searcher.js | 6 ++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 35bd3ae..84ff028 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "moment-timezone": "^0.5.26", "mssql": "^5.1.0", "parse-duration": "^0.1.1", - "puppeteer": "^1.18.1", + "puppeteer": "^1.20.0", "shelljs": "^0.8.3", "prompt-sync": "^4.1.7", "timetable-fns": "^0.1.16", diff --git a/src/Engine.js b/src/Engine.js index 2d1a71e..d3b7f22 100644 --- a/src/Engine.js +++ b/src/Engine.js @@ -201,6 +201,8 @@ class Engine { } if (docker) { args.push('--no-sandbox', '--headless', '--disable-dev-shm-usage') + } else { + args.push('--no-sandbox') } if (remoteAddress === "") { diff --git a/src/Searcher.js b/src/Searcher.js index 246c9f2..ef7e0ef 100644 --- a/src/Searcher.js +++ b/src/Searcher.js @@ -160,7 +160,16 @@ class Searcher { return page.evaluate((values) => { for (var key in values) { if (values.hasOwnProperty(key)) { - const arr = document.getElementsByName(key) + + // AC has same name both one-way and round-trip option buttons (tripTypeRoundTrip) + // so for this, use value instead + var arr; + if (key=="tripTypeOneWay") { + arr = [ document.getElementById('tripTypeRoundTrip2') ] + } else { + arr = document.getElementsByName(key) + } + if (arr.length === 0) { throw new Error(`Missing form element: ${key}`) } diff --git a/src/engines/ac/searcher.js b/src/engines/ac/searcher.js index 1210628..5ff1b26 100644 --- a/src/engines/ac/searcher.js +++ b/src/engines/ac/searcher.js @@ -28,6 +28,12 @@ module.exports = class extends Searcher { } await this.clickAndWait('button.btn-primary.form-login-submit') + // aeroplans new website is SUPER slow, and navigates multiple times before login dance is done + // so the hacky workaround is to just wait... + await page.waitFor(10000) + + // TODO: check if the "verify your email" dialog is appearing for new accounts, since it'll never work in that case... + // Check for errors const msgError = await this.textContent('div.form-msg-box.has-error span.form-msg') if (msgError.includes('does not match our records')) {