How to iterate through all parameters of a <select> field in behit / mink

I am testing a product search form. Products can be searched by various parameters (for example, status, material, light, etc.). When I want to search by status, I do the following:

Scenario Outline: search by status
  When I select "<status>" from "search_form_status"
  And I press "Search"
  And I wait for 3 seconds                        // implemented
  And I follow random link from test result table // implemented
  Then I should see "<status>" in the "div#status" element
Examples:
  |status  |
  |enabled |
  |disabled|

      

And everything is all right. But if I wanted to test the same search for, say, productMaterial, I'm stuck as product materials that can be changed at any time (we may need new materials, edit material names, or delete old unused ones). Add to that the fact that materials will differ in the test environment and on the production site. I know I can do something like:

Given I select product material

      

And let's implement the foreach loop step as follows:

$matList = $this->getSession()->getPage()->findAll('css', "select option");
    foreach($matList as $material){
        // DO SOMETHING
    }
}

      

But how do I create all the other steps like in the example status

? I am guessing that I would like to use the variable $material

in the next steps in the search.feature file for the steps that follow this custom step. But how can I do this? How would I go through the whole list of options and do a bunch of steps on each iteration?

+3


source to share


1 answer


You will need to write PHP code that runs the individual steps you want inside your method, which contains the code to select all of the options.

For example:



$handler = $this->getSession()->getSelectorsHandler();

$optionElements = $this->getSession()->getPage()->findAll('named', array('option', $handler->selectorToXpath('css', 'select ));

foreach ($optionElements as $optionElement) {
    $this->getSession()->getPage()->selectFieldOption('portal', $optionElement->getValue());
    $this->pressButton("show");
    $this->assertPageContainsText(" - Report Report");
}

      

+3


source







All Articles