我想将测试名称传递给browserstack,以便将它们记录在browserstack界面内的会话值(名称)中
在我的验收助手中,我定义了以下方法
/**
* HOOK: before test
*
* We use this method to set the test name which will be logged in BrowserStack
* https://www.browserstack.com/automate/capabilities
* @param \Codeception\TestInterface $test
*/
public function _before(\Codeception\TestInterface $test)
{
codecept_debug('_before');
codecept_debug($this->getModule('WebDriver')->_getConfig()['capabilities']);
$config['capabilities'] = $this->getModule('WebDriver')->_getConfig()['capabilities'];
$config['capabilities']['name'] = $test->getName();
$this->getModule('WebDriver')->_setConfig($config);
codecept_debug($this->getModule('WebDriver')->_getConfig()['capabilities']);
}
我的方法存在一些问题
我应该使用哪个事件来实现自己的目标?
答案 0 :(得分:0)
通过代码接收,尤其是Webdriver源代码,我看到了以下内容: https://github.com/Codeception/Codeception/blob/2.5/src/Codeception/Module/WebDriver.php#L394
/**
* Change capabilities of WebDriver. Should be executed before starting a new browser session.
* This method expects a function to be passed which returns array or [WebDriver Desired Capabilities](https://github.com/facebook/php-webdriver/blob/community/lib/Remote/DesiredCapabilities.php) object.
* Additional [Chrome options](https://github.com/facebook/php-webdriver/wiki/ChromeOptions) (like adding extensions) can be passed as well.
*
* ```php
* <?php // in helper
* public function _before(TestInterface $test)
* {
* $this->getModule('WebDriver')->_capabilities(function($currentCapabilities) {
* // or new \Facebook\WebDriver\Remote\DesiredCapabilities();
* return \Facebook\WebDriver\Remote\DesiredCapabilities::firefox();
* });
* }
* ```
*
* to make this work load `\Helper\Acceptance` before `WebDriver` in `acceptance.suite.yml`:
*
* ```yaml
* modules:
* enabled:
* - \Helper\Acceptance
* - WebDriver
* ```
*
* For instance, [**BrowserStack** cloud service](https://www.browserstack.com/automate/capabilities) may require a test name to be set in capabilities.
* This is how it can be done via `_capabilities` method from `Helper\Acceptance`:
*
* ```php
* <?php // inside Helper\Acceptance
* public function _before(TestInterface $test)
* {
* $name = $test->getMetadata()->getName();
* $this->getModule('WebDriver')->_capabilities(function($currentCapabilities) use ($name) {
* $currentCapabilities['name'] = $name;
* return $currentCapabilities;
* });
* }
* ```
* In this case, please ensure that `\Helper\Acceptance` is loaded before WebDriver so new capabilities could be applied.
这似乎产生了与我最初的问题相同的错误,
编辑: 发生上述情况的原因是,在我的环境文件/设备定义中,有一个
声明。 modules:
enabled:
- WebDriver
删除已启用和webdriver的定义将使回退到accept.suite.yml,然后可以按预期正确运行