Problem/Motivation

The element selector type "CSS, XPath" in PHPDocs in core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php should be lowercase. It can be confusing.

https://www.drupal.org/project/drupal/issues/2892440#comment-13111427

https://www.drupal.org/project/drupal/issues/3041768#comment-13031018

diff --git a/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php b/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php
index 959b663d20..21a62d22fb 100644
--- a/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php
+++ b/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php
@@ -200,7 +200,7 @@ public function waitOnAutocomplete() {
    * Drupal CI Javascript tests by default use a viewport of 1024x768px.
    *
    * @param string $selector_type
-   *   The element selector type (CSS, XPath).
+   *   The element selector type (css, xpath).
    * @param string|array $selector
    *   The element selector. Note: the first found element is used.
    * @param bool|string $corner
@@ -243,7 +243,7 @@ public function assertVisibleInViewport($selector_type, $selector, $corner = FAL
    * Note: the node should exist in the page, otherwise this assertion fails.
    *
    * @param string $selector_type
-   *   The element selector type (CSS, XPath).
+   *   The element selector type (css, xpath).
    * @param string|array $selector
    *   The element selector. Note: the first found element is used.
    * @param bool|string $corner

vendor/behat/mink/src/Exception/ElementNotFoundException.php using lowercase in conditional in_array($selector, array('css', 'xpath')) so $selector is case sensitive.

class ElementNotFoundException extends ExpectationException
{
    /**
     * Initializes exception.
     *
     * @param DriverInterface|Session $driver   driver instance
     * @param string                  $type     element type
     * @param string                  $selector element selector type
     * @param string                  $locator  element locator
     */
    public function __construct($driver, $type = null, $selector = null, $locator = null)
    {
        $message = '';

        if (null !== $type) {
            $message .= ucfirst($type);
        } else {
            $message .= 'Tag';
        }

        if (null !== $locator) {
            if (null === $selector || in_array($selector, array('css', 'xpath'))) {
                $selector = 'matching '.($selector ?: 'locator');
            } else {
                $selector = 'with '.$selector;
            }
            $message .= ' '.$selector.' "'.$locator.'"';
        }

        $message .= ' not found.';

        parent::__construct($message, $driver);
    }
}

It means that element selector type should be "css" or "xpath", not "CSS" or "XPath".

/**
 * Checks that specific element exists on the current page.
 *
 * @param string           $selectorType element selector type (css, xpath)
 * @param string|array     $selector     element selector
 * @param ElementInterface $container    document to check against
 *
 * @return NodeElement
 *
 * @throws ElementNotFoundException
 */
public function elementExists($selectorType, $selector, ElementInterface $container = null)
{
    $container = $container ?: $this->session->getPage();
    $node = $container->find($selectorType, $selector);

    if (null === $node) {
        if (is_array($selector)) {
            $selector = implode(' ', $selector);
        }

        throw new ElementNotFoundException($this->session->getDriver(), 'element', $selectorType, $selector);
    }

    return $node;
}

Proposed resolution

Change "CSS, XPath" to lowercase.

Remaining tasks

Check if it occurs in other files.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Krzysztof Domański created an issue. See original summary.

Krzysztof Domański’s picture

Status: Active » Needs review
Issue tags: +Quick fix
FileSize
1.14 KB

Only two cases.

$ grep -rni 'css[,] xpath' core
core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php:203:   *   The element selector type (CSS, XPath).
core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php:246:   *   The element selector type (CSS, XPath).
$ grep -rni 'xpath[,] css' core | wc -c
0
Krzysztof Domański’s picture

Title: The element selector type in JSWebAssert is case sensitive » The element selector type "CSS, XPath" in JSWebAssert should be lowercase
Issue summary: View changes
Krzysztof Domański’s picture

Issue summary: View changes

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

longwave’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll, +Bug Smash Initiative

The patch looks sensible and matches the other cases already in core:

core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php:249:   *   The element selector type (CSS, XPath).
core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php:292:   *   The element selector type (CSS, XPath).
core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php:485:   *   The element selector type (css, xpath).
core/tests/Drupal/Tests/WebAssert.php:985:   *   Element selector type (css, xpath).
core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTestBase.php:93:   *   Element selector type (css, xpath)

However it needs a minor reroll before it can be committed.

yogeshmpawar’s picture

Assigned: Unassigned » yogeshmpawar

Working on it.

yogeshmpawar’s picture

Assigned: yogeshmpawar » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
1.1 KB

Added updated patch.

longwave’s picture

Status: Needs review » Needs work
+++ b/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php
@@ -246,7 +246,7 @@ public function waitOnAutocomplete() {
+   *   The element selector type (css, XPath).

@@ -289,7 +289,7 @@ public function assertVisibleInViewport($selector_type, $selector, $corner = FAL
+   *   The element selector type (css, XPath).

"XPath" should also be in all lowercase in both places.

ankithashetty’s picture

Status: Needs work » Needs review
FileSize
1.1 KB
969 bytes

Updated the patch, thanks!

Before patch:

$ grep -rni 'css[,] xpath' core
core/tests/Drupal/Tests/WebAssert.php:985:   *   Element selector type (css, xpath).
core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php:249:   *   The element selector type (CSS, XPath).
core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php:292:   *   The element selector type (CSS, XPath).
core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php:485:   *   The element selector type (css, xpath).
core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTestBase.php:93:   *   Element selector type (css, xpath)

After patch:

$ grep -rni 'css[,] xpath' core
core/tests/Drupal/Tests/WebAssert.php:985:   *   Element selector type (css, xpath).
core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php:249:   *   The element selector type (css, xpath).
core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php:292:   *   The element selector type (css, xpath).
core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php:485:   *   The element selector type (css, xpath).
core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTestBase.php:93:   *   Element selector type (css, xpath)
longwave’s picture

Status: Needs review » Reviewed & tested by the community

Thank you, this looks good to go now.

  • lauriii committed 3e14e0b on 10.0.x
    Issue #3041900 by ankithashetty, Krzysztof Domański, yogeshmpawar,...

  • lauriii committed b04c08e on 9.4.x
    Issue #3041900 by ankithashetty, Krzysztof Domański, yogeshmpawar,...
lauriii’s picture

Version: 9.4.x-dev » 9.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed 3e14e0b and pushed to 10.0.x. Also cherry-picked to 9.4.x and 9.3.x since this impacts only documentation. Thanks!

  • lauriii committed 57269e4 on 9.3.x
    Issue #3041900 by ankithashetty, Krzysztof Domański, yogeshmpawar,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.