0

I am trying to setup browser testing with selenium and docker with behat.

The main issue I am having is reliability when running the tests.

Sometimes I can get connected and am able to run tests fine, but a lot of the time I cannot.

It seems quite inconsistent, I startup the containers and run tests, first time fails, run again, the second time it runs and works fine.

Once I restart the selenium-hub and run tests again it's fine (mostly).

Thanks for the help.

A common error I get is:

  Could not open connection: session not created exception
  from disconnected: unable to connect to renderer
    (Session info: chrome=61.0.3163.91)
    (Driver info: chromedriver=2.32.498513 (2c63aa53b2c658de596ed550eb5267ec5967b351),platform=Linux 4.4.0-96-generic x86_64) (WARNING: The server did not provide any stacktrace information)
  Command duration or timeout: 411 milliseconds
  Build info: version: '3.5.3', revision: 'a88d25fe6b', time: '2017-08-29T12:54:15.039Z'
  System info: host: 'e0218fe24a14', ip: '172.18.0.6', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-96-generic', java.version: '1.8.0_131'
  Driver info: driver.version: unknown (Behat\Mink\Exception\DriverException)

docker-compose.yml

version: '2'
services:
    db:
        build:
            context: .
            dockerfile: DockerfileDb
        container_name: db
        ports:
            - "3396:3306"
        environment:
            - MYSQL_ROOT_PASSWORD=password

    web:
        build:
            context: .
            dockerfile: DockerfileWeb
        depends_on:
            - db
        container_name: web
        ports:
            - "8080:80"
        links:
            - db
            - selenium-hub
        environment: 
            - LOCALHOST_DOCKER=db
            - MYSQL_USER=root
            - MYSQL_PASSWORD=password
        volumes:
            - ./conf/rsyslog.conf:/etc/rsyslog.d/rsyslog-custom.conf        
            - ./:/var/www
            - ./sites-enabled:/etc/apache2/sites-enabled
            - ./conf/hosts:/etc/hosts

    selenium-hub:
        container_name: selenium_hub
        image: selenium/hub
        ports:
            - "4444:4444"

    chrome:
        container_name: selenium_node_chrome
        image: selenium/node-chrome
        volumes:
            - /dev/shm:/dev/shm # Mitigates the Chromium issue described at https://code.google.com/p/chromium/issues/detail?id=519952
        links:
            - selenium-hub
            - web
        environment:
            - HUB_PORT_4444_TCP_ADDR=selenium-hub
            - HUB_PORT_4444_TCP_PORT=4444
        volumes:
            - ./conf/hosts_selenium:/etc/hosts
        depends_on:
            - selenium-hub
        shm_size: 1g

    firefox:
        container_name: selenium_node_firefox
        image: selenium/node-firefox
        links:
            - selenium-hub
            - web
        environment:
            - HUB_PORT_4444_TCP_ADDR=selenium-hub
            - HUB_PORT_4444_TCP_PORT=4444
        volumes:
            - ./conf/hosts_selenium:/etc/hosts
        depends_on:
            - selenium-hub

behat.yml

default:
    extensions:
        Laracasts\Behat:
            # env_path: .env.behat
        Behat\MinkExtension:
            base_url: http://**********:8080/
            default_session: laravel
            laravel: ~
            selenium2:
                wd_host: http://selenium_node_chrome:5555/wd/hub
                capabilities: {'platform': 'LINUX', 'browser': 'chrome'}
            browser_name: chrome

login.feature

@mink:selenium2
Feature: login
    Users should be able to login

  Scenario: Login Successfully                   # features/Login.feature:5
    When I wait 1 seconds                        # FeatureContext::iWaitSeconds()
      Could not open connection: session not created exception
      from disconnected: unable to connect to renderer
        (Session info: chrome=61.0.3163.91)
        (Driver info: chromedriver=2.32.498513 (2c63aa53b2c658de596ed550eb5267ec5967b351),platform=Linux 4.4.0-96-generic x86_64) (WARNING: The server did not provide any stacktrace information)
      Command duration or timeout: 411 milliseconds
      Build info: version: '3.5.3', revision: 'a88d25fe6b', time: '2017-08-29T12:54:15.039Z'
      System info: host: 'e0218fe24a14', ip: '172.18.0.6', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-96-generic', java.version: '1.8.0_131'
      Driver info: driver.version: unknown (Behat\Mink\Exception\DriverException)
    Given I am on "/"                            # FeatureContext::visit()
    Then print current URL                       # FeatureContext::printCurrentUrl()
    Then take screenshot "test1.png"             # FeatureContext::takeScreenshot()
    Then I should not see "Whoops"               # FeatureContext::assertPageNotContainsText()
    And I should not see "ERR_NAME_NOT_RESOLVED" # FeatureContext::assertPageNotContainsText()
    Then take screenshot "login_test.png"   
Gokul
  • 788
  • 2
  • 12
  • 30
alistaircol
  • 1,433
  • 12
  • 22

2 Answers2

0

You can try to update the chrome driver to the lastest version, it works for me: https://sites.google.com/a/chromium.org/chromedriver/downloads

0

I see this answer has had quite a lot of views, so here is what I came up with to fix this issue for me.


So, I added a volume (./conf/hosts_selenium:/etc/hosts) to each of the selenium nodes in docker-compose.yml.

...
chrome:
    container_name: selenium_node_chrome
    image: selenium/node-chrome
    volumes:
        - /dev/shm:/dev/shm # Mitigates the Chromium issue described at https://code.google.com/p/chromium/issues/detail?id=519952
        - ./conf/hosts_selenium:/etc/hosts
    links:
        - selenium-hub
        - web
    environment:
        - HUB_PORT_4444_TCP_ADDR=selenium-hub
        - HUB_PORT_4444_TCP_PORT=4444
    depends_on:
        - selenium-hub
    shm_size: 1g

firefox:
    container_name: selenium_node_firefox
    image: selenium/node-firefox
    links:
        - selenium-hub
        - web
    environment:
        - HUB_PORT_4444_TCP_ADDR=selenium-hub
        - HUB_PORT_4444_TCP_PORT=4444
    volumes:
        - ./conf/hosts_selenium:/etc/hosts
    depends_on:
        - selenium-hub
    shm_size: 2g

To add a host file to the nodes (./conf/hosts_selenium):

#<ip-address>   <hostname.domain.org>   <hostname>
127.0.0.1       localhost.localdomain   localhost
::1             localhost.localdomain   localhost

This seemed to fix the issue for me.. weird

alistaircol
  • 1,433
  • 12
  • 22