gpt4 book ai didi

php - 在 docker 容器中使用 Selenium 的 Codeception 无法看到测试它的站点

转载 作者:行者123 更新时间:2023-12-02 20:04:13 33 4
gpt4 key购买 nike

我的网站使用 docker-compose 在 LEMP 堆栈上运行,一切正常。

我遵循了 Selenium docker 的官方文档,我的 Composer 文件是他们的摘录副本:

version: "3"
services:
selenium-hub:
image: selenium/hub:3.12.0-cobalt
container_name: selenium-hub
ports:
- "4444:4444"
chrome:
image: selenium/node-chrome:3.12.0-cobalt
depends_on:
- selenium-hub
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
firefox:
image: selenium/node-firefox:3.12.0-cobalt
depends_on:
- selenium-hub
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444

然后我已经完全按照文档配置了代码接收:
acceptance.suite.yml
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://172.22.1.2
browser: chrome
- \Helper\Acceptence
TestCest.php
...
public function tryToTest(AcceptanceTester $I)
{
$I->amOnPage('/');
$I->see('Homepage');
}
...

运行测试时,它们超时并失败说 This site can't be reached . docker 容器肯定正在运行,并且可以通过 Web 浏览器通过容器 IP 172.22.1.2 访问

当我使用默认的 PhpBrowser 时,测试全部运行并正常工作,因此似乎 codeception 无法访问 selenium docker 容器。对此有何建议?

编辑.........
为了清楚起见,添加 docker-compose
version: "3.1"
services:

mariadb:
image: mariadb:10.1
container_name: reports-mariadb
working_dir: /application
volumes:
- .:/application
environment:
- MYSQL_ROOT_PASSWORD=reports
- MYSQL_DATABASE=reports
- MYSQL_USER=reports
- MYSQL_PASSWORD=reports
ports:
- "8011:3306"
networks:
reports:
ipv4_address: 172.22.1.3

webserver:
image: nginx:latest
container_name: reports-nginx
working_dir: /application
volumes:
- .:/application
- ./dev/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "8010:80"
networks:
reports:
ipv4_address: 172.22.1.2

php-fpm:
build: dev/php-fpm
container_name: reports-php-fpm
working_dir: /application
volumes:
- .:/application
- ./dev/php-fpm/php-ini-overrides.ini:/etc/php/7.2/fpm/conf.d/99-overrides.ini
networks:
reports:
ipv4_address: 172.22.1.4

networks:
reports:
driver: bridge
ipam:
config:
- subnet: 172.22.1.0/24

最佳答案

在发布问题后它来到我这里......它默认在本地主机上查看,但由于应用程序在虚拟网络 172.22.1.0/24 内运行,与应用程序容器相比,它显然是不同的本地主机。

所以我将容器移到我的主 docker-compose 文件中并添加了 selenium-hub像这样到虚拟网络:

version: "3.1"
services:

mariadb:
image: mariadb:10.1
container_name: reports-mariadb
working_dir: /application
volumes:
- .:/application
environment:
- MYSQL_ROOT_PASSWORD=reports
- MYSQL_DATABASE=reports
- MYSQL_USER=reports
- MYSQL_PASSWORD=reports
ports:
- "8011:3306"
networks:
reports:
ipv4_address: 172.22.1.3

webserver:
image: nginx:latest
container_name: reports-nginx
working_dir: /application
volumes:
- .:/application
- ./dev/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "8010:80"
networks:
reports:
ipv4_address: 172.22.1.2

php-fpm:
build: dev/php-fpm
container_name: reports-php-fpm
working_dir: /application
volumes:
- .:/application
- ./dev/php-fpm/php-ini-overrides.ini:/etc/php/7.2/fpm/conf.d/99-overrides.ini
networks:
reports:
ipv4_address: 172.22.1.4

selenium-hub:
image: selenium/hub:3.12.0-cobalt
container_name: selenium-hub
ports:
- "4444:4444"
chrome:
image: selenium/node-chrome:3.12.0-cobalt
depends_on:
- selenium-hub
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
firefox:
image: selenium/node-firefox:3.12.0-cobalt
depends_on:
- selenium-hub
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444

networks:
reports:
driver: bridge
ipam:
config:
- subnet: 172.22.1.0/24

然后你只需要告诉codeception它在哪个主机上运行:
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://172.22.1.2
host: 172.22.1.5
browser: chrome
- \Helper\Acceptence

关于php - 在 docker 容器中使用 Selenium 的 Codeception 无法看到测试它的站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51159068/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com