Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Clarify why SpinnedMinkSteps and WebsiteInteractionSteps both have "element exists" steps #11

Open
1 task
bakoe opened this issue Sep 3, 2018 · 0 comments
Labels

Comments

@bakoe
Copy link
Collaborator

bakoe commented Sep 3, 2018

Actual

Currently, the following two seemingly equivalent methods exist:

  • WebsiteInteractionSteps::waitForMatchingElementsWithinSpecifiedTime
  • SpinnedMinkSteps::assertElementOnPageWithinSpecifiedTime

The WebsiteInteractionSteps method uses plain JavaScript (note line 51):

/**
* Waits asynchronously until elements matching the given selector are existing
* Example: Then I see elements matching ".content" within 3 seconds
*
* @Then /^I see elements matching "(?P<selector>[^"]+)" within (?P<seconds>\d+) seconds?$/
* @Then /^sehe ich auf "(?P<selector>[^"]+)" passende Elemente innerhalb von (?P<seconds>\d+) Sekunden?$/
* @throws ExpectationException
*/
public function waitForMatchingElementsWithinSpecifiedTime($selector, $seconds)
{
$didFindElements = $this->getSession()->wait(
$seconds * 1000,
'document.querySelectorAll(' . json_encode($selector) . ').length'
);
if ($didFindElements === false) {
throw new ExpectationException(
'Element(s) matching "' . $selector . '" could not be found within ' . $seconds . ' seconds',
$this->getSession()->getDriver()
);
}
}

The SpinnedMinkSteps method internally uses the default MinkContext::assertElementOnPage method which in turn converts the given CSS selector into XPath and uses XPath to search for the element(s) (note lines 165 to 168):

https://github.com/minkphp/Mink/blob/d5ee350c40baff5f331a05ebdbe1927345c9ac8b/src/Element/Element.php#L151-L169

Points of Discussion

  • Do we need both variants (using JavaScript for CSS selection and using the Driver's internal XPath matching ability)? If not, can we remove the WebsiteInteractionSteps method in favor of the spinned variant of MinkContext's default method?
@bakoe bakoe added the question label Sep 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant