gpt4 book ai didi

Codeception,如何从命令行覆盖特定(或非特定)套件测试的 url?

转载 作者:行者123 更新时间:2023-12-04 16:04:32 24 4
gpt4 key购买 nike

我正在寻找一种方法来从命令行覆盖我的测试的基本 url。以后我会测试很多网站,所以如果我必须将每个网站都添加到acceptance.suite.yml中的新环境中是非常笨拙的。文件。

目前,我的 acceptance.suite.yml是:

actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://foo.com
browser: chrome

我看到我可以在运行命令中使用选项“覆盖”,但即使我阅读了代码接收文档并浏览了帮助网站(如堆栈溢出..),我也找不到覆盖的好方法。有人能帮我吗?

当我打印所有配置(通过 ./vendor/bin/concept )时,我得到:
Array
(
actor => AcceptanceTester
modules => Array
(
enabled => Array
(
0 => Array
(
WebDriver => Array
(
url => http://foo.foo
browser => chrome
)
)
1 => \Helper\Acceptance
)
config => Array
(
)
depends => Array
(
)
)

我试过: ./vendor/bin/codecept run acceptance --steps -o 'modules: enabled: 0: WebDriver: url: http://faa.faa ,但测试在 http://foo.foo 上运行过

在此 codeception issue post ,当我们运行特定套件时,似乎不可能覆盖配置值(我的英语不是很好,所以也许我误解了)。所以我在 acceptance.suite.yml 中添加了一个 env文件 :
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://foo.foo
browser: chrome
env:
generic:
modules:
config:
WebDriver:
url: http://faa.faa

我尝试了这些命令:
./vendor/bin/codecept run acceptance --env generic --steps -o 'env: generic: modules: config: WebDriver: url: http://faa.faa

./vendor/bin/codecept run acceptance --env generic --steps -o 'WebDriver: url: http://faa.faa
什么也没发生。我的测试总是在 http://foo.foo
在“军团”帮助后编辑

当我使用这个时 acceptance.suite.yml :
actor: AcceptanceTester
modules:
enabled:
- WebDriver
config:
WebDriver:
url: ''
browser: ''

env:
chrome:
modules:
config:
WebDriver: {}

我收到一个错误:

enter image description here

所以当我使用这个 acceptance.suite.yml :
actor: AcceptanceTester
modules:
enabled:
- WebDriver
config:
WebDriver:
url: ''
browser: chrome

env:
chrome:
modules:
config:
WebDriver: {}

我收到另一个错误:

enter image description here

如果我使用这个 acceptance.suite.yml :
actor: AcceptanceTester
modules:
enabled:
- WebDriver
config:
WebDriver:
url: ''
browser: chrome

env:
chrome:
modules:
config:
WebDriver:
url: 'http://foo.foo'
browser: 'chrome'

没有错误!呜呜呜!我不在好的网址上 x)

enter image description here

我得到的网址是“数据:”,它很奇怪......
为了获取 url,我在我的测试文件中添加了这个简单的行:
$this->comment("I am on the url : " . $this->executeJS("return window.location.href") . "\n");

最佳答案

注意:您需要 Codeception 1.8 或更高版本!在那个版本被窃听之前。

如果版本 > 1.8 它应该可以工作...您可以尝试像下面一样编辑您的接受文件,看看是否有什么改变:

actor: AcceptanceTester
modules:
enabled:
- WebDriver
config:
WebDriver:
url: 'http://foo.foo/'
browser: 'firefox'

env:
chrome: #or watherver you want
modules:
config:
WebDriver:
url: 'http://fuu.fuu/'
browser: 'chrome'

像下面一样运行它:
php vendor/bin/codecept run acceptance --env chrome

** 编辑 **

要从命令行传递 url,您需要空的 WebDriver 配置:
actor: AcceptanceTester
modules:
enabled:
- WebDriver
config:
WebDriver: {}
env:
chrome: #or watherver you want
modules:
config:
WebDriver:
url:'http://foo.foo'
browser:'firefox'

命令行:
./vendor/bin/codecept run acceptance --env chrome --steps -o 'WebDriver: url: \'http://faa.faa\' browser: \'chrome\''

(我通常使用顶点作为 url 和浏览器......但不确定是否真的需要)。

关于Codeception,如何从命令行覆盖特定(或非特定)套件测试的 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52135740/

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