Skip to content

change buildTestName for behat/gherkin  #70

@DolgushinG

Description

@DolgushinG

Hey guys, we've problem using allure in our project.(codeception 3.0.2 + behat/gherkin 4.4.0 + allure 1.4.0 )

Summary: when we run .features in codeception , allure generates xml file using name feature instead name scenario. And when in one feature there are few scenario, than allure generate just last scenario.

For example

Feature: FooterLinksTest
I want to check all links in footer

Background:
    When I log in to the site, i click button

    @footerLinksTest
    Scenario: footerLinksTest
        Then check links in Footer

   @HeaderLinksTest
    Scenario: HeadeLinksTest
        Then check links in Header

after run .feature FooterLinksTest
we get a result allure xml

<?xml version="1.0" encoding="UTF-8"?>
<alr:test-suite xmlns:alr="urn:model.allure.qatools.yandex.ru" start="1621868275968" stop="1621868340898" version="1.4.0">
  <name>acceptance (chromeheadless)</name>
  <test-cases>
    <test-case start="1621868280976" stop="1621868340846" status="passed">
      <name>HeadeLinksTest</name>
      <steps>
        <step start="1621868281331" stop="1621868281331" status="passed">
          <name>  i want to check all links in Header </name>
        </step>
      </steps>
      <labels>
        <label name="footerLinksTest" value="feature"/>
      </labels>
    </test-case>
  </test-cases>
</alr:test-suite>

and first scenario was lost

SOLUTION

if you change this
$testName = $test->getMetadata()->getFeature();
to this
$testName = $test->getScenarioNode()->getTitle();

private function buildTestName($test) {
    $testName = get_class($test->getTestClass()) . '::' . $test->getName();
    if ($test instanceof Cest) {
        if(isset($this->testInvocations[$testName])) {
            $this->testInvocations[$testName]++;
        } else {
            $this->testInvocations[$testName] = 0;
        }
        $currentExample = $test->getMetadata()->getCurrent();
        if ($currentExample && isset($currentExample['example']) ) {
            $testName .= ' with data set #' . $this->testInvocations[$testName];
        }
    } else if($test instanceof Gherkin) {
         $testName = $test->getScenarioNode()->getTitle();
    }
    return $testName;
}

after changed allure generates every scenario

What do you think about it? or did you miss something ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions