Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

[Behat] WIP Improve structure and usability of PlatformUI behat Contexts #602

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

miguelcleverti
Copy link

@miguelcleverti miguelcleverti commented Jun 1, 2016

NOT YET FOR MERGE

This PR refactors the platfomui behat contexts in order to make them more decoupled and usable.
Main objectives:

  • Remove the BehatBubdle Browser Context dependency from PlatformUI Context
  • Remove all traits and make them into Contexts classes
  • Separate CommonsActions trait into specific Contexts
  • Add/improve DOCs
  • Improve namespaces/organization?
  • Improve/shorten behat_suite.yml?

Also added a easier way to gather contexts by using annotations in the properties specifying the context needed.
There are a lot of changes here but most of it is code that has already been reviewed.

depends on:

@miguelcleverti
Copy link
Author

miguelcleverti commented Jun 1, 2016

ping @bdunogier @joaoinacio @andrerom

{
$this->sleep();
$result = $this->getElementByText($message, '.ez-notification-text');
Assertion::AssertNotNull($result);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instance var not really necessary, if not for consistency maybe?

@ezrobot
Copy link

ezrobot commented Jun 27, 2016

This Pull Request does not respect PSR-2 Coding Standards, please, see the suggested diff below:

Loaded config from "/jenkins/jenkins.std/jobs/PlatformUIBundle-Pull-Request-checker/workspace/.php_cs"
.............F.....
Legend: ?-unknown, I-invalid file syntax, file ignored, .-no changes, F-fixed, E-error
   1) Features/Context/SubContext/BrowserContext.php (unused_use)
      ---------- begin diff ----------
      --- Original
      +++ New
      @@ @@

      -use EzSystems\BehatBundle\Helper\EzAssertion;
       use EzSystems\PlatformUIBundle\Features\Context\PlatformUI;
       use EzSystems\PlatformBehatBundle\Helper\Xpath;

       class BrowserContext extends PlatformUI
       {
           /**
            * @Given I clicked on/at (the) :link link
            * @When  I click on/at (the) :link link
            *
            * Click a link with text ':link'
            */
           public function clickLink($link)
           {
               $this->clickElementByText($link, 'a');
           }

           /**
            * @Given I clicked on/at (the) :button button
            * @When I click on/at (the) :button button
            *
            * Clicks the button identified by ':button'
            */
           public function iClickAtButton($button)
           {
               $this->clickElementByText($button, 'button');
           }

           /**
            * @When I fill in :field with :value
            * @When I set :field as empty
            *
            * Spin function make it possible to retry in case of failure
            */
           public function fillFieldWithValue($field, $value = '')
           {
               $fieldNode = $this->spin(
                   function () use ($field) {
                       $fieldNode = $this->getSession()->getPage()->findField($field);
                       if ($fieldNode == null) {
                           throw new \Exception('Field not found');
                       }

                       return $fieldNode;
                   }
               );

               $this->spin(
                   function () use ($fieldNode, $field, $value) {
                       // make sure any autofocus elements don't mis-behave when setting value
                       $fieldNode->blur();
                       usleep(10 * 1000);
                       $fieldNode->focus();
                       usleep(10 * 1000);

                       // setting value on pre-filled inputs can cause issues, clearing before
                       $fieldNode->setValue('');
                       $fieldNode->setValue($value);

                       // verication that the field was really filled in correctly
                       $this->sleep();
                       $check = $this->getSession()->getPage()->findField($field)->getValue();
                       if ($check != $value) {
                           throw new \Exception('Failed to set the field value: ' . $check);
                       }

                       return true;
                   }
               );
           }

           /**
            * @Then I (should) see :title title/topic
            */
           public function iSeeTitle($title)
           {
               $page = $this->getSession()->getPage();
               $this->spin(
                   function () use ($title, $page) {
                       $titleElements = $page->findAll('css', 'h1, h2, h3');
                       foreach ($titleElements as $titleElement) {
                           $elementText = $titleElement->getText();
                           if ($elementText == $title) {
                               return $titleElement;
                           }
                       }
                       throw new \Exception("Title '$title' not found");
                   }
               );
           }

           /**
            * @Then I should see a :label input field
            */
           public function seeInputField($label)
           {
               $field = $this->getSession()->getPage()->findField($label);
               if (!$field) {
                   throw new \Exception("Field '$label' not found");
               }
           }

           /**
            * @Given I checked :label checkbox
            * @When  I check :label checkbox
            *
            * Toggles the value for the checkbox with name ':label'
            */
           public function checkOption($option)
           {
               $session = $this->getSession();
               $selectorsHandler = $session->getSelectorsHandler();
               $literal = $selectorsHandler->xpathLiteral($option);

               // To be able to work on mink 1.6 (ezplatform) & mink 1.5 (5.4+ezpublish-community) w/o deprecation exceptions
               $selector = $selectorsHandler->isSelectorRegistered('named_partial') ?
                   $selectorsHandler->getSelector('named_partial') :
                   $selectorsHandler->getSelector('named');
               $xpath = $selector->translateToXPath(array('field', $literal));

               $fieldElement = $session->getPage()->find('xpath', $xpath);
               $fieldElement->check();
           }
       }


      ---------- end diff ----------

Fixed all files in 16.341 seconds, 8.500 MB memory used

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

Successfully merging this pull request may close these issues.

3 participants