Open arnaugm opened 10 years ago
Selecting a radio button in a radio group is done through selectOption
in Mink, so the step I select "foo" from "my field"
works for radio groups too
The radio buttons are often on their own which means there is no radio group. How do you do it in this case?
Well, this would mean that you can not unselect it. Is it really what you expect
And technically, you can still use this step (just select the option corresponding to this radio button in the radio group where it is alone)
I'm not sure to get it, how would you select one of the two options given this code?
<ul class="paymethod">
<li>
<input type="radio" id="method_0" name="method" value="paypal" checked="checked">
<label for="method_0">PayPal</label>
</li>
<li>
<input type="radio" id="method_1" name="method" value="trans">
<label for="method_1">Bank transfer</label>
</li>
</ul>
I select "Bank transfer" from "???"
@arnaugm this is a single radio group with 2 buttons in it here, given that they have the same name. So it is not what you described above
Ok I understood you were refering to radio buttons inside a fieldset. But still in this case I've tried with:
I select "Bank transfer" from "method"
I select "trans" from "method"
I select "method_1" from "method"
an non of them work, at least with the Selenium2 driver.
@arnaugm field set have nothing to do here. The HTML spec defines a radio group as being all radio buttons having the same name in a given form (and you can check only one of the buttons of a radio group. This is the difference with checkboxes).
I select "trans" from "method"
should work (we have tests in the Mink testsuite ensuring that drivers can handle this case, and Selenium2Driver passes them). What is the error you get ?
There is no error but the radio button doesn't change, which makes the test fail later on. I tested it with Sahi and it does work with it.
"name": "behat/mink-sahi-driver",
"version": "v1.1.0",
"name": "behat/mink-selenium2-driver",
"version": "v1.1.1",
This is not the latest version version of Selenium2Driver. v1.1.1 had a bug with radio buttons indeed. This has been fixed in 1.2.0 so please use it.
I was using the v1.1.1 because I'm unable to have Selenium2Driver 1.2.0 together with SahiDriver 1.1.0, one asks for mink 1.5 and to other 1.6.
behat/mink-selenium2-driver v1.2.0 requires behat/mink ~1.6@dev -> satisfiable by behat/mink[v1.6.0, v1.6.1].
behat/mink-sahi-driver v1.1.0 requires behat/mink ~1.5.0 -> no matching package found.
@arnaugm why are you using them both together ? SahiDriver is very slow from my experience (and from Travis build times) and it suffers from several issues: https://travis-ci.org/minkphp/MinkSahiDriver/jobs/49665767#L140 (which is why it has not received its 1.2 release yet btw)
I have some legacy tests that for some reason work with Sahi and not with Selenium2, probably because Sahi is less strict in some aspects (buttons covered by a layer and things like this). I noticed the difference in speed a while ago and I'm in the process of migrating everything, but I haven't had time yet, so in the meantime I need to keep both.
I was about to recommend using 1.2.*@dev
for MinkSahiDriver, but we actually require Mink 1.7 (still in dev) now there. It is a pain that SahiDriver 1.1 was using the wrong constraint for the semver operator...
Well, I'll try to workaround it. In any case, the problem I see with the solution
I select "trans" from "method"
is that is not very "business people" friendly, because it needs to specify values only visible in the source code, which is not the idea in BDD is it? Maybe a solution using only the radio label would be better, what do you think?
@arnaugm I have a few ideas to provide a better step in the MinkContext indeed.
However, "business people" are unlikely to speak the language of HTML anyway, so the Mink API is better used inside your own steps rather than in scenarios themselves.
Subscribing because also interested in a more simple yet precise way of selecting radio buttons. I'm coming from Drupal where radio buttons are output like this (with some semantically meaningless divs removed):
<fieldset data-drupal-selector="edit-field-category" id="edit-field-category--wrapper" class="fieldgroup form-composite required js-form-item form-item js-form-wrapper form-wrapper" required="required" aria-required="true">
<legend><span class="fieldset-legend js-form-required form-required">Category</span></legend>
<div id="edit-field-category" class="form-radios">
<input data-drupal-selector="edit-field-category-4" id="edit-field-category-4" name="field_category" value="4" checked="checked" class="form-radio" type="radio">
<label for="edit-field-category-4" class="option">Design</label>
<input data-drupal-selector="edit-field-category-19" id="edit-field-category-19" name="field_category" value="19" class="form-radio" type="radio">
<label for="edit-field-category-19" class="option">Advocacy</label>
<input data-drupal-selector="edit-field-category-25" id="edit-field-category-25" name="field_category" value="25" class="form-radio" type="radio">
<label for="edit-field-category-25" class="option">Research</label>
<input data-drupal-selector="edit-field-category-31" id="edit-field-category-31" name="field_category" value="31" class="form-radio" type="radio">
<label for="edit-field-category-31" class="option">Training</label>
</div>
</fieldset>
Maybe i should be looking at improvements to DrupalExtension but thinking of an upstream fix first.
Looking at this... telling Drupal to output radio buttons correctly is also a possibility.
Also relevant: http://stackoverflow.com/questions/18979890/check-radio-button-with-behat
(Edited to add the fieldset and legend, which is really the point of what i'd like to do, e.g., say "Select radio button 'Design' from 'Category'")
A step like this I think would be helpful:
/**
* @When /^I check the "([^"]*)" radio button$/
*/
public function iCheckTheRadioButton($labelText)
{
$page = $this->getSession()->getPage();
$radioButton = $page->find('named', ['radio', $labelText]);
if ($radioButton) {
$select = $radioButton->getAttribute('name');
$option = $radioButton->getAttribute('value');
$page->selectFieldOption($select, $option);
return;
}
throw new \Exception("Radio button with label {$labelText} not found");
}
Is there any good reason why a basic step like selecting a radio button is not implemented? If not I would be happy to create a PR with a proposal.