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

Simplify and speedup Elements #74

Open
spolischook opened this issue Oct 1, 2016 · 2 comments
Open

Simplify and speedup Elements #74

spolischook opened this issue Oct 1, 2016 · 2 comments

Comments

@spolischook
Copy link

For now we have two types of Elements, but they do the same things, and have the same purpose.
First of all Elements configuration must be unified.
I suggest to add names for Custom elements, and add classes for Inline Elements - it's only that needed for merge them.
So we will have the next configuration in behat.yml:

default:
  extensions:
    SensioLabs\Behat\PageObjectExtension:
      elements:
        Search form:
          selector: 'form#search'
          class: SensioLabs\Behat\PageObjectExtension\PageObject\InlineElement
        Navigation:
          selector: {'css': '.header div.navigation'}
          class: Acme\DemoBundle\Tests\Behat\Page\Element\Navigation

And configuration for Inline Elements:

<?php

namespace Page;

use SensioLabs\Behat\PageObjectExtension\PageObject\Page;

class Homepage extends Page
{
    // ...

    protected $elements = array(
        'Search form' => [
          'selector' => 'form#search',
          'class' => 'SensioLabs\Behat\PageObjectExtension\PageObject\InlineElement',
        ],
        'Navigation' => array(
          'selector' => ['css' => '.header div.navigation'],
          'class' => Acme\DemoBundle\Tests\Behat\Page\Element\Navigation,
        )
      );

    // ...

So what do you think about it?
As side effect you don't need to guess Element class anymore (that can be performance issue by the way), you are always know what instance you must create.

@jakzal
Copy link
Member

jakzal commented Oct 2, 2016

I'm a bit sceptical to adding anything to the configuration.

What about moving away from named elements to using classes? With the class constant it would be very easy: getPage(Homepage::class). It would only be possible to access inline elements from within the page object, so we'd only need to handle it there.

@spolischook
Copy link
Author

Names of elements is very useful in my cases. I have some common step definition:

<?php

    /**
     * Fill form with data
     * Example: And fill form with:
     *            | Subject     | Simple text     |
     *            | Users       | [Charlie, Pitt] |
     *            | Date        | 2017-08-24      |
     *
     * @When /^(?:|I )fill "(?P<formName>(?:[^"]|\\")*)" form with:$/
     * @When /^(?:|I )fill form with:$/
     */
    public function iFillFormWith(TableNode $table, $formName = "OroForm")
    {
        /** @var Form $form */
        $form = $this->createElement($formName);
        $form->fill($table);
    }

And create form by element name.
About class for inline elements - it's also needed so much. For example if I have two TinyMce on form I can use two selectors and one Element.

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

2 participants