Problem/Motivation
Selenium driver rocks! But upload file does not work properly when working with remote files. See #2942900-13: Convert JavascriptTestBase Tests to use DrupalSelenium2Driver case #3.
We solved this problem with #2944291: Upgrade behat/mink-selenium2-driver to 1.3.x-dev thanks to the fix from @pfrenssen in dev branch.
This solves the problem when working with $field->attachFile()
. But there are other cases where it may be needed.
Good example $field->setValue()
.
setValue()
has an important advantage over the $field->attachFile()
, because it allows you to test fields with multiple attribute (https://github.com/w3c/webdriver/pull/505/files).
Proposed resolution
Unfortunately, we can not use \Behat\Mink\Driver\Selenium2Driver::uploadFile()
for get remote path to file. Because it is private method.
But we can just copy the code into our own method, as it is done in #2644468-85: Multiple image upload breaks image dimensions.
@borisson_ offered to make it like trait or maybe like method of our DrupalSelenium2Driver
class.
Remaining tasks
Choose the best place for the API.
Add the API (maybe full copy from parent uploadFile()
) + test coverage (maybe short version of #2644468-85).
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#21 | 2947517-21.patch | 5.41 KB | jibran |
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedvaplas created an issue. See original summary.
Comment #2
Anonymous (not verified) CreditAttribution: Anonymous commentedFirst attempt.
Comment #3
jibranI really like this idea. Thanks, for creating and working on the issue. Here are my suggestions:
Should we add some link here?
I'd prefer doing it in catch block rather than having
if
. I don't mind using unlink twice once inside the catch block once outside it.Let's use entity test instead.
If we want to use setValue then why are we using node form? Why not just use
Node::create()
to create the node?Comment #4
Anonymous (not verified) CreditAttribution: Anonymous commented@jibran, thanks for review and good suggestions!
I just full copied
\Behat\Mink\Driver\Selenium2Driver::uploadFile()
with only one change:Like and test just copied from our test to #2644468-85.
But I did not mind the additional edits :)
finally
(for Drupal 8 min version PHP 5.5)Also removed trait for image, because we can testing this with any file type.
Comment #5
jibranThanks, for addressing the feedback.
I didn't know about. Good to know.
In #3.4, my point was why to use FAPI at all we can test it just with entity API.
Comment #7
Anonymous (not verified) CreditAttribution: Anonymous commentedEntity API works directly without using webDriver, so we need FAPI (edit: Mink/Element). Or am I missing something?
Comment #9
mondrakeBumping to critical as this is a blocker for the last simpletest to be converted to JTB #2809503: Convert AJAX part of \Drupal\file\Tests\FileFieldWidgetTest to JavascriptTestBase and an helper for #2644468: Multiple image upload breaks image dimensions which is critical on its own.
Comment #10
LendudeNeeded a reroll and some waitFor stuff to make pass locally, lets see what the bot makes of this.
Comment #11
jibranReviewed it again didn't find anything objectionable so RTBC.
Comment #12
jibranCan we please mention vaplas's name in the commit message?
Comment #13
jibranCan we please move this to a trait so that Drupal testing trait can also use it?
Comment #14
Lendude@jibran good idea.
uploadFileAndGetRemoteFilePath
which might be a little verbose but I think is much clearer in its intent and purposeedit:
Also removed the scenario were the new method is not used to test if it is still needed, since that fails when the local en remote environment are the same (like my local setup), which is really confusing I think.
Comment #15
jibranI think it is better to have local vars instead of calling methods again and again.
Comment #16
larowlanshould we also do this in the happy-path? i.e when no exceptions occur?
+1 to what jibran said in #15
Comment #17
LendudeThis bit is always run, so I think we are good.
Addressed #15
Comment #18
jibranThanks! do we need a change notice for the new trait?
Comment #19
mondrakeAdding test for lowest PHP
Comment #20
alexpottI've tried to think of a better way to make this change - like maybe overriding \Behat\Mink\Driver\Selenium2Driver::attachFile() but we always hit the fact that \Behat\Mink\Driver\Selenium2Driver::uploadFile is private. So the solution of adding
uploadFileAndGetRemoteFilePath()
whilst clunky feels pragmatic.That said I don't think we should add a trait. It adds complex and surface area and the argument that this is needed for https://gitlab.com/weitzman/drupal-test-traits doesn't reflect that they will still need to provided their own implementation of \Behat\Mink\Driver\Selenium2Driver in order to implement the trait. Once they do that they could chose to extend \Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver or just use it if possible. Maybe something in \Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver::setCookie or \Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver::__construct() is doing something they don't want but in this case they can alter those methods.
Comment #21
jibranI agree. I don't see any reason for DTT to not use
DrupalSelenium2Driver
instead ofSelenium2Driver
inSelenium2DriverTrait
. https://gitlab.com/weitzman/drupal-test-traits/issues/42 can address that.Following patch removes the trait.
Comment #22
jibranDo we need to add ext-zip in composer.json but this is test only change so I'm not sure? This is the only place in core where we are using it. Should we use \Drupal\Core\Archiver\Zip instead?
Comment #23
jibran@alexpott replied in slack to my questions
This is a c&p from the library
http://php.net/manual/en/class.ziparchive.php is part of PHP since 5.2
I just moved the code in #21 so setting it back to RTBC.
Comment #24
LendudeTiny nit
; at the end
other then that, RTBC +1
Comment #25
alexpottFixed on commit.
Comment #26
alexpottCommitted 2c4ca06 and pushed to 8.7.x.
Committed f481697ca1 and pushed to 8.6.x. Thanks!
Also fixed this lot.