codeception - 将 codeception 测试名称传递给 browserstack
问题描述
我想将我的测试名称传递给 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']);
}
我的方法有一些问题
- 此事件似乎在测试登录到 browserstack 后触发(这是我的主要问题 - 我正在寻找注入此名称值的正确位置)
- 有时会以错误的名称记录测试 - 多个测试将使用相同的名称
我应该使用哪个事件来实现我的目标?
解决方案
通过 codeception,特别是 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
删除 enabled 和 webdriver 定义允许回退到 accept.suite.yml 上,然后按预期正常工作
推荐阅读
- jquery - 我在向 MVC 发送列表数据时遇到问题
- reactjs - FlatList 重新渲染图像,尽管使用了 React.memo (AND shouldComponentUpdate, AND extraData)
- angular - 如何在 Angular RxJS 中正确链接 concatMaps
- python - 使用 Python 创建 PDF 时出现黑框
- qt - 在 Qt3D 中找不到适合 QUrl 的导入器插件 - .dae 对象
- r - 将 geom_text 添加到现有图表
- typescript - TypeScript:从接口方法返回类的实例
- python - discord.py 没有当前事件循环
- assembly - 这条指令需要多少指令周期?
- php - Laravel Echo 与 Pusher 支持多个用户