drevops / behat-screenshot

🧪 Behat extension and step definitions to create HTML and image screenshots on demand or when tests fail
GNU General Public License v3.0
22 stars 7 forks source link

Update screenshot filename to be based on the step #4

Closed AlexSkrypnyk closed 7 years ago

AlexSkrypnyk commented 7 years ago

Important: Remove all conflicting config code.

Also, please update readme file.

Pseudo-code:

  /**
   * Init values required for snapshots.
   *
   * @BeforeStep
   */
  public function beforeScenarioScreenshotInit(BeforeStepScope $scope) {
    $this->screenshotScenarioStartedTimestamp = microtime(TRUE);
    $this->screenshotScope = $scope;
    $paths = $scope->getSuite()->getSetting('paths');
    $this->screenshotDir = getenv('BEHAT_SCREENSHOT_DIR') ? getenv('BEHAT_SCREENSHOT_DIR') : reset($paths) . '/screenshots';
  }

  /**
   * Make screenshot filename.
   *
   * Format: micro.seconds_title_of_scenario_trimmed.ext.
   *
   * @param string $ext
   *   File extension without dot.
   *
   * @return string
   *   Unique file name.
   */
  protected function makeScreenshotFileName($ext) {
    $fileName = basename($this->screenshotScope->getFeature()->getFile());
    $stepLine = $this->screenshotScope->getStep()->getLine();

    return sprintf('%s.%s_[%s].%s', $this->screenshotScenarioStartedTimestamp, $fileName, $stepLine, $ext);
  }

test feature


@testapi
Feature: Behat screenshots

  Ensure that Behat is capable of taking screenshots.

  @phpserver
  Scenario: Make HTML screenshot of the test page
    Given I am on the screenshot test page
    When I save screenshot
    Then file wildcard "*.api\.screenshot\.feature_\[9\]\.html" should exist

```****
bladeaweb commented 7 years ago

Closed by PR #7