Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature file does not recognize an implemented step #6704

Open
gafi9 opened this issue Oct 12, 2023 · 0 comments
Open

Feature file does not recognize an implemented step #6704

gafi9 opened this issue Oct 12, 2023 · 0 comments

Comments

@gafi9
Copy link

gafi9 commented Oct 12, 2023

I'm trying to make a POC using Codeconcept with BDD. I've created a stepobject and I wanted to use this file for test steps. I've followed CONFIGURATION section to autoload the additional steps file since only context files can contain these. When I run php vendor/bin/codecept gherkin:steps Acceptance I get this as a result:

Steps from default context:

+-----------------------------------------+---------------------------------------------------------
| Step                                    | Implementation                                                 
+-----------------------------------------+---------------------------------------------------------
| The user logs in with the default user. | Tests\Support\Step\Acceptance\LoginSteps::loginWithDefaultUser |
+-----------------------------------------+---------------------------------------------------------

When I run the test with php vendor/bin/codecept run --debug the test runs successfully, and when I run the test from PHPStorm itself, the test also runs successfully. Nonetheless the step is not recognised in the feature file and it is showed as an undefined step reference.

Below you can find all the specs, files, and steps I did:

Specs:

PHP version: 8.2.11
Codeception version: 5.0.11
System: Windows 10 / IDE: PHPStorm
Here are the steps I did:

I've installed codeconcept with composer require codeception/module-webdriver --dev
I've installed the webdriver module with composer require codeception/module-webdriver --dev --ignore-platform-req=ext-zip
I've run php vendor/bin/codecept bootstrap - this generated all suites
I've generated one pageobject file with php vendor/bin/codecept g:pageobject Acceptance Login
I've generated one stebobject file with php vendor/bin/codecept g:stepobject Acceptance LoginSteps
I've generated one feature file with php vendor/bin/codecept g:feature Acceptance coupon
This is how my directory looks like:

/codeception
├── codeception.yml
├── tests
│   ├── Acceptance.suite.yml
|   ├── Acceptance
|   |   └── coupon.feature
│   ├── Support
│   │   ├── AcceptanceTester.php
│   │   ├── Step
│   │   │   └── Acceptance
│   │   │       └── LoginSteps.php
|   |   ├── Page
|   |   |   └── Acceptance
|   |   |       └── Login.php

This is the content of codeception.yml:

namespace: Tests
support_namespace: Support
paths:
    tests: tests
    output: tests/_output
    data: tests/Support/Data
    support: tests/Support
    envs: tests/_envs
actor_suffix: Tester
extensions:
    enabled:
        - Codeception\Extension\RunFailed

params:
    - .env

This is the content of Acceptance.suite.yml:

actor: AcceptanceTester
modules:
    enabled:
        - WebDriver:
            url: 'https://test.com/'
            browser: chrome

# add Codeception\Step\Retry trait to AcceptanceTester to enable retries
step_decorators:
    - Codeception\Step\ConditionalAssertion
    - Codeception\Step\TryTo
    - Codeception\Step\Retry

gherkin:
    contexts:
        path: tests/Support/Step
        namespace_prefix: Tests\Support\Step
        default:
            - Tests\Support\AcceptanceTester

This is the content of Login.php:

namespace Tests\Support\Page\Acceptance;

use Tests\Support\AcceptanceTester;

class Login
{
    public string $accountField = "input[name='account']";
    public string $emailField = "input[name='mail']";
    public string $passwordField = "input[name='password']";
    public string $loginButton = "button[type='submit']";

    /**
     * @var AcceptanceTester;
     */
    protected AcceptanceTester $acceptanceTester;

    public function __construct(AcceptanceTester $I)
    {
        $this->acceptanceTester = $I;
    }

    public function fillAccountField(string $account): void
    {
        $this->acceptanceTester->fillField($this->accountField, $account);
    }

    public function fillEmailField(string $email): void
    {
        $this->acceptanceTester->fillField($this->emailField, $email);
    }

    public function fillPasswordField(string $password): void
    {
        $this->acceptanceTester->fillField($this->passwordField, $password);
    }

    public function clickLoginButton(): void
    {
        $this->acceptanceTester->click($this->loginButton);
    }

}

This is the content of LoginSteps.php:

namespace Tests\Support\Step\Acceptance;

use Codeception\Attribute\When;
use Tests\Support\AcceptanceTester;
use Tests\Support\Page\Acceptance\Login;

class LoginSteps
{

    protected AcceptanceTester $acceptanceTester;

    public function __construct(AcceptanceTester $I)
    {
        $this->acceptanceTester = $I;
    }

    #[When('The user logs in with the default user.')]
    public function loginWithDefaultUser(): void
    {
        $this->acceptanceTester->amOnPage("/");
        $loginPage = new Login($this->acceptanceTester);
        $loginPage->fillAccountField($_ENV['BRAND_NAME']);
        $loginPage->fillEmailField($_ENV['DEFAULT_USERNAME']);
        $loginPage->fillPasswordField($_ENV['DEFAULT_PASSWORD']);
        $loginPage->clickLoginButton();
    }

}

This is the content of coupon.feature:

Feature: coupon

  Scenario: try coupon
    * The user logs in with the default user. - THIS STEP IS NOT RECOGNIZED!

Am I missing something here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant