Setting up my CEF with Selenium

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Setting up my CEF with Selenium

Postby nikolamilev » Fri Mar 01, 2019 11:07 am

I've followed the instructions from the tutorial UsingChromeDriver. I've downloaded the ChromeDriver from here (version 2.46) and Selenium standalone server from here (version 3.9.1). I know that the tutorial says what the last tested versions were but I was unable to find the mentioned CEF version so I just went with the new versions of the tools/CEF. The CEF version I used is 3.3578.

Is this tutorial still considered to be a reliable method of using Selenium with CEF? I've had some really non-deterministic behavior: in some cases, the example "test" works fine and in some, it crashes. Below is an example code. Perhaps I've done something wrong?

Code: Select all
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class TestSloba  {
  public static void main(String[] args) {
    WebDriver driver = null;
    try{
      System.setProperty("webdriver.chrome.driver", "/home/debian-tp/Desktop/selenium_test/chromedriver_linux64/chromedriver");

      ChromeOptions options = new ChromeOptions();

      // Cefclient won't start ptoperly without these options
      options.addArguments("--no-sandbox");
      options.addArguments("--disable-extensions");

      String pathToBinary = "/home/debian-tp/Desktop/cef_binary_3.3578.1861.g1992780_linux64/cef_binary_3.3578.1861.g1992780_linux64//build/tests/cefclient/Debug/cefclient";
      options.setBinary(pathToBinary);

      options.addArguments("--remote-debugging-port=8088");

      driver = new ChromeDriver(options);
      sleep(2000);
      driver.get("http://192.168.15.166:8080");
      sleep(2000);

      System.out.println("Title: " + driver.getTitle());
      sleep(2000);
      System.out.println("Title test 1: " + (driver.getTitle().trim().equals("Page redirection test")));
      sleep(2000);

    } catch (Exception e) {
      System.out.println("EXCEPTION: " + e.toString());
    }finally {
      if (driver != null)
        driver.quit();
      System.exit(0);
    }
  }

  static void sleep(int time) {
    try { Thread.sleep(time); } catch (InterruptedException e) {}
  }
}



I replace the path argument with the path to my other executable when I try to test this example with my custom CEF project.
It mostly works with cefclient: sometimes it crashes but that seems to be related to the command line arguments that I pass.

Also, when I don't get the crash with my application, I see no window. On cefclient, I see a window just fine.

So, am I doing something wrong? If you need more info, let me know!

EDIT:
Adding the crash message I get:

Code: Select all
Starting ChromeDriver 2.46.628388 (4a34a70827ac54148e092aafb70504c4ea7ae926) on port 1988
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
EXCEPTION: org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: crashed
  (chrome not reachable)
  (The process started from chrome location /home/debian-tp/Desktop/cross_platform_new_cef/build/AplWrapperTestInCLinux/Debug/apltestc_linux is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=2.46.628388 (4a34a70827ac54148e092aafb70504c4ea7ae926),platform=Linux 4.9.0-8-amd64 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.05 seconds
Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:42:28.403Z'
System info: host: 'debian-tp', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.9.0-8-amd64', java.version: '1.8.0_181'
Driver info: driver.version: ChromeDriver
nikolamilev
Mentor
 
Posts: 52
Joined: Wed Nov 14, 2018 5:22 am

Re: Setting up my CEF with Selenium

Postby Czarek » Fri Mar 01, 2019 2:19 pm

Check CEF logs.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Setting up my CEF with Selenium

Postby Czarek » Fri Mar 01, 2019 2:33 pm

Try also this version of Chromedriver: https://chromedriver.storage.googleapis ... .3578.137/
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Setting up my CEF with Selenium

Postby nikolamilev » Mon Mar 04, 2019 4:49 am

Hi! Thanks for the reply! Unfortunately, changing the Chrome Driver version did not help. Regardless of whether the process crashes or passes "fine" (still no window shown, but this is the least of my concerns right now), the log is the same:

Code: Select all
[0304/101951.575766:ERROR:sandbox_linux.cc(364)] InitializeSandbox() called with multiple threads in process gpu-process.
[0304/101951.579537:FATAL:main.cc(339)] Check failed: !is_initialized.


I now get a third outcome: the process freezes.

I've looked up my own logs and found out that the freeze/crash happens inside CefInitialize. The other weird things I saw is that CefInitialize is called two times. This might be the cause of the freeze/crash.

The exact code I'm using is here:

Code: Select all
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class Example  {
  public static void main(String[] args) {
    // Path to the ChromeDriver executable.
    System.setProperty("webdriver.chrome.driver", "/home/debian-tp/Desktop/selenium_test/chromedriver_linux64/chromedriver");

    ChromeOptions options = new ChromeOptions();
    // Path to the CEF executable.
    options.setBinary("/home/debian-tp/Desktop/cross_platform_new_cef/build/AplWrapperTestInCLinux/Debug/apltestc_linux");
    // Port to communicate on. Required starting with ChromeDriver v2.41.
    options.addArguments("remote-debugging-port=8088");

    WebDriver driver = new ChromeDriver(options);
    sleep(1000);
    driver.get("http://192.168.15.166:8080");
    sleep(1000);  // Let the user actually see something!

    WebElement ws1box = driver.findElement(By.name("ws1data"));
    System.out.println("Content 1: " + ws1box.getAttribute("value"));
    sleep(1000);
    System.out.println("Content: " + ws1box.getAttribute("value"));
    sleep(1000);
    driver.quit();
  }

  static void sleep(int time) {
    try { Thread.sleep(time); } catch (InterruptedException e) {}
  }
}


The crash/freeze happens at the line:
Code: Select all
WebDriver driver = new ChromeDriver(options);


EDIT: I would like to add that sometimes even cefclient crashes/freezes with this setup. A reboot seems to have solved this issue. Is there a possibility that this is a Selenium/Chrome Driver issue?
nikolamilev
Mentor
 
Posts: 52
Joined: Wed Nov 14, 2018 5:22 am

Re: Setting up my CEF with Selenium

Postby Czarek » Mon Mar 04, 2019 6:36 am

Looks like you're calling CefInitialize multiple times. It should be called only once in the main/browser process. See cefclient/cefsimple sample applications for how you should handle the value returned by CefExecuteProcess.

What do CEF logs show when cefclient application crashes? (original unmodified example)

Try latest CEF supported branch 3626 from Spotify builds.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Setting up my CEF with Selenium

Postby nikolamilev » Mon Mar 04, 2019 6:42 am

Czarek wrote:Looks like you're calling CefInitialize multiple times. It should be called only once in the main/browser process. See cefclient/cefsimple sample applications for how you should handle the value returned by CefExecuteProcess.


The application works fine and doesn't have multiple CefInitialize calls when I'm not trying to test it with Selenium/WebDriver. This is what confuses me the most.


Czarek wrote:What do CEF logs show when cefclient application crashes? (original unmodified example)

Try latest CEF supported branch 3626 from Spotify builds.


I'll test that now and let you know.
nikolamilev
Mentor
 
Posts: 52
Joined: Wed Nov 14, 2018 5:22 am

Re: Setting up my CEF with Selenium

Postby nikolamilev » Mon Mar 04, 2019 9:18 am

A quick update: I have succeeded in running the tests on Windows (my original issue was on Debian). The application was build using CEF 3.3538 (Chrome version 70, according to cef_version.h) and ChromeDriver 2.45.

I'll try to run Selenium with my application on Windows but with the newest CEF asap.

Is there anything that differs in this process between operating systems?
nikolamilev
Mentor
 
Posts: 52
Joined: Wed Nov 14, 2018 5:22 am

Re: Setting up my CEF with Selenium

Postby nikolamilev » Mon Mar 04, 2019 11:29 am

I've managed to make cefclient, both versions 3538 and 3626, crash with Selenium. The debug.log file from the crash is pretty short:
Code: Select all
[0304/170044.634:FATAL:permissions_parser.cc(127)] Check failed: feature. Could not find feature for management


This cefclient instance runs fine when executed from PowerShell or Windows Explorer.

I must add that I've successfully run my application with Selenium, built with CEF 3538, before, on the same PC and OS.

This all seems pretty non-deterministic. Can you give me any clues?
nikolamilev
Mentor
 
Posts: 52
Joined: Wed Nov 14, 2018 5:22 am

Re: Setting up my CEF with Selenium

Postby Czarek » Mon Mar 04, 2019 1:10 pm

What do you mean by "managed to crash"? If you use some special features not supported by CEF then it won't work obviously. The error you report is in "extensions/common/manifest_handlers/permissions_parser.cc" which probably means the Extensions feature you try is not supported. CEF supports extensions only partially, load "chrome://extensions-support" url to see what is supported.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Setting up my CEF with Selenium

Postby nikolamilev » Tue Mar 05, 2019 4:26 am

Czarek wrote:What do you mean by "managed to crash"? If you use some special features not supported by CEF then it won't work obviously. The error you report is in "extensions/common/manifest_handlers/permissions_parser.cc" which probably means the Extensions feature you try is not supported. CEF supports extensions only partially, load "chrome://extensions-support" url to see what is supported.


I mean that I managed to reproduce the issue with cefclient. I haven't added the "--disable-extensions flag".

When I add it, the test with cefclient runs fine.
When I add it while using my application, the test and the application start but the constructor for ChromeDriver never returns and I get an exception about a minute later:
Code: Select all
Exception in thread "main" org.openqa.selenium.WebDriverException: chrome not reachable
  (Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.17763 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 61.16 seconds
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'DESKTOP-88U0FIQ', ip: '192.168.15.94', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191'
Driver info: driver.version: ChromeDriver
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
   at java.lang.reflect.Constructor.newInstance(Unknown Source)
   at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
   at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
   at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$errorHandler$0(JsonWireProtocolResponse.java:54)
   at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)
   at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)
   at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
   at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)
   at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
   at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
   at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
   at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
   at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)
   at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
   at java.util.stream.ReferencePipeline.findFirst(Unknown Source)
   at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)
   at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)
   at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
   at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
   at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
   at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
   at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
   at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
   at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
   at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:157)
   at paket.MainTest.main(MainTest.java:28)
nikolamilev
Mentor
 
Posts: 52
Joined: Wed Nov 14, 2018 5:22 am

Next

Return to Support Forum

Who is online

Users browsing this forum: No registered users and 53 guests