Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

codeception in docker-compose - can't connect to Webdriver

I have somewhere an error in setting the Webdriver for my codeception and just can't figure it out.

when starting with

docker-compose run --rm codeception run

it finds the acceptance tests, and even reads the $I->wantTo

but then throws an error:

[ConnectionException] Can't connect to Webdriver at http://127.0.0.1:4444/wd/hub. Please make sure that Selenium Server or PhantomJS is running.

my acceptance.suite.yml is the following and I already tried replacing the url with chrome, nginx-web, the ip of the actual server (which does not make sense, but I really don't know what else to put in there)

actor: AcceptanceTester
modules:
    enabled:
        # selenium webdriver
        - WebDriver:
            url: 'http://localhost/'
            browser: chrome

        - \Helper\Acceptance

my docker-compose.yml. I set the volumes in an additionl override

version: '2'
services:

  codeception:
    image: codeception/codeception:2.3.5
    depends_on:
      - nginx-web
      - php-web
      - chrome

  nginx-web:
    image:
      nginxext:0.5.6
    depends_on:
      - php-web
    expose:
      - 80

  php-web:
    image:
      phpext:0.7.0
    expose:
      - 9000

  # https://github.com/SeleniumHQ/docker-selenium
  chrome:
    image: selenium/standalone-chrome-debug:3.7.1
    ports:
      - 4444
      - 5900

Any ideas what I am doing wrong?

like image 696
TheRealPir Avatar asked Nov 29 '17 20:11

TheRealPir


People also ask

Can I run selenium in Docker container?

Docker can ship Selenium Server with all its dependencies and browsers inside a single container. Running tests inside Docker is as easy as pulling official selenium image and starting a container with Chrome: By using --net=host allow Selenium to access local websites.

How to install the WebDriver module in codeception?

If you use Codeception installed using composer, install this module with the following command: Alternatively, you can enable WebDriver module in suite configuration file and run This module was bundled with Codeception 2 and 3, but since version 4 it is necessary to install it separately. Some modules are bundled with PHAR files. Warning.

How to listen to external IP in a docker container?

You therefore need to listen on the external IP inside the container, and the easiest way to do that is by listening on all interfaces: 0.0.0.0. You need to start packaging your Python application with Docker, and you keep hitting errors, from connection refused to OCI runtime complaints, because you don't really understand how it all works.

How does Docker run on non-Linux OSes like macOS?

Docker runs on non-Linux OSes like macOS by running a Linux virtual machine, but the practical consequences are the same. Your operating system has multiple network “interfaces”. For example, on my computer (with output shortened for clarity):


1 Answers

I finally found it. Given the various descriptions on the net using just url, I thought that I am setting the host also with the url. But you actually need to set the host and the url independently. So the solution is to add the service name of the selenium browser together with host.

        - WebDriver:
            url: http://localhost/      # url of app
            browser: chrome
            host: chrome                # selenium server host, default 127.0.0.1
#            port: 4444                 # selenium server port, default 4444
#            window_size: maximize      # or 640x480
like image 148
TheRealPir Avatar answered Oct 09 '22 15:10

TheRealPir