Run in non-headless mode on docker container - webdriver/docker/ubuntu

1,668 views
Skip to first unread message

garvitag...@gmail.com

unread,
Jun 27, 2018, 2:46:48 AM6/27/18
to Selenium Users
Hi,

My test are running in docker container in headless mode . I want ti run in display mode to debug it. I am not finding way to do that. Here are steps i do:
1. start docker using docker-compose up 

version: "2"
services:
  test-ng-environment:
    image: "test-ng-environment:latest"
    build:
      context: "."
      dockerfile: "Dockerfile"
    command: "sleep infinity"
    volumes:
      # hardcoded to live next to the code repo
      - "../code:/my_code"
      - "./m2:/root/.m2"
      - "/var/run/docker.sock:/var/run/docker.sock"
    cap_add:
      # this is required for chrome to be able to start in sandbox mode
      - SYS_ADMIN
    network_mode: "bridge"
    shm_size: '2gb'

2. Run environment bash , go to mounted directory and run test using :
 xvfb-run -a mvn test --batch-mode --errors --fail-at-end --show-version -Dtest.browser=chrome -Durl="${TEST_URL}" -Dusername=testuser -Dpassword="${TEST_PASSWORD}"

Test run fine in headless mode. I removed xvfb-run -a and run test using mvn test only. I got error :
org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally

Here is method to start chrome driver:

public WebDriver setupChromeDriver() {
   
        final boolean headlessMode = prop.getProperty("mode.chromeheadless", "").equals("true");
        ChromeOptions options = new ChromeOptions();
        Map<String, Object> prefs = new HashMap<>();

         prefs.put("credentials_enable_service", false);
        prefs.put("profile.password_manager_enabled", false);
        options.setExperimentalOption("prefs", prefs);
        options.addArguments("disable-infobars");
        options.addArguments("disable-extensions");
        if (headlessMode) {
            options.addArguments("headless");
        }
        options.setCapability(ChromeOptions.CAPABILITY, options);
        driver = new ChromeDriver(options);
        // Resize the current window to the given dimension
        driver.manage().window().setPosition(new Point(0, 0));
        driver.manage().window().setSize(d);

}

Thanks !!


Serguei Kouzmine

unread,
Jul 21, 2018, 1:14:14 AM7/21/18
to Selenium Users
Hello Garvitag

stopping x window server does not look like the right way of switching to gui mode. In fact the opposite may be true :  when passing the `headess` to chromedriver / chrome  you probably do not need xvfb, but for the gui node chrome run x  is absolutey required: it is linked to x libraries and will fail to launch :
```
file /opt/google/chrome/chrome
/opt/google/chrome/chrome: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=6b766636ccc2748536dbd66ecc3ab46dd7957068, stripped
                                                  
ldd /opt/google/chrome/chrome

        linux-vdso.so.1 =>  (0x00007fff89db8000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f3ed1fca000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f3ed1dc2000)
        libpangocairo-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so.0 (0x00007f3ed1bb4000)
        libpango-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0 (0x00007f3ed1967000)
        libcairo.so.2 => /usr/lib/x86_64-linux-gnu/libcairo.so.2 (0x00007f3ed165c000)
        libgobject-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007f3ed140a000)
        libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f3ed1102000)
        libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f3ed0dcd000)
        libXcomposite.so.1 => /usr/lib/x86_64-linux-gnu/libXcomposite.so.1 (0x00007f3ed0bc9000)

... truncated
```


BTW unless your host is Linux I doubt it is worth the effort running  full gui via docker  -  i may be wrong with this please correct me if so. 
Reply all
Reply to author
Forward
0 new messages