Mink icon indicating copy to clipboard operation
Mink copied to clipboard

fieldValueEquals fails on textarea with goutte driver

Open ifdattic opened this issue 9 years ago • 7 comments

Assuming you have HTML with textarea containing a value:

<textarea id="comment" class="form-control" rows="3">Very well done with a few typos</textarea>

And you run the following in the step:

$this->assertSession()->fieldValueEquals('comment', $comment);

It would fail with Goutte driver as the value is null. This would work fine with Selenium driver. In my opinion it should work in both cases as you're not using any JS and the markup is correct.

Bellow is the dumps of the following lines:

$commentField = $this->assertSession()->elementExists('css', '#comment');

var_dump($commentField->getText());
var_dump($commentField->getValue());
# with goutte driver
/home/vagrant/peerfeedback/features/bootstrap/StudentFeedbackContext.php:89:
string(31) "Very well done with a few typos"
/home/vagrant/peerfeedback/features/bootstrap/StudentFeedbackContext.php:90:
NULL

# with selenium driver
/home/vagrant/peerfeedback/features/bootstrap/StudentFeedbackContext.php:89:
string(31) "Very well done with a few typos"
/home/vagrant/peerfeedback/features/bootstrap/StudentFeedbackContext.php:90:
string(31) "Very well done with a few typos"

ifdattic avatar Aug 11 '16 15:08 ifdattic

This seems to known limitation of Goutte driver because of underlying BrowserKit driver is treating {{ like template placeholders. I'm not 100% sure, that this is the case here, but it might be.

aik099 avatar Aug 11 '16 17:08 aik099

@aik099 Forgot to change that one, it's actually the Twig variable so on the normal page it's just normal Very well done with a few typos text.

ifdattic avatar Aug 12 '16 04:08 ifdattic

So this is isn't a problem anymore?

aik099 avatar Aug 12 '16 06:08 aik099

No, it's still the same issue. I just meant that it's actually normal text in HTML so {{ are not there to be treated as template placeholders.

ifdattic avatar Aug 12 '16 08:08 ifdattic

There is a test in driver test suite, that confirms, that Goutte can get current value from textarea (presuming that textarea initially had that value in HTML and it wasn't set later using JavaScript): https://github.com/minkphp/Mink/blob/master/driver-testsuite/tests/Form/GeneralTest.php#L168 (analog to $commentField->getValue() code from your example).

  • Maybe HTML markup of page you're testing is broken and being headless Goutte can't properly parse HTML and detect value inside textarea?
  • Or maybe you have 2 textareas with same name on the page?

aik099 avatar Aug 12 '16 08:08 aik099

That scenario needs any JavaScript (that is how I found this as after removing the @javascript tag it started to fail).

There was a few markup issues, but after fixing them the issue was not fixed.

No, there is only a single textarea on that page.

ifdattic avatar Aug 12 '16 14:08 ifdattic

Maybe you can add failing test (via PR) in https://github.com/minkphp/Mink/tree/master/driver-testsuite that will demonstrate the problem?

aik099 avatar Aug 12 '16 14:08 aik099