Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
DrupalExtension is an extension for Behat which makes it easier to test a Drupal application. One of it's features is that it allows normal Drupal modules to provide Behat sub contexts by simply implementing them in a file called module_name.behat.inc within the module. Sub contexts allow you to provide new step definitions to Behat.
It seems like a great idea to me for chosen to provide a Behat subcontext which allows a developer to manipulate chosen page elements via behat and assert their current state.
Comment | File | Size | Author |
---|---|---|---|
#10 | chosen-behat-2562805.patch | 2.58 KB | wingmanjd |
#3 | chosen-behat-2562805-3.patch | 2.58 KB | johnennew |
Comments
Comment #2
johnennew CreditAttribution: johnennew at Deeson commentedComment #3
johnennew CreditAttribution: johnennew at Deeson commentedHe's a rough starter in case this of interest.
This provides the following step definition:
When I the set the chosen element "My Field" to "Some value"
This sets the value of the field labeled "My Field" to "Some value" which should be one of the options.
There is work to do on this to provide multiple selections / deselections and to assert the current state of the select element.
Comment #4
clemens.tolboomWe are testing with behat and do use chosen. Can you please add some documentation with the patch on how to use this new context as I have no clue how to manage that. But it's awesome you try this as I was wondering how this would land in contrib.
No whiteline.
Comment #5
johnennew CreditAttribution: johnennew at Deeson commentedI don't think the patch is ready yet (I left it on active) but its great you think its useful.
There is work to do on this to provide multiple selections / deselections and to assert the current state of the select element. Since this is of interest I'll try and find some time for it.
I can add some information to the README or could add to doc comment in the file.
Effectively the steps to use a sub context with drupalextension are documented at the link below (you add an extra line to the behat.yml file):
http://behat-drupal-extension.readthedocs.org/en/latest/subcontexts.html
This then lets you use the step definitions in the sub context, in this case:
When I the set the chosen element "My Field" to "Some value"
Where "My Field" is a field identifier, usually a label and "Some value" is the option element to select.
John
Comment #6
clemens.tolboomI'm completely focused on a behat 3 og.behat.inc but your patch helped :-)
I'm not sure how to indicate the difference between Behat 2 & 3 regarding DrupalExtension but
This is Behat 2 syntax imho. For Behat 3 (we use)
@When I the set the chosen element :locator to :$value
Comment #7
johnennew CreditAttribution: johnennew at Deeson commentedog? Do you not use group yet?! Thats what all the cool kids are using :)
Thanks for the information on the regex syntax, I am using behat 3 and the patch works for it - but we should probably just support version 3 and do it properly.
Comment #8
wingmanjd CreditAttribution: wingmanjd commentedHow can I add more than one item to a multi-select chosen field?
Comment #9
wingmanjd CreditAttribution: wingmanjd commentedNevermind, just calling the line again allows me to select additional items.
Comment #10
wingmanjd CreditAttribution: wingmanjd commentedThere was a small typo in the step definition. I've removed the extraneous "the" from the step definition.