Skip to content

Instantly share code, notes, and snippets.

@pbuyle
Last active January 25, 2024 23:25
Show Gist options
  • Select an option

  • Save pbuyle/7698675 to your computer and use it in GitHub Desktop.

Select an option

Save pbuyle/7698675 to your computer and use it in GitHub Desktop.

Revisions

  1. pbuyle revised this gist Mar 12, 2014. 1 changed file with 19 additions and 0 deletions.
    19 changes: 19 additions & 0 deletions LICENSE
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    Copyright (c) 2014 Pierre Buyle

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
  2. pbuyle revised this gist Mar 12, 2014. 1 changed file with 0 additions and 7 deletions.
    7 changes: 0 additions & 7 deletions LICENSE
    Original file line number Diff line number Diff line change
    @@ -1,7 +0,0 @@
    Copyright © 2014 Pierre Buyle

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  3. pbuyle revised this gist Mar 12, 2014. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions LICENSE
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    Copyright © 2014 Pierre Buyle

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  4. pbuyle revised this gist Nov 28, 2013. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions example.feature
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,5 @@
    Scenario: Conditional display of textfield
    Given I am on "/custon/form"
    And I select the radio button "Show foo"
    Then I should see an "University" textfield form element
    And I should not see an "Anti-Doping Organization" textfield form element
    And I should not see an "Other" textfield form element
    Then I should see a "Foo" textfield form element
    And I should not see a "Bar" textfield form element
  5. pbuyle revised this gist Nov 28, 2013. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions example.feature
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    @javascript
    Scenario: Conditional display of textfield
    Given I am on "/custon/form"
    And I select the radio button "Show foo"
    Then I should see an "University" textfield form element
    And I should not see an "Anti-Doping Organization" textfield form element
    And I should not see an "Other" textfield form element
  6. pbuyle created this gist Nov 28, 2013.
    103 changes: 103 additions & 0 deletions FeatureContext.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,103 @@
    <?php

    use Behat\Behat\Context\ClosuredContextInterface,
    Behat\Behat\Context\TranslatedContextInterface,
    Behat\Behat\Context\BehatContext,
    Behat\Behat\Exception\PendingException;
    use Behat\Gherkin\Node\PyStringNode,
    Behat\Gherkin\Node\TableNode;

    /**
    * Features context.
    */
    class FeatureContext extends \Drupal\DrupalExtension\Context\DrupalContext {
    /**
    * Initializes context.
    * Every scenario gets it's own context object.
    *
    * @param array $parameters context parameters (set them up through behat.yml)
    */
    public function __construct(array $parameters) {
    // Initialize your context here
    }


    /**
    * Checks, that form element with specified label is visible on page.
    *
    * @Then /^(?:|I )should see an? "(?P<label>[^"]*)" form element$/
    */
    public function assertFormElementOnPage($label) {
    $element = $this->getSession()->getPage();
    $nodes = $element->findAll('css', '.form-item label');
    foreach ($nodes as $node) {
    if ($node->getText() === $label) {
    if ($node->isVisible()) {
    return;
    }
    else {
    throw new \Exception("Form item with label \"$label\" not visible.");
    }
    }
    }
    throw new \Behat\Mink\Exception\ElementNotFoundException($this->getSession(), 'form item', 'label', $label);
    }

    /**
    * Checks, that form element with specified label and type is visible on page.
    *
    * @Then /^(?:|I )should see an? "(?P<label>[^"]*)" (?P<type>[^"]*) form element$/
    */
    public function assertTypedFormElementOnPage($label, $type) {
    $container = $this->getSession()->getPage();
    $pattern = '/(^| )form-type-' . preg_quote($type). '($| )/';
    $label_nodes = $container->findAll('css', '.form-item label');
    foreach ($label_nodes as $label_node) {
    // Note: getText() will return an empty string when using Selenium2D. This
    // is ok since it will cause a failed step.
    if ($label_node->getText() === $label
    && preg_match($pattern, $label_node->getParent()->getAttribute('class'))
    && $label_node->isVisible()) {
    return;
    }
    }
    throw new \Behat\Mink\Exception\ElementNotFoundException($this->getSession(), $type . ' form item', 'label', $label);
    }

    /**
    * Checks, that element with specified CSS is not visible on page.
    *
    * @Then /^(?:|I )should not see an? "(?P<label>[^"]*)" form element$/
    */
    public function assertFormElementNotOnPage($label) {
    $element = $this->getSession()->getPage();
    $nodes = $element->findAll('css', '.form-item label');
    foreach ($nodes as $node) {
    // Note: getText() will return an empty string when using Selenium2D. This
    // is ok since it will cause a failed step.
    if ($node->getText() === $label && $node->isVisible()) {
    throw new \Exception();
    }
    }
    }

    /**
    * Checks, that form element with specified label and type is not visible on page.
    *
    * @Then /^(?:|I )should not see an? "(?P<label>[^"]*)" (?P<type>[^"]*) form element$/
    */
    public function assertTypedFormElementNotOnPage($label, $type) {
    $container = $this->getSession()->getPage();
    $pattern = '/(^| )form-type-' . preg_quote($type). '($| )/';
    $label_nodes = $container->findAll('css', '.form-item label');
    foreach ($label_nodes as $label_node) {
    // Note: getText() will return an empty string when using Selenium2D. This
    // is ok since it will cause a failed step.
    if ($label_node->getText() === $label
    && preg_match($pattern, $label_node->getParent()->getAttribute('class'))
    && $label_node->isVisible()) {
    throw new \Behat\Mink\Exception\ElementNotFoundException($this->getSession(), $type . ' form item', 'label', $label);
    }
    }
    }
    }