我正在尝试从webdriverIO运行测试脚本。
这是代码:
var webdriverio = require('webdriverio');
var options = {
desiredCapabilities: {
browserName: 'chrome'
}
};
webdriverio
.remote(options)
.init()
.url('http://www.google.com')
.getTitle().then(function(title) {
console.log('Title was: ' + title);
})
.end()
.catch(function(err) {
console.log(err);
});
当我运行这个时,我会收到我无法理解的错误。 这就是Node告诉我的:
C:\...\webdriverio-node>node test.js
{ Error: A new session could not be created.
at end() - C:\...\webdriverio-node\test.js:15:6
details: undefined,
message: 'Unable to create session from org.openqa.selenium.remote.NewSessionP
ayload@25bd2276\nBuild info: version: \'3.11.0\', revision: \'e59cfb3\', time: \
'2018-03-11T20:33:15.31Z\'\nSystem info: host: \'USER-PC\', ip: \'\', os.name: \'Windows 7\', os.arch: \'amd64\', os.version: \'6.1\', java.vers
ion: \'1.8.0_171\'\nDriver info: driver.version: unknown',
type: 'RuntimeError',
seleniumStack:
{ type: 'SessionNotCreatedException',
message: 'A new session could not be created.',
orgStatusMessage: 'Unable to create session from org.openqa.selenium.remote
.NewSessionPayload@25bd2276\nBuild info: version: \'3.11.0\', revision: \'e59cfb
3\', time: \'2018-03-11T20:33:15.31Z\'\nSystem info: host: \'USER-PC\', ip: \'\', os.name: \'Windows 7\', os.arch: \'amd64\', os.version: \'6.1\
', java.version: \'1.8.0_171\'\nDriver info: driver.version: unknown' } }
这是我从selenium-server-standalone获得的消息:
16:49:43.014 INFO [ActiveSessionFactory.apply] - Capabilities are: Capabilities
{browserName: chrome, handlesAlerts: true, javascriptEnabled: true, locationCont
extEnabled: true, loggingPrefs: org.openqa.selenium.logging..., requestOrigins:
{name: webdriverio, url: http://webdriver.io, version: 4.12.0}, rotatable: true}
16:49:43.016 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.o
penqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selen
ium.chrome.ChromeDriverService)
当我将第4行从代码更改为:
browserName: 'firefox'
这是Node.js生成的错误:
C:\...\webdriverio-node>node test.js
{ Error: An unknown server-side error occurred while processing the command.
at end() - C:\...\webdriverio-node\test.js:15:6
details: undefined,
message: 'Process unexpectedly closed with status -1073741511\nBuild info: ver
sion: \'3.11.0\', revision: \'e59cfb3\', time: \'2018-03-11T20:33:15.31Z\'\nSyst
em info: host: \'USER-PC\', ip: \'\', os.name: \'Windows 7\', os
.arch: \'amd64\', os.version: \'6.1\', java.version: \'1.8.0_171\'\nDriver info:
driver.version: unknown\nremote stacktrace: ',
type: 'RuntimeError',
seleniumStack:
{ type: 'UnknownError',
message: 'An unknown server-side error occurred while processing the comman
d.',
orgStatusMessage: 'Process unexpectedly closed with status -1073741511\nBui
ld info: version: \'3.11.0\', revision: \'e59cfb3\', time: \'2018-03-11T20:33:15
.31Z\'\nSystem info: host: \'USER-PC\', ip: \'\', os.name: \'Win
dows 7\', os.arch: \'amd64\', os.version: \'6.1\', java.version: \'1.8.0_171\'\n
Driver info: driver.version: unknown\nremote stacktrace: ' } }
这就是selenium-server-standalone告诉我的:
16:50:53.332 INFO [ActiveSessionFactory.apply] - Capabilities are: Capabilities
{browserName: firefox, handlesAlerts: true, javascriptEnabled: true, locationCon
textEnabled: true, loggingPrefs: org.openqa.selenium.logging..., requestOrigins:
{name: webdriverio, url: http://webdriver.io, version: 4.12.0}, rotatable: true
}
16:50:53.335 INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.o
penqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selen
ium.firefox.GeckoDriverService)
1524577853389 geckodriver INFO geckodriver 0.20.0
1524577853399 geckodriver INFO Listening on 127.0.0.1:42211
1524577854396 mozrunner::runner INFO Running command: "C:\\Program Fi
les (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" "C:\\Users\\Us
er\\AppData\\Local\\Temp\\rust_mozprofile.oSWu443RM4TY"
我使用的是selenium-server-standalone-3.11.0.jar
答案 0 :(得分:1)
这是因为找不到合适的二进制文件。查看webdriver.io的这个Setup-Chrome部分
使用最新版本的Selenium,浏览器的大多数驱动程序都带有一个必须下载和设置的外部驱动程序。
从操作系统的chromedriver下载最新版本的chromedriver,并将其放在与ur test.js相同的位置,或在Windows中设置PATH。它将被自动拾取。我只用chrome尝试过它,并且能够成功执行你的代码。
我个人使用webdriver-manager来管理二进制文件
npm install webdriver-manager
webdriver-manager update
webdriver-manager start
这将设置所有必需的二进制驱动程序以连接到浏览器
答案 1 :(得分:0)
我能够解决firefox部分,只是重新安装Firefox,因为浏览器安装已损坏。
不幸但是,我很失望,在我取回我的结果之前,WebdriverIO催生了Firefox浏览器。
我不知道是否可以在无头模式下运行它。