Sup*_*pra 13 php phantomjs codeception
我有两个php envs,我现在可以为不同的URL运行这样的东西
modules:
enabled:
- WebDriver
- AcceptanceHelper
config:
WebDriver:
url: 'http://localhost/'
browser: 'phantomjs'
env:
alpha:
modules:
config:
WebDriver:
url: 'http://myalphasite/'
beta:
modules:
config:
WebDriver:
url: 'http://mybetasite/'
Run Code Online (Sandbox Code Playgroud)
目前我使用命令运行它们
codecept run --env alpha ,或者 codecept run --env beta
有没有办法在运行代码测试时从命令行提供url,比如codecept run site = alpha.test.com然后从配置内部抓取它而不是硬编码网址?
我遇到了同样的问题,并且确实扩展了 Codeception 以支持动态服务器 URL。
我还可以通过以下代码通过 php 调用我的 Codeceptions-Test:
chdir('myPathTo: tests/codeception');
$codeception = new \Wrapper\Codecept([
'steps' => true,
'verbosity' => 1,
// some other options (see Codeception docs/sources)
]);
$codeception->setBaseUrl('myServerUrl');
$codeception->run('myTestSuiteName');
Run Code Online (Sandbox Code Playgroud)
这是我在 Codeception 中所做的扩展:
<?php
namespace Wrapper;
use Codeception\Codecept as CodeceptOriginal;
class Codecept extends CodeceptOriginal {
private $baseUrl = null;
public function runSuite($settings, $suite, $test = null) {
if ($settings['modules']['enabled']) {
foreach ($settings['modules']['enabled'] as $key => $module) {
if (is_array($module) && $module['PhpBrowser']['url']) {
$module['PhpBrowser']['url'] = $this->getBaseUrl();
$settings['modules']['enabled'][$key] = $module;
}
}
}
return parent::runSuite($settings, $suite, $test = null);
}
public function getBaseUrl() {
return $this->baseUrl;
}
public function setBaseUrl($baseUrl) {
$this->baseUrl = $baseUrl;
return $this;
}
}
Run Code Online (Sandbox Code Playgroud)
在您的情况下,您需要一些额外的编程才能将所有 cli 选项放入 codecpetion 中(//参见其他一些选项)。
或者
您可以扩展 Codecption cli 接口来实例化 Wrapper/Codecept 而不是原始的 Codecept。
希望这对您有所帮助,并让您了解如何解决您的问题。
| 归档时间: |
|
| 查看次数: |
3761 次 |
| 最近记录: |