twistersfury/codeception-gherkin

Page Object Helpers For Use In Codeception

v0.2.1 2019-07-13 02:06 UTC

This package is auto-updated.

Last update: 2024-05-13 12:35:39 UTC


README

codecov pipelines

Codeception Gherkin Page Object Helper

This project provides the default steps for the various Codeception modules. It leverages the concept of Page Object Models to allow you to easily configure specific elements without the need to put these directly in your feature files.

Steps

Add any of the included traits to your Tester Class. After adding, you can use the Codeception codecept gherkin:steps to see all options.

Available Traits

  • TwistersFury\Codeception\Gherkin\Module\Db
  • TwistersFury\Codeception\Gherkin\Module\WebDriver
Example Steps:
haveInDatabase
Scenario: Do Something
  Given I have in database "table"
    | field1 | field2 | field3 |
    | value 1| value 2| value #|
seeInDatabase
Scenario: Do Something
  Then I see in database "table"
    | field1 | field2 | field3 |
    | value 1| value 2| value #|

PageObject

Register your pages in the Codeception bootstrap file. The page name will be the identifier used in your gherkin feature files. The class name is the class to initialize. As part of your Scenario, use the I am on page step to initialize the page.

Your Page Objects must extend TwistersFury\Codeception\Gherkin\Page\AbstractPage and define the methods:

  • getUrl the relative url of the page.
  • getElementMap The map of elements (See Below)
  • getDefaultElement The default HTML element.

Element Maps

Element maps are used to define elements on the page. The selection system uses the Codeception Location class to build the selector in the command. If an element is requested that doesn't exist, then the requested is returned. Possible values for a mapping are:

  • method Location Method To Use. Options are:
    • find - Default -
    • href
    • name
  • attributes - Defines Search In find
  • element - Defines HTML element in find and name. Defaults to getDefaultElement
  • url - Used in href method.
Examples

bootstrap.php

<?php

use My\Pages\AdminPage;
use My\Pages\Signup;
use My\Pages\ProfilePage
use TwistersFury\Codeception\Gherkin\Page\Factory;

Factory::reset();
Factory::getInstance()->addPages(
   [
        'admin'  => AdminPage::class,
        'signup' => SignUp::class
   ]
);

Factory::getInstance()->addPage(
    'profile', ProfilePage::class
);

tests/_support/Pages/Signup.php

<?php

namespace My\Pages;

class Signup {
    protected function getDefaultElement(): string 
    {
        return 'input';
    }
    
    public function getUrl(): string 
    {
        return '/signup';
    }

    protected function getElementMap(): array
    {
        return [
            'signup' => [
                'element' => 'button',
                'attributes' => [
                    'class' => 'signup'
                ]
            ],
            'forgot-my-pass' => [
                'method' => 'href',
                'url'    => '/forgot-pass/'
            ],
            'username' => [
                'method' => 'name'
            ]
        ]; 
    }
}