I have two php envs and I am currently able to run something like this for different urls
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/'
Currently I run them using commands
codecept run --env alpha
, or codecept run --env beta
Is there a way to provide the url from commandline while running the codeception tests , something like codecept run site=alpha.test.com and then grabbing it from inside the config instead of hardcoding urls ?
Cest is a common test format for Codeception, it is “Test” with the first C letter in it. It is scenario-driven format so all tests written in it are executed step by step. Unless you need direct access to application code inside a test, Cest format is recommended.
i had the same Problem and did extend Codeception to support a dynamic Server-Url.
I can call my Codeceptions-Test by php in addition by the following code:
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');
Here is the extension i did in 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;
}
}
In your case you need some additional programming to get all cli option into codecpetion (//see some other options).
OR
You can extend the Codecption cli interface to instantiate the Wrapper/Codecept and not the original Codecept.
Hope this helps a bit and gives you an idea how to fix your issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With