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

Cannot make AM/PM part of behat contains assertion steps

XMLWordPrintable

      Was running local behat tests (MacOS) towards getting the Release testing matrix slowly completed when a few failures were detected.

      001 Scenario: Course forum summary report can be viewed by teacher and contains accurate data # /Users/stronk7/git_moodle/testing/mod/forum/report/summary/tests/behat/course_summary.feature:57
            And the following should exist in the "forumreport_summary_table" table:                # /Users/stronk7/git_moodle/testing/mod/forum/report/summary/tests/behat/course_summary.feature:63
              (//html/.//table[(./@id = 'forumreport_summary_table' or contains(.//caption, 'forumreport_summary_table') or contains(.//th, 'forumreport_summary_table') or contains(concat(' ', normalize-space(@class), ' '), 'forumreport_summary_table' ))])[1]/tbody/tr[descendant::th[normalize-space(.)='Student 1'] | descendant::td[normalize-space(.)='Student 1']]/child::*[position() = count((//html/.//table[(./@id = 'forumreport_summary_table' or contains(.//caption, 'forumreport_summary_table') or contains(.//th, 'forumreport_summary_table') or contains(concat(' ', normalize-space(@class), ' '), 'forumreport_summary_table' ))])[1]/thead/tr[1]/th[(normalize-space(.)='Earliest post' or a[normalize-space(text())='Earliest post'] or div[normalize-space(text())='Earliest post'])]/preceding-sibling::*) + 1][contains(normalize-space(.),'Thursday, 28 March 2019, 11:50 AM')]
              
              Column value matching locator "Thursday, 28 March 2019, 11:50 AM" in "Student 1" row with column "Earliest post" not found. (Behat\Mink\Exception\ElementNotFoundException)
       
      002 Scenario: Students given the view capability can view their own course report data # /Users/stronk7/git_moodle/testing/mod/forum/report/summary/tests/behat/course_summary.feature:89
            And the following should exist in the "forumreport_summary_table" table:         # /Users/stronk7/git_moodle/testing/mod/forum/report/summary/tests/behat/course_summary.feature:97
              (//html/.//table[(./@id = 'forumreport_summary_table' or contains(.//caption, 'forumreport_summary_table') or contains(.//th, 'forumreport_summary_table') or contains(concat(' ', normalize-space(@class), ' '), 'forumreport_summary_table' ))])[1]/tbody/tr[descendant::th[normalize-space(.)='Student 1'] | descendant::td[normalize-space(.)='Student 1']]/child::*[position() = count((//html/.//table[(./@id = 'forumreport_summary_table' or contains(.//caption, 'forumreport_summary_table') or contains(.//th, 'forumreport_summary_table') or contains(concat(' ', normalize-space(@class), ' '), 'forumreport_summary_table' ))])[1]/thead/tr[1]/th[(normalize-space(.)='Earliest post' or a[normalize-space(text())='Earliest post'] or div[normalize-space(text())='Earliest post'])]/preceding-sibling::*) + 1][contains(normalize-space(.),'Thursday, 25 January 2018, 4:40 PM')]
              
              Column value matching locator "Thursday, 25 January 2018, 4:40 PM" in "Student 1" row with column "Earliest post" not found. (Behat\Mink\Exception\ElementNotFoundException)
       
      003 Scenario: Add posts and view accurate summary report                                                                                 # /Users/stronk7/git_moodle/testing/mod/forum/report/summary/tests/behat/summary_data_post_dates.feature:7
            Then "Teacher 1" row "Earliest post" column of "forumreport_summary_table" table should contain "Tuesday, 2 January 2018, 9:00 AM" # /Users/stronk7/git_moodle/testing/mod/forum/report/summary/tests/behat/summary_data_post_dates.feature:50
              (//html/.//table[(./@id = 'forumreport_summary_table' or contains(.//caption, 'forumreport_summary_table') or contains(.//th, 'forumreport_summary_table') or contains(concat(' ', normalize-space(@class), ' '), 'forumreport_summary_table' ))])[1]/tbody/tr[descendant::th[normalize-space(.)='Teacher 1'] | descendant::td[normalize-space(.)='Teacher 1']]/child::*[position() = count((//html/.//table[(./@id = 'forumreport_summary_table' or contains(.//caption, 'forumreport_summary_table') or contains(.//th, 'forumreport_summary_table') or contains(concat(' ', normalize-space(@class), ' '), 'forumreport_summary_table' ))])[1]/thead/tr[1]/th[(normalize-space(.)='Earliest post' or a[normalize-space(text())='Earliest post'] or div[normalize-space(text())='Earliest post'])]/preceding-sibling::*) + 1][contains(normalize-space(.),'Tuesday, 2 January 2018, 9:00 AM')]
              
              Column value matching locator "Tuesday, 2 January 2018, 9:00 AM" in "Teacher 1" row with column "Earliest post" not found. (Behat\Mink\Exception\ElementNotFoundException)
      

      Looking to history... this was introduced by MDL-66594 some months ago.

      The problem here is that MacOS (and other BSD flavors), by default, produces all those time stamps with lowercase "AM/PM" and that', obviously, breaks the test.

      This is not the first time we face this. Also has happened a number of times within unit tests (although the fix is better there, because we can compare after converting to lower/upper). See for example MDL-66135.

      But here, within Behat, we cannot perform those modifications, and surely the case is not worth the creation of a new "should contain in case insensitive way" step. So the proposal is to just remove the "AM/PM" from the assertions and done. That way the text will be found, and the AM/PM aren't adding much there.

            stronk7 Eloy Lafuente (stronk7)
            stronk7 Eloy Lafuente (stronk7)
            Victor Déniz Falcón Victor Déniz Falcón
            Andrew Lyons Andrew Lyons
            CiBoT CiBoT
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 40 minutes
                1h 40m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.