fieldValueEquals fails on textarea with goutte driver
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"
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 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.
So this is isn't a problem anymore?
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.
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?
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.
Maybe you can add failing test (via PR) in https://github.com/minkphp/Mink/tree/master/driver-testsuite that will demonstrate the problem?