minkphp / driver-testsuite

Functional testsuite for Mink drivers
MIT License
8 stars 29 forks source link

Remove syntax erroring javascript #31

Closed robertfausk closed 5 years ago

robertfausk commented 5 years ago

...because function () {document.querySelector("h1").textContent = "Hello world";}() and function () {document.querySelector("h1").textContent = "Hello world";}(); are throwing a SyntaxError which leads to failing tests at least when executed with chrome web driver.

image

stof commented 5 years ago

Well, they could be supported until now, and they used to work. So they might be used in the wild. That's precisely why we have them in the testsuite.

It is true that Selenium does not support passing that syntax directly, but our Selenium2Driver handles that transparently.

stof commented 5 years ago

To explain where this come from, in the early days on Mink (before this common driver testsuite was created), each driver was supporting what it wanted for this executeScript signature. When building the common testsuite, we identified the different syntaxes supported by each driver, and then we ensured that all drivers were supporting all of them. This syntax is not valid JS by itself. But wrap it in parenthesis and it becomes valid JS again. That's how it was a supported syntax in some of the drivers, as they were doing this parenthesis wrapping.

robertfausk commented 5 years ago

First it felt a little bit hacky but it's also a nice feature.

For clarification if other users stumbling across this, see implementation detail on: https://github.com/minkphp/MinkSelenium2Driver/blob/v1.3.1/src/Selenium2Driver.php#L894-L897

Working example: image

stof commented 5 years ago

For reference, the driver which supported this syntax natively (but was missing some other syntax) was Sahi.