typescript 会话未在量角器中为 chrome 创建异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40100960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
session not created exception for chrome in Protractor
提问by SMPH
I get below error when try to run Protractor test against chrome.
尝试针对 chrome 运行 Protractor 测试时出现以下错误。
My conf.ts
我的配置文件
import {Config} from 'protractor'
export let config: Config = {
framework: 'jasmine',
// capabilities: { browserName: 'chrome'},
multiCapabilities: [
// {browserName: 'firefox'},
{
browserName: 'chrome',
chromeOptions: {
args: ['--start-maximized']
},
}],
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
seleniumPort: null,
seleniumArgs: [],
specs: [
'./Protractor/Login/*.spec.js',
Error:
错误:
Protractor conf.js
[17:19:07] I/hosted - Using the selenium server at http://127.0.0.1:4444/wd/hub
[17:19:07] I/launcher - Running 1 instances of WebDriver
[17:19:09] E/launcher - session not created exception
from unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"8800.1","isDefault":true},"id":1,"name":"","origin":"://"}
(Session info: chrome=54.0.2840.59)
(Driver info: chromedriver=2.22.397933 (1cab651507b88dec79b2b2a22d1943c01833cc1b),platform=Windows NT 6.3.9600 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.07 seconds
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
System info: host: 'MAL000009416062', ip: '192.168.1.4', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_73'
Driver info: org.openqa.selenium.chrome.ChromeDriver
[17:19:09] E/launcher - SessionNotCreatedError: session not created exception
from unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"8800.1","isDefault":true},"id":1,"name":"","origin":"://"}
(Session info: chrome=54.0.2840.59)
(Driver info: chromedriver=2.22.397933 (1cab651507b88dec79b2b2a22d1943c01833cc1b),platform=Windows NT 6.3.9600 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.07 seconds
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
System info: host: 'MAL000009416062', ip: '192.168.1.4', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_73'
Driver info: org.openqa.selenium.chrome.ChromeDriver
at WebDriverError (C:\Users2811\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\error.js:27:5)
at SessionNotCreatedError (C:\Users2811\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\error.js:308:5)
conf.ts
配置文件
multiCapabilities: [
{
browserName: 'chrome',
chromeOptions: {
args: ['--start-maximized']
},
}],
Most of the discussion on the web is around version. I am currently using up-to-date versions
网络上的大部分讨论都是围绕版本进行的。我目前使用的是最新版本
Any clue please?
请问有什么线索吗?
Cheers
干杯
回答by Sudharsan Selvaraj
You can change the version of chromedriver downloaded by webdriver-manager by altering Protractor's config.json file...
您可以通过更改 Protractor 的 config.json 文件来更改 webdriver-manager 下载的 chromedriver 版本...
- Edit Protractor's config file: node_modules/protractor/config.json
- Change the chrome driver version to whatever you need. eg. "chromedriver": "2.24".
- Run webdriver-manager update.
- 编辑量角器的配置文件:node_modules/protractor/config.json
- 将 chrome 驱动程序版本更改为您需要的任何版本。例如。“chromedriver”:“2.24”。
- 运行 webdriver-manager 更新。
from the error you posted, protractor is not using the latest chrome driver version.In stack trace it is displaying chrome driver version as 2.21
.
根据您发布的错误,量角器未使用最新的 chrome 驱动程序版本。在堆栈跟踪中,它将 chrome 驱动程序版本显示为2.21
.
回答by tehbeardedone
I don't have enough rep yet to leave a comment under Sudharsan's answer but the location of the config file he is telling you to modify is actually at
我还没有足够的代表在 Sudharsan 的回答下发表评论,但他告诉您要修改的配置文件的位置实际上位于
node_modules/protractor/node_modules/webdriver-manager/config.json
It's not the protractor tsconfig but the webdriver-manager config.json
that you want to modify.
config.json
您要修改的不是量角器 tsconfig,而是 webdriver-manager 。
That being said, I've run into this problem before and taken a different approach to solving it. The solution that Sudharsan provided would work if you only needed to install it once. We have our builds running in TFS which cleans out the build agents working directory and pulls in a fresh repo on each build. Changing the webdriver config would not work in this situation because we npm install
all the things before each build. In this case it would always revert back to the older version of chromedriver.
话虽如此,我之前遇到过这个问题,并采取了不同的方法来解决它。如果您只需要安装一次,Sudharsan 提供的解决方案就会起作用。我们在 TFS 中运行我们的构建,它会清除构建代理工作目录并在每次构建时引入一个新的存储库。在这种情况下,更改 webdriver 配置不起作用,因为我们npm install
在每次构建之前都会进行所有操作。在这种情况下,它总是会恢复到旧版本的 chromedriver。
What I did instead was added chromedriver to my devDependencies in the package.json
and then I delete the version of chromedriver that webdriver-manager installs and move the updated version of chromedriver into the correct location with a gulp task. So in the package.json I have this listed under devDependencies:
我所做的是将 chromedriver 添加到我的 devDependencies 中package.json
,然后我删除了 webdriver-manager 安装的 chromedriver 版本,并使用 gulp 任务将 chromedriver 的更新版本移动到正确的位置。所以在 package.json 中,我在 devDependencies 下列出了这个:
"chromedriver": "~2.24.1"
and then I have a gulp task that deletes and moves the files like this:
然后我有一个 gulp 任务来删除和移动这样的文件:
var gulp = require('gulp');
var del = require('del');
var chromeDriverFilesToMove = [
'./node_modules/chromedriver/lib/chromedriver/**'
];
var chromeDriverFilesToDelete = [
'./node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver*.exe',
'./node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver*.zip'
];
gulp.task('delete-chromedriver', function() {
return del(chromeDriverFilesToDelete);
});
gulp.task('move-chromedriver', function() {
gulp.src(chromeDriverFilesToMove)
.pipe(gulp.dest('node_modules/protractor/node_modules/webdriver-manager/selenium/'));
});
gulp.task('chromedriver-update', ['delete-chromedriver', 'move-chromedriver']);
And because protractor will still be looking for the older version of chromedriver that was installed when you ran webdriver-manager update
you have to tell it where to look for the chromedriver.exe so add this to your protractor conf.js and it should start working.
并且因为量角器仍然会寻找在您运行时安装的旧版本 chromedriver,所以webdriver-manager update
您必须告诉它在哪里寻找 chromedriver.exe,因此将它添加到您的量角器 conf.js 中,它应该开始工作。
chromeDriver: "../node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver.exe",
It's kind of silly that we have to go through all this trouble to get it to work but chromedriver 2.22 doesn't seem to work with Chrome 53+. At least not in my experience.
我们必须经历所有这些麻烦才能让它工作,但 chromedriver 2.22 似乎不适用于 Chrome 53+,这有点愚蠢。至少在我的经验中不是。
TL;DR
TL; 博士
If you only have to install it once use Sudharsan's solution (given you modify the correct config), it's easier. If you are in my situation and will have to install protractor continuously try my solution. It has worked well for me and I haven't run into this error since.
如果您只需要安装一次,使用 Sudharsan 的解决方案(假设您修改了正确的配置),那就更容易了。如果您处于我的情况并且必须不断安装量角器,请尝试我的解决方案。它对我来说效果很好,从那以后我就没有遇到过这个错误。
回答by Marc Stober
I just needed to:
我只需要:
npm update -g protractor
webdriver-manager update
And it worked again.
它又奏效了。
回答by Sevfuria
Protractor has a new release (4.0.10) that will use the new release of webdriver-manager (10.2.6), which in turn will update to the new Chromedriver when calling webdriver-manager update. All you need to do is update Protractor in your package.json file.
Protractor 有一个新版本 (4.0.10),它将使用新版本的 webdriver-manager (10.2.6),当调用 webdriver-manager update 时,它将更新到新的 Chromedriver。您需要做的就是在 package.json 文件中更新 Protractor。
"protractor": "^4.0.9" to "protractor": "^4.0.10"
Hope this helps :)
希望这可以帮助 :)
回答by Raj Kumar
- Just run the following command:
- Projectdirectory:/>webdriver-manager update --versions.chrome=ChromeVersion
- Replace this with "ChromeVersion" Google Chrome Browser Version.Find chrome version by navigating to "Help>>About Google chrome>>For Example: Version 76.0.3809.100(Official Build) (64-bit)".
- 只需运行以下命令:
- 项目目录:/>webdriver-manager update --versions.chrome=ChromeVersion
- 将其替换为“ChromeVersion”Google Chrome 浏览器版本。通过导航到“帮助>>关于 Google chrome>>例如:版本76.0.3809.100(官方版本)(64 位)”来查找 chrome 版本。
I hope this will work for you.
我希望这对你有用。
回答by Johnny
For me, updating chromedriver and protractor-conf.js
fixed the issue.
对我来说,更新 chromedriver 并protractor-conf.js
解决了这个问题。
- Download latest chromedriver that suitable to your OS (change the minor version if needed) from here: http://chromedriver.storage.googleapis.com/index.html?path=2.24/
- Unzip to
/usr/local/bin/chromedriver
folder. - In
protractor-conf.js
(should be in app root) add a line withconfig.chromeDriver = '/usr/local/bin/chromedriver';