<commit_before>Working with page objects
=========================

Creating a page object class
----------------------------

To create a new page object extend the
``SensioLabs\Behat\PageObjectExtension\PageObject\Page`` class:

    .. code-block:: php

        <?php

        namespace Page;

        use SensioLabs\Behat\PageObjectExtension\PageObject\Page;

        class Homepage extends Page
        {
        }

Instantiating a page object
---------------------------

Using the page object factory
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Pages are created with a built in factory. One of the ways to use them in your
context is to call the ``getPage`` method provided by the
``SensioLabs\Behat\PageObjectExtension\Context\PageObjectContext``:

    .. code-block:: php

        <?php

        use SensioLabs\Behat\PageObjectExtension\Context\PageObjectContext;

        class SearchContext extends PageObjectContext
        {
            /**
             * @Given /^(?:|I )search for (?P<keywords>.*?)$/
             */
            public function iSearchFor($keywords)
            {
                $this->getPage('Homepage')->search($keywords):
            }
        }

    .. note::

        Alternatively you could implement the
        ``SensioLabs\Behat\PageObjectExtension\Context\PageObjectAwareInterface``.

Page factory finds a corresponding class by the passed name:

* *"Homepage"* becomes a *"Homepage"* class
* *"Article list"* becomes an *"ArticleList"* class
* *"My awesome page"* becomes a *"MyAwesomePage"* class

    .. note::

        It is possible to implement your own way of mapping a page name to
        an appropriate page object with a :doc:`custom factory </cookbooks/custom_factory>`.

Injecting page objects into a context file
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It is possible to avoid using page object factory explicitly, and inject
page objects directly into a context file.

    .. code-block:: php

        <?php
<commit_msg>Replaces colon with semicolon in PageObjectContext example<commit_after>Working with page objects
=========================

Creating a page object class
----------------------------

To create a new page object extend the
``SensioLabs\Behat\PageObjectExtension\PageObject\Page`` class:

    .. code-block:: php

        <?php

        namespace Page;

        use SensioLabs\Behat\PageObjectExtension\PageObject\Page;

        class Homepage extends Page
        {
        }

Instantiating a page object
---------------------------

Using the page object factory
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Pages are created with a built in factory. One of the ways to use them in your
context is to call the ``getPage`` method provided by the
``SensioLabs\Behat\PageObjectExtension\Context\PageObjectContext``:

    .. code-block:: php

        <?php

        use SensioLabs\Behat\PageObjectExtension\Context\PageObjectContext;

        class SearchContext extends PageObjectContext
        {
            /**
             * @Given /^(?:|I )search for (?P<keywords>.*?)$/
             */
            public function iSearchFor($keywords)
            {
                $this->getPage('Homepage')->search($keywords);
            }
        }

    .. note::

        Alternatively you could implement the
        ``SensioLabs\Behat\PageObjectExtension\Context\PageObjectAwareInterface``.

Page factory finds a corresponding class by the passed name:

* *"Homepage"* becomes a *"Homepage"* class
* *"Article list"* becomes an *"ArticleList"* class
* *"My awesome page"* becomes a *"MyAwesomePage"* class

    .. note::

        It is possible to implement your own way of mapping a page name to
        an appropriate page object with a :doc:`custom factory </cookbooks/custom_factory>`.

Injecting page objects into a context file
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It is possible to avoid using page object factory explicitly, and inject
page objects directly into a context file.

    .. code-block:: php

        <?php

{'fraction_non_alphanumeric': 0.15608531994981178, 'fraction_numerical': 0.0, 'mean_word_length': 2.5494211932324133, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5817106', 'n_tokens_mistral': 1057, 'n_tokens_neox': 987, 'n_words': 352}