我一直在尝试使用此页面中的Selenium示例:https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Your_own_automation_environment。
我已完成以下步骤:
npm install selenium-webdriver
然后我创建了示例google_test.js的本地副本(如下所示)并使用命令node google_test
运行它。
var webdriver = require('selenium-webdriver'), 通过= webdriver.By, until = webdriver.until;
var driver = new webdriver.Builder() .forBrowser( '火狐') .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'))点击();
driver.sleep(2000).then(function(){ driver.getTitle()。then(function(title){ if(title ==='webdriver - Google Search'){ console.log('测试通过'); } else { console.log('测试失败'); } }); });
driver.quit();
我的问题是,对我来说,上面的例子只会打开一个新的Firefox实例,并立即关闭而不执行任何操作。
运行命令node google_test
后,我收到以下错误消息:
(node:23652) UnhandledPromiseRejectionWarning: SessionNotCreatedError: Tried to run command without establishing a connection
at Object.throwDecodedError (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/error.js:550:15)
at parseHttpResponse (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/http.js:542:13)
at Executor.execute (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/http.js:468:26)
at process._tickCallback (internal/process/next_tick.js:178:7)
(node:23652) 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: 1)
(node:23652) [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:23652) UnhandledPromiseRejectionWarning: SessionNotCreatedError: Tried to run command without establishing a connection
at Object.throwDecodedError (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/error.js:550:15)
at parseHttpResponse (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/http.js:542:13)
at Executor.execute (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/http.js:468:26)
at process._tickCallback (internal/process/next_tick.js:178:7)
(node:23652) 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:23652) UnhandledPromiseRejectionWarning: SessionNotCreatedError: Tried to run command without establishing a connection
at Object.throwDecodedError (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/error.js:550:15)
at parseHttpResponse (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/http.js:542:13)
at Executor.execute (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/http.js:468:26)
at process._tickCallback (internal/process/next_tick.js:178:7)
(node:23652) 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:23652) UnhandledPromiseRejectionWarning: SessionNotCreatedError: Tried to run command without establishing a connection
at Object.throwDecodedError (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/error.js:550:15)
at parseHttpResponse (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/http.js:542:13)
at Executor.execute (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/http.js:468:26)
at process._tickCallback (internal/process/next_tick.js:178:7)
(node:23652) 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: 5)
(node:23652) UnhandledPromiseRejectionWarning: SessionNotCreatedError: Tried to run command without establishing a connection
at Object.throwDecodedError (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/error.js:550:15)
at parseHttpResponse (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/http.js:542:13)
at Executor.execute (/home/hanbin/programman/webdev/selenium-test/node_modules/selenium-webdriver/lib/http.js:468:26)
at process._tickCallback (internal/process/next_tick.js:178:7)
(node:23652) 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: 6)
我的package.json文件是:
{
"name": "selenium-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"selenium-webdriver": "^4.0.0-alpha.1"
}
}
有人可以帮助我吗?