General developer forum

How do I get a full Behat match instead of a partial

 
Picture of Mike Churchward
How do I get a full Behat match instead of a partial
Core developersParticularly helpful MoodlersPlugin developersPlugins guardiansTesters

I am trying to write a Behat test that uses the Cohort editing page. The particular page has three edit icons per table row: "Edit cohort name", "Edit cohort ID" and "Edit". I have a test line that looks like this:

And I click on "Edit" "icon" in the "Cohort One" "table_row"

The problem is that this statement matches the "Edit cohort name" icon first, and triggers that icon instead. I need to trigger the one named just "Edit".

Any ideas?

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: How do I get a full Behat match instead of a partial
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

Well, sometimes, if you have difficulty getting Behat to do what you want, it is a sign that you have an accessibility problem. If all you can see (or hear) are three choices: "Edit cohort name", "Edit cohort ID" and "Edit", because you cannot see the shape of the icon, do you have any idea what 'Edit' is going to do? Perhaps the best option is to use a better alt text on the icon, or add some class="accesshide" text to disambiguate.

Incidentally, I assume that at the moment, if you have multiple cohorts on the same page, the links to edit each cohort will be identical. That is also not great accessibility, although you found a way around that in Behat.

The other part of the answer is that you can teach Behat to be cleverer. For buttons, at least, it does prefer an exact match (since Behat 3.x which we have been using for ages). See MDL-44584 for some history. Perhaps a similar change should be implemented in the 'icon' selector? Also, not that "link" can often be used instead of "icon", and that probably gets the 'prefer exact match' logic right.

 
Average of ratings: -
Picture of Mike Churchward
Re: How do I get a full Behat match instead of a partial
Core developersParticularly helpful MoodlersPlugin developersPlugins guardiansTesters

Hi Tim -

I agree with the accessibility issue. Unfortunately the issue is in core code. I could figure out what needs to be changed and propose it, but it won't help in the short run.

I'll check that issue to see if it reveals any solutions. In this case, both "link" and "icon" seem to be interchangeable, and have the same problems.

Mike

 
Average of ratings: -
Picture of Mike Churchward
Re: How do I get a full Behat match instead of a partial
Core developersParticularly helpful MoodlersPlugin developersPlugins guardiansTesters

I was able to get it to work using an 'xpath_element' solution.

    And I click on "Edit" "link" in the "//table[@id='cohorts']//tr[1]//td[6]" "xpath_element"

Not ideal, but allows me to get Behat tests working.

mike

 
Average of ratings: -