I am trying to set up Codeception to do Acceptance and Functional testing for my web app. Below are my files:
docker-compose.yml
version: '3.7'
services:
# nginx - web server
nginx:
build:
context: ./docker-config/nginx
dockerfile: ./Dockerfile
env_file: &env
- ./cms/.env
init: true
ports:
- "8000:80"
volumes:
- cpresources:/var/www/project/cms/web/cpresources
- ./cms/web:/var/www/project/cms/web:cached
networks:
mmc-network:
aliases:
- mmc.nginx
# php - run php-fpm
php:
build: &php-build
context: ./docker-config/php-prod-craft
dockerfile: ./Dockerfile
depends_on:
- "mysql"
- "redis"
env_file:
*env
expose:
- "9000"
init: true
volumes: &php-volumes
- some volumes............
networks:
mmc-network:
aliases:
- mmc.php
# mysql - database
mysql:
build:
context: ./docker-config/mysql
dockerfile: ./Dockerfile
cap_add:
- SYS_NICE # CAP_SYS_NICE
env_file:
*env
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: project
MYSQL_USER: project
MYSQL_PASSWORD: project
init: true
ports:
- "3306:3306"
volumes:
- db-data:/var/lib/mysql
- ./db-seed/:/docker-entrypoint-initdb.d
networks:
- MMC-network
# redis - key/value database for caching & php sessions
redis:
build:
context: ./docker-config/redis
dockerfile: ./Dockerfile
expose:
- "6379"
init: true
networks:
- mmc-network
# webpack - frontend build system
webpack:
build:
context: ./docker-config/node-dev-webpack
dockerfile: ./Dockerfile
env_file:
*env
init: true
ports:
- "8080:8080"
volumes:
- some volumes..........
networks:
- mmc-network
# selenium - web driver for codeception testing
selenium:
container_name: mmc-selenium
ports:
- "4444:4444"
volumes:
- ./cms:/data
build:
context: ./docker-config/selenium
dockerfile: ./Dockerfile
networks:
mmc-network:
aliases:
- mmc.selenium
volumes:
db-data:
cpresources:
storage:
networks:
mmc-network:
acceptance.suite.dist.yml:
actor: AcceptanceTester
extensions:
enabled:
- CodeceptionExtensionRunFailed
- CodeceptionExtensionRecorder
modules:
error_level: "E_ALL"
enabled:
- WebDriver:
url: 'http://mmc.nginx'
host: mmc.selenium
port: '4444'
window_size: 1920x1200
browser: 'chrome'
wait: 60
capabilities:
os: Windows
os_version: 10
browserstack.local: true
- HelperAcceptance
NavigationCept.php
<?php
$I = new AcceptanceTester($scenario);
# define purpose of the test
$I->wantTo("check that navigation is functional.");
# check all menu items
$I->amOnPage('/');
$I->see('Search');
***Now, point to be noted, Codeception
is already installed inside my PHP container and working perfectly.
When I try to run the test, I get the below error which indicates that the connection to my host (which is my Nginx server) has been refused.
I tried with a different url
, for example, https://google.com
and it just connected fine and everything was successful. Am I doing something wrong in here? Is my url
param incorrect? Please help me out if you can. Thanks in advance.
2
Answers
Docker service are reachable from each other using the service name as hostname. So your configuration could be:
An alias to a service could be specified at another service as:
Then the url could be
url: 'http://mmc.nginx'
Workaround: use service IP address
Test setup using
busybox
:docker-compose.yaml that runs 2 dummy web servers with
netcat
utility for demonstration purposes.test command:
Response:
Access from outside docker network:
Ping to
mmc-nginx
Find service IP address:
Using
docker
. Changesvc
value accordingly.:Using
jq
. Changesvc
value accordingly. jq is a great json processing tool to have btw.Using
grep
I have seen such exception earlier with Codeception + Selenium. I do not have that project config file to share with you though.
My strong guess here is this error could be due to conflicts around Codeception-ChromeDriver-Selenium versions
You could review the following notes which may help you debug this more
Will update this answer if I find other resources to resolve this.