How to configure selenium for CEF/Winforms applications (exe)

时光怂恿深爱的人放手 提交于 2019-12-11 07:58:26

问题


Main Question: How does one configure selenium for CEFsharp applications in C#?

If anyone is having issues with configuring selenium to CEFsharp applications please take a look at this post. I had a tough time and scoured the internet to make this happen and I want to share this information with others.

My Environment:

  • VS 2017
  • C# backend/middleware
  • Angular frontend
  • CEF to encapsulate application
  • Application is exe

回答1:


Here is the solution:

Make sure your application uses RemoteDebugging (in main program file):

 static void Main()
        {
            var cefSettings = new CefSettings
            {
                WindowlessRenderingEnabled = true,
                MultiThreadedMessageLoop = true,
                BrowserSubprocessPath = @"CefSharp.BrowserSubprocess.exe",  
                LogSeverity = LogSeverity.Error,
            };
            cefSettings.CefCommandLineArgs.Add("--disable-pinch", "1");

#if DEBUG
            **cefSettings.RemoteDebuggingPort = port#;**
#endif
        Cef.Initialize(cefSettings);

If using angular make sure to include (in clientshellwinforms section):

#if DEBUG

           _webView.Load("http://localhost:portForAngular");
#endif

To connect to application on selenium use:

 public void Main()
    {
        var chromeDriverService = ChromeDriverService.CreateDefaultService();
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.AddArgument("remote-debugging-port=port#");
        chromeOptions.DebuggerAddress = "localhost:port#";
        driver = new ChromeDriver(chromeDriverService, chromeOptions);
    }

Then you should be able to drive through using selenium.

Things to consider:

As long as the application has remote debugging enabled you can open it and then run the selenium functions.

Use chrome://inspect (instead or debugger port) to take full advantage of dev tools.

Nuget:

  1. Selenium.Chrome.WebDriver 2.34.0 (Old, but gold)
  2. Selenium.Support & Selenium.WebDriver 3.141.0
  3. NUnit/NUnit3TestAdapter 3.11/3.13
  4. DotNetSeleniumExtras.PageObjects 3.11.0

Good luck!



来源:https://stackoverflow.com/questions/55497969/how-to-configure-selenium-for-cef-winforms-applications-exe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!