gpt4 book ai didi

testing - Travis-CI 可以运行 Codeception 测试吗?

转载 作者:行者123 更新时间:2023-11-28 19:40:22 26 4
gpt4 key购买 nike

我正在使用 Codeception 创建我的测试(虽然我是初学者,正在学习)。这包括目前的验收和单元测试。

我想将我的存储库添加到 Travis CI,这样我就可以在每次提交并放置构建状态标签后自动执行测试过程。

我想问;

  1. Travis-CI 可以运行代码检测测试吗?
  2. Travis-CI 可以运行模拟浏览器的代码接收验收测试吗?
  3. 如果两个答案都不是,是否有其他 CI 工具可以?

谢谢。

最佳答案

是的,可以在 Travis CI 上运行 Codeception 测试,包括使用 WebDriver 运行的验收测试。

possible to run your tests with a real browser on Travis , 但使用 headless 浏览器最简单,因为 Travis 运行在 headless 机器上。 PhantomJS非常适合这个,它预装了 Travis CI 的构建 Bootstrap 。

要使用 PhantomJS 运行测试,您需要在 .yml Codeception 配置文件中像这样配置 WebDriver 模块:

modules:
config:
WPWebDriver:
url: 'http://127.0.0.1:8888'
browser: phantomjs

URL 很重要。我发现尝试使用 localhost 而不是 127.0.0.1 是行不通的。此外,如果您不小心遗漏了 http://,那也不会起作用。您可以使用大多数 8*** 端口,因为它们中的大多数都是开放的,但是当然您需要在该端口上运行一个 Web 服务器来为您的静态文件提供服务或运行您的 PHP应用。我发现最简单的方法是使用 PHP 的内置网络服务器。

您的 .travis.yml 文件可能如下所示:

# Travis CI configuration file.

language: php

php:
- 5.6
- 7.0

before_script:
# Start up a web server.
- php -S 127.0.0.1:8888 -t /path/to/web/root >/dev/null 2>&1 &
# Start up the webdriver.
- phantomjs --webdriver=4444 >/dev/null 2>&1 &
# Install Codeception.
# Doing this last gives the webdriver and server time to start up.
- composer install --prefer-source

script:
- vendor/bin/codecept run

您当然需要将 Codeception 添加到项目的 composer.json 文件中:

composer require --dev codeception/codeception

您还需要将上面的 path/to/web/root 更改为您希望服务器文档根目录所在的目录的路径。

如果您想查看针对 WordPress 运行 WebDriver 测试的工作演示,您可以查看 this GitHub repo .

关于testing - Travis-CI 可以运行 Codeception 测试吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18558392/

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