Я пытался запустить свои тесты Selenium на AWS Lambda со временем выполнения Node.js 12.x, но я столкнулся с ошибкой.
{
"errorType": "Error",
"errorMessage": "The ChromeDriver could not be found on the current PATH. Please download the latest version of the ChromeDriver from http://chromedriver.storage.googleapis.com/index.html and ensure it can be found on your PATH.",
"trace": [
"Error: The ChromeDriver could not be found on the current PATH. Please download the latest version of the ChromeDriver from http://chromedriver.storage.googleapis.com/index.html and ensure it can be found on your PATH.",
" at new ServiceBuilder (/var/task/aws-Lambda-Selenium-2.0/node_modules/selenium-webdriver/chrome.js:232:13)",
" at getDefaultService (/var/task/aws-Lambda-Selenium-2.0/node_modules/selenium-webdriver/chrome.js:321:22)",
" at Function.createSession (/var/task/aws-Lambda-Selenium-2.0/node_modules/selenium-webdriver/chrome.js:695:44)",
" at createDriver (/var/task/aws-Lambda-Selenium-2.0/node_modules/selenium-webdriver/index.js:155:33)",
" at Builder.build (/var/task/aws-Lambda-Selenium-2.0/node_modules/selenium-webdriver/index.js:662:16)",
" at Runtime.module.exports.testFn [as handler] (/var/task/aws-Lambda-Selenium-2.0/handler.js:35:32)",
" at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
]
}
Я знаю, что на аналогичный вопрос недавно был дан ответ, но я использовал пакет chrome-aws-lambda
npm, но он все еще не работает. Моя функция Lambda Имеется 2 ГБ памяти, и я ограничил время ожидания до 5 минут. Ниже я разместил код моего handler.js
. Любая помощь будет принята с благодарностью.
'use strict';
module.exports.testFn = async (event, context, callback) =>
{
const webdriver = require("selenium-webdriver");
const chrome = require('selenium-webdriver/chrome');
const builder = new webdriver.Builder().forBrowser('chrome');
const chromeOptions = new chrome.Options();
const defaultChromeFlags =
[
'--headless',
'--disable-gpu',
'--disable-dev-shm-usage',
'--window-size=1280x1696',
'--no-sandbox',
'--user-data-dir=/tmp/user-data',
'--hide-scrollbars',
'--enable-logging',
'--log-level=0',
'--v=99',
'--single-process',
'--data-path=/tmp/data-path',
'--ignore-certificate-errors',
'--homedir=/tmp',
'--disk-cache-dir=/tmp/cache-dir'
];
const HEADLESS_CHROME_PATH = '/var/task/aws-Lambda-Selenium-2.0/node_modules/chrome-aws-lambda/bin/chromium.br';
chromeOptions.setChromeBinaryPath(HEADLESS_CHROME_PATH);
chromeOptions.addArguments(defaultChromeFlags);
builder.setChromeOptions(chromeOptions);
let driver = await builder.build(); // <-- program is not getting passed this line
await driver.get("https://www.google.com/");
await driver.getTitle().then(() =>
{
console.log("Page title for " + "https://www.google.com/" + " is ");
});
await driver.quit();
}