【问题标题】:Pass codeception test name to browserstack将 codeception 测试名称传递给 browserstack
【发布时间】:2018-10-13 07:11:36
【问题描述】:

我想将我的测试名称传递给 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']);
}

我的方法存在一些问题

  1. 此事件似乎在测试登录到 browserstack 后触发(这是我的主要问题 - 我正在寻找注入此名称值的正确位置)
  2. 测试有时会以错误的名称记录 - 多个测试将使用相同的名称

我应该使用哪个事件来实现我的目标?

【问题讨论】:

    标签: codeception browserstack


    【解决方案1】:

    查看 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.
    

    这似乎产生了与我原来的问题相同的错误,

    1. 有些测试没有设置名称
    2. 某些测试具有先前测试集的名称

    编辑: 发生上述情况的原因是因为在我的环境文件/设备定义中有一个声明

     modules:
      enabled:
       - WebDriver
    

    删除 enabled 和 webdriver 定义允许回退到 accept.suite.yml 上,然后按预期正常工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-29
      • 2017-07-21
      • 1970-01-01
      • 2021-05-25
      相关资源
      最近更新 更多