Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-66559

Components should be able to define their own named selectors

    XMLWordPrintable

Details

    Description

      We have partial and exact named selectors in core.
      These are defined in lib/behat/classes/*_named_selector.php and are essentially a mapping of human-readable things, to xpath replacements.

      We use these quite a bit (as we should) to make things understandable.

      For example, we have one to translate the "dialogue" xpath so that, instead of writing:

      I click on "Cancel" "button' in the ".//div[contains(concat(' ', normalize-space(@class), ' '), ' moodle-dialogue ') and
          normalize-space(descendant::div[
              contains(concat(' ', normalize-space(@class), ' '), ' moodle-dialogue-hd ')
              ]) = %locator%] |
      .//div[contains(concat(' ', normalize-space(@class), ' '), ' yui-dialog ') and
          normalize-space(descendant::div[@class='hd']) = %locator%]
              |
      .//div[@data-region='modal' and descendant::*[@data-region='title'] = %locator%]
              |
      .//div[
              contains(concat(' ', normalize-space(@class), ' '), ' modal-content ')
                  and
              normalize-space(descendant::*[self::h4 or self::h5][contains(concat(' ', normalize-space(@class), ' '), ' modal-title ')]) = %locator%
          ]
              |
      .//div[
              contains(concat(' ', normalize-space(@class), ' '), ' modal ')
                  and
              normalize-space(descendant::*[contains(concat(' ', normalize-space(@class), ' '), ' modal-header ')] = %locator%)
          ]
      XPATH" "xpath_element"
      

      We can instead write:

      I click on "Cancel" "button' in the "Activity chooser" "dialogue"
      

      We have several of these already, and we're beginning to see component-specific ones being introduced. For example, messaging introduced a number of selectors relating to group messaging.

      I feel that we need to make it possible for components to do this.

      This will allow much clearer steps and better re-use of existing step definitinos.

      For example, it will be easy to write a named selector for "Discussion" and use all existing steps (And "Name your hobby" "mod_forum > Discussion" should exist")

      Attachments

        Issue Links

          Activity

            People

              dobedobedoh Andrew Lyons
              dobedobedoh Andrew Lyons
              Tim Hunt Tim Hunt
              Jake Dallimore Jake Dallimore
              CiBoT CiBoT
              Votes:
              1 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                11/Nov/19

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 1 day, 2 hours, 30 minutes
                  1d 2h 30m