web-dev-qa-db-fra.com

Comment configurer correctement Selenium pour Firefox dans Kubuntu 18.04

pour un prochain projet d’automatisation, je souhaite utiliser Selenium pour Firefox. J'ai suivi CE GUIDE . Maintenant, lorsque je veux exécuter le script mentionné à partir de ce guide en utilisant 'node /path/to/script/scriptName.js, une fenêtre Firefox s'ouvre pendant une milliseconde et se ferme immédiatement. Jusqu'ici, le script consiste uniquement à copier/coller le contenu du guide.

Node/npm et webdriver ont été installés avec succès. geckodriver se trouve dans le répertoire '/ home' et placé dans '$ PATH'.

var webdriver = require('Selenium-webdriver'),
    By = webdriver.By,
    until = webdriver.until;

var driver = new webdriver.Builder()
    .forBrowser('firefox')
    .build();

driver.get('http://www.google.com');

driver.findElement(By.name('q')).sendKeys('webdriver');

driver.sleep(1000).then(function() {
  driver.findElement(By.name('q')).sendKeys(webdriver.Key.TAB);
});

driver.findElement(By.name('btnK')).click();

driver.sleep(2000).then(function() {
  driver.getTitle().then(function(title) {
    if(title === 'webdriver - Google Search') {
      console.log('Test passed');
    } else {
      console.log('Test failed');
    }
  });
});

driver.quit();

La console génère alors beaucoup d’erreurs, mais je ne suis pas en mesure de lire, ce qui ne fonctionne pas correctement ici. Quelqu'un peut-il me dire ce que j'ai pu manquer?

node ~/projects/googleTest.js
(node:21344) UnhandledPromiseRejectionWarning: SessionNotCreatedError: Tried to run command without establishing a connection
    at Object.throwDecodedError (/home/ruphus/node_modules/Selenium-webdriver/lib/error.js:550:15)
    at parseHttpResponse (/home/ruphus/node_modules/Selenium-webdriver/lib/http.js:542:13)
    at Executor.execute (/home/ruphus/node_modules/Selenium-webdriver/lib/http.js:468:26)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
(node:21344) 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)
(node:21344) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:21344) UnhandledPromiseRejectionWarning: SessionNotCreatedError: Tried to run command without establishing a connection
    at Object.throwDecodedError (/home/ruphus/node_modules/Selenium-webdriver/lib/error.js:550:15)
    at parseHttpResponse (/home/ruphus/node_modules/Selenium-webdriver/lib/http.js:542:13)
    at Executor.execute (/home/ruphus/node_modules/Selenium-webdriver/lib/http.js:468:26)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
(node:21344) 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: 3)
(node:21344) UnhandledPromiseRejectionWarning: SessionNotCreatedError: Tried to run command without establishing a connection
    at Object.throwDecodedError (/home/ruphus/node_modules/Selenium-webdriver/lib/error.js:550:15)
    at parseHttpResponse (/home/ruphus/node_modules/Selenium-webdriver/lib/http.js:542:13)
    at Executor.execute (/home/ruphus/node_modules/Selenium-webdriver/lib/http.js:468:26)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
(node:21344) 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: 4)
(node:21344) UnhandledPromiseRejectionWarning: NoSuchSessionError: This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used.
    at promise.finally (/home/ruphus/node_modules/Selenium-webdriver/lib/webdriver.js:726:38)
    at Object.thenFinally [as finally] (/home/ruphus/node_modules/Selenium-webdriver/lib/promise.js:124:12)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
(node:21344) 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: 8)
1
r. roger

J'ai trouvé une solution de contournement consistant à installer une version plus ancienne de Selenium-webdriver dans cette menace .

npm i [email protected]

1
r. roger