我正在寻找一种方法来从命令行覆盖我的测试的基本URL。在将来,我会测试很多网站,所以如果我必须在acceptance.suite.yml
文件中的新环境中添加每个网站,这是非常笨拙的。
目前,我的acceptance.suite.yml
是:
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://foo.com
browser: chrome
我看到我可以使用run命令选项'override',但即使我读了代码库文档并浏览帮助网站(比如stack overflox ..),我找不到一个好的覆盖方法。有人能帮我吗?
当我打印所有配置(通过./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
在“LEGION”帮助之后编辑
当我使用这个acceptance.suite.yml
时:
actor: AcceptanceTester
modules:
enabled:
- WebDriver
config:
WebDriver:
url: ''
browser: ''
env:
chrome:
modules:
config:
WebDriver: {}
我收到一个错误:
所以,当我使用这个acceptance.suite.yml
:
actor: AcceptanceTester
modules:
enabled:
- WebDriver
config:
WebDriver:
url: ''
browser: chrome
env:
chrome:
modules:
config:
WebDriver: {}
我收到另一个错误:
如果我使用这个acceptance.suite.yml
:
actor: AcceptanceTester
modules:
enabled:
- WebDriver
config:
WebDriver:
url: ''
browser: chrome
env:
chrome:
modules:
config:
WebDriver:
url: 'http://foo.foo'
browser: 'chrome'
没错! buuuUUUT!我不是好网址x)
我得到的网址是“数据:”,它很奇怪...为了获取网址,我在我的测试文件中添加了这个简单的行:
$this->comment("I am on the url : " . $this->executeJS("return window.location.href") . "\n");
N.B:您需要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\''
(我通常使用顶点作为网址和浏览器......但不确定是否真的需要)。