'Verifies that the page contains the given number of elements located by the given `locator`.
See `introduction` for details about locating elements.
See `Page Should Contain Element` for explanation about `message` and
`loglevel` arguments.'

@keyword
def locator_should_match_x_times(self, locator, expected_locator_count, message='', loglevel='INFO'):

    actual_locator_count = len(self.find_element(locator, first_only=False, required=False))
    if (int(actual_locator_count) != int(expected_locator_count)):
        if (not message):
            message = ('Locator    %s    should    have    matched    %s    times    but    matched    %s    times' % (locator, expected_locator_count, actual_locator_count))
        self.ctx.log_source(loglevel)
        raise AssertionError(message)
    self.info(("Current    page    contains    %s    elements    matching    '%s'." % (actual_locator_count, locator)))
