Я установил веб-драйвер селена
`npm install selenium-webdriver`
и драйвер хрома
npm install chromedriver
Пакет. Json выглядитвот так
{
"name": "todoperformancetest",
"version": "1.0.0",
"description": "selenium test",
"main": "index.js",
"scripts": {
"test": "node indes.js",
"start": "node index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/steinko/TodoPerformanceTest.git"
},
"author": "steinko",
"license": "ISC",
"bugs": {
"url": "https://github.com/steinko/TodoPerformanceTest/issues"
},
"homepage": "https://github.com/steinko/TodoPerformanceTest#readme",
"dependencies": {
"chromedriver": "^73.0.0",
"selenium-webdriver": "^4.0.0-alpha.1"
}
}
драйвер chrome также установлен в / application мой путь
echo $ PATH
/Library/Frameworks/Python.framework/Versions/3.7/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/Applications/google-cloud-sdk/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/Users/stein/.sdkman/candidates/groovy/current/bin:/usr/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications:/Applications/sonar-scanner-3.2.0.1227-macosx/bin:/Applications/chromedriver:/opt/gradle/gradle-4.7/bin
Я также создал .npmrc, содержащий
chromedriver_force_download=true
Тест на селен выглядит следующим образом:
"use strict"
require('chromedriver')
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder()
.forBrowser('chrome')
.build()
console.log(driver.session_id)
driver.get('http://www.google.com')
var element = driver.findElement(webdriver.By.name('q'));
element.sendKeys('Cheese!');
element.submit();
driver.getTitle().then(function(title) {
console.log('Page title is: ' + title);
});
driver.wait(function() {
return driver.getTitle().then(function(title) {
return title.toLowerCase().lastIndexOf('cheese!', 0) === 0;
});
}, 3000);
driver.getTitle().then(function(title) {
console.log('Page title is: ' + title);
});
driver.quit();
Когда я выполняю команду запуска npm, я получаю следующеесообщение об ошибке: Steins-MacBook-Pro-2: TodoPerformanceTest stein $ npm start
> todoperformancetest@1.0.0 start /Users/stein/Development/ReactSpringBooTutorial/TodoPerformanceTest
> node index.js
undefined
Page title is:
Page title is:
(node:32072) UnhandledPromiseRejectionWarning: NoSuchSessionError: invalid session id
(Driver info: chromedriver=73.0.3683.20 (8e2b610813e167eee3619ac4ce6e42e3ec622017),platform=Mac OS X 10.14.3 x86_64)
at Object.checkLegacyResponse (/Users/stein/Development/ReactSpringBooTutorial/TodoPerformanceTest/node_modules/selenium-webdriver/lib/error.js:585:15)
at parseHttpResponse (/Users/stein/Development/ReactSpringBooTutorial/TodoPerformanceTest/node_modules/selenium-webdriver/lib/http.js:533:13)
at Executor.execute (/Users/stein/Development/ReactSpringBooTutorial/TodoPerformanceTest/node_modules/selenium-webdriver/lib/http.js:468:26)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:32072) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
Как настроить и запустить селен в Chrome?