[英]C# - Google chrome is getting crashed when running selenium tests on docker windows
I am getting the following error when running selenium c# tests on docker windows.在 docker Z0F4137ED1502B5055D6083AA258 上运行 selenium c# 测试时出现以下错误。 Could anyone please help me on this.
谁能帮我解决这个问题。 I am really struggling to get it solved.
我真的很难解决它。
The Error that I am getting is shown below:我得到的错误如下所示:
OpenQA.Selenium.WebDriverException : unknown error: Chrome failed to start: crashed.
(chrome not reachable)
(The process started from chrome location C:\Program Files\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver…ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
at OpenQA.Selenium.Chrome.ChromeDriver…ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
at SeleniumCore.Core.Chrome.Initialize() in C:\src\SeleniumCore\Core\Chrome.cs:line 58
The code which initializes the chrome is shown below:初始化 chrome 的代码如下所示:
public class Chrome : IBrowser
{
public RemoteWebDriver MainDriver { get; private set; }
private readonly bool Headless;
public Chrome(AppConfigContext context)
{
Headless = context.Headless;
}
/// <summary>
/// Initialize Chrome Browser Instance.
/// </summary>
public void Initialize()
{
ChromeOptions options = new ChromeOptions();
if (Headless)
options.AddArgument("headless");
options.AddArgument("--disable-gpu");
options.AddArgument("--no-sandbox");
options.AddArguments("--disable-dev-shm-usage");
var downloadPath = Controls.DataFilePath + @"Downloads";
Controls.CreateDirectory(downloadPath);
options.AddUserProfilePreference("download.default_directory", downloadPath);
options.AddUserProfilePreference("download.prompt_for_download", false);
options.AddUserProfilePreference("disable-popup-blocking", "true");
RemoteWebDriver driver = new ChromeDriver(@"C:\Chromedrivers\new",options);
MainDriver = driver;
The docker info which I am using:我正在使用的 docker 信息:
Client:客户:
Context: default上下文:默认
Debug Mode: false调试模式:假
Plugins:插件:
buildx: Docker Buildx (Docker Inc., v0.7.1) buildx:Docker Buildx(Docker Inc.,v0.7.1)
compose: Docker Compose (Docker Inc., v2.2.1)撰写:Docker 撰写(Docker Inc.,v2.2.1)
scan: Docker Scan (Docker Inc., v0.14.0)扫描:Docker 扫描(Docker Inc.,v0.14.0)
Server:服务器:
Containers: 5容器:5
Running: 0运行:0
Paused: 0暂停:0
Stopped: 5停止:5
Images: 50图片:50
Server Version: 20.10.11服务器版本:20.10.11
Storage Driver: windowsfilter存储驱动程序:windowsfilter
Windows: Windows:
Logging Driver: json-file日志记录驱动程序:json 文件
Plugins:插件:
Volume: local音量:本地
Kernel Version: 10.0 19042 (19041.1.amd64fre.vb_release.191206-1406) Kernel 版本:10.0 19042 (19041.1.amd64fre.vb_release.191206-1406)
Operating System: Windows 10 Pro Version 2009 (OS Build 19042.1466)操作系统:Windows 10 Pro 版本 2009(操作系统内部版本 19042.1466)
OSType: windows操作系统类型:windows
Architecture: x86_64架构:x86_64
CPUs: 4中央处理器:4
Total Memory: 7.886GiB总 Memory:7.886GiB
Name:姓名:
Labels:标签:
Experimental: false实验:错误
Insecure Registries:不安全的注册表:
127.0.0.0/8 127.0.0.0/8
Live Restore Enabled: false启用实时恢复:假
Product License: Community Engine产品许可证:社区引擎
Please reply for this.请对此作出答复。 Thank you
谢谢
If your usecase is to connect to the RemoteWebDriver
, instead of:如果您的用例是连接到
RemoteWebDriver
,而不是:
RemoteWebDriver driver = new ChromeDriver(@"C:\Chromedrivers\new",options);
You have to:你必须:
var MainDriver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), DesiredCapabilities.Chrome()); // replace this url with the url of your remote hub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.