Wil*_*mes 5 php selenium nginx docker codeception
我正在尝试设置 Codeception 来对我的 Web 应用程序进行验收和功能测试。以下是我的文件:
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:
Run Code Online (Sandbox Code Playgroud)
accept.suite.dist.yml:
actor: AcceptanceTester
extensions:
enabled:
- Codeception\Extension\RunFailed
- Codeception\Extension\Recorder
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
- \Helper\Acceptance
Run Code Online (Sandbox Code Playgroud)
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');
Run Code Online (Sandbox Code Playgroud)
***现在,要注意的Codeception
是,它已经安装在我的 PHP 容器中并且运行良好。
当我尝试运行测试时,出现以下错误,表明与我的主机(即我的 Nginx 服务器)的连接已被拒绝。
url
例如,我尝试了一个不同的,https://google.com
它连接良好,一切都成功了。我在这里做错了吗?我的url
参数不正确吗?如果可以,请帮帮我。提前致谢。
Docker 服务可以使用服务名称作为主机名相互访问。所以你的配置可能是:
enabled:
- WebDriver:
url: 'http://nginx'
host: selenium
port: '4444'
Run Code Online (Sandbox Code Playgroud)
一个服务的别名可以在另一个服务中指定为:
selenium:
links:
- "nginx:mmc.nginx"
Run Code Online (Sandbox Code Playgroud)
那么网址可以是url: 'http://mmc.nginx'
解决方法:使用服务 IP 地址
enabled:
- WebDriver:
url: 'http://172.18.0.3'
host: 172.18.0.2
port: '4444'
Run Code Online (Sandbox Code Playgroud)
busybox
使用docker -compose.yaml进行测试设置
,运行 2 个虚拟 Web 服务器,并具有netcat
用于演示目的的实用程序。
version: '3.7'
services:
nginx:
container_name: mmc-nginx
hostname: mmc-nginx
image: busybox
command: ["sh", "-c", "while true ; do (echo -e 'HTTP/1.1 200 OK\r\nConnection: Close\r\nContent-type: application/xml\r\n\r\n'; echo 'response from '`hostname`':80') | nc -l -p 80 ;done" ]
init: true
ports:
- "8000:80"
networks:
- mmc-network
# selenium - web driver for codeception testing
selenium:
container_name: mmc-selenium
hostname: mmc-selenium
command: ["nc", "-l", "-p", "4444"]
ports:
- "4444:4444"
image: busybox
networks:
- mmc-network
networks:
mmc-network:
name: mmc-network
Run Code Online (Sandbox Code Playgroud)
测试命令:
docker exec -it mmc-selenium wget -q "http://mmc-nginx" -O -
docker exec -it mmc-selenium wget -q "http://172.18.0.3" -O -
Run Code Online (Sandbox Code Playgroud)
回复:
response from mmc-nginx:80
Run Code Online (Sandbox Code Playgroud)
从外部docker网络访问:
wget -q "http://localhost:8000" -O -
response from mmc-nginx:80
Run Code Online (Sandbox Code Playgroud)
ping 至mmc-nginx
docker exec -it mmc-selenium ping -c2 mmc-nginx
PING mmc-nginx (172.18.0.3): 56 data bytes
64 bytes from 172.18.0.3: seq=0 ttl=64 time=0.071 ms
64 bytes from 172.18.0.3: seq=1 ttl=64 time=0.111 ms
--- mmc-nginx ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.071/0.091/0.111 ms
Run Code Online (Sandbox Code Playgroud)
查找服务IP地址:
使用docker
。相应地更改svc
值:
svc='friendly_solomon' docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$svc"
Run Code Online (Sandbox Code Playgroud)
使用jq
。相应地更改svc
值。顺便说一句,jq是一个很棒的 json 处理工具。
svc='mmc-nginx'; docker network inspect bridge | jq -r --arg svc "$svc" '.[] | .Containers | .[] | select(.Name == $svc) | .IPv4Address'
Run Code Online (Sandbox Code Playgroud)
使用grep
svc='mmc-nginx' docker network inspect bridge | grep -A5 "$svc" | grep 'IPv4Address
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
164 次 |
最近记录: |