docker:c#如何通过webapi运行selenium

docker:c#如何通过webapi运行selenium,c#,selenium-webdriver,.net-core,C#,Selenium Webdriver,.net Core,我正在运行一个测试PoC web api。我正在web api端点内运行Selenium测试。在本地一切正常,但当我在Docker Image上运行它时。我得到一个错误: System.Exception: at Interop.Sys.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boo

我正在运行一个测试PoC web api。我正在web api端点内运行Selenium测试。在本地一切正常,但当我在Docker Image上运行它时。我得到一个错误:

System.Exception:    at Interop.Sys.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setUser, UInt32 userId, UInt32 groupId, Int32& lpChildPid, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean shouldThrow)
   at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at OpenQA.Selenium.DriverService.Start()
   at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
我在本地使用一个简单的chromedriver来运行它,但我不确定本地代码与在docker中创建图像时的代码有什么不同。谢谢你的帮助。我已经读了很多关于docker和selinum的书,但是还没有找到任何东西

失败的代码:

  ChromeOptions options = new ChromeOptions();
  options.AddArgument("headless");
  options.AddArguments("no-sandbox");
  ChromeDriverService service = ChromeDriverService.CreateDefaultService(System.AppContext.BaseDirectory, "chromedriver");
  _driver = new ChromeDriver(service, options, TimeSpan.FromSeconds(30));
我一直使用的参考资料:


    • 我找到了答案。我最终使用了docker映像中的
      RemoteWebDriver
      。按照说明操作后,现在一切正常