You are here

public function FeatureContext::clickRadioButton in Open Social 8

Same name and namespace in other branches
  1. 8.2 tests/behat/features/bootstrap/FeatureContext.php \FeatureContext::clickRadioButton()

@When I click radio button :label with the id :id @When I click radio button :label

1 call to FeatureContext::clickRadioButton()
FeatureContext::iSelectPostVisibility in tests/behat/features/bootstrap/FeatureContext.php
@When I select post visibility :visibility

File

tests/behat/features/bootstrap/FeatureContext.php, line 305

Class

FeatureContext
Defines application features from the specific context.

Code

public function clickRadioButton($label = '', $id = '') {
  $session = $this
    ->getSession();
  $session
    ->executeScript("var inputs = document.getElementsByTagName('input');\n        for(var i = 0; i < inputs.length; i++) {\n        inputs[i].style.opacity = 1;\n        inputs[i].style.left = 0;\n        inputs[i].style.visibility = 'visible';\n        inputs[i].style.position = 'relative';\n        }\n        ");
  $element = $session
    ->getPage();
  $radiobutton = $id ? $element
    ->findById($id) : $element
    ->find('named', array(
    'radio',
    $this
      ->getSession()
      ->getSelectorsHandler()
      ->xpathLiteral($label),
  ));
  if ($radiobutton === NULL) {
    throw new \Exception(sprintf('The radio button with "%s" was not found on the page %s', $id ? $id : $label, $this
      ->getSession()
      ->getCurrentUrl()));
  }
  $value = $radiobutton
    ->getAttribute('value');
  $labelonpage = $radiobutton
    ->getParent()
    ->getText();
  if ($label !== '' && $label != $labelonpage) {
    throw new \Exception(sprintf("Button with id '%s' has label '%s' instead of '%s' on the page %s", $id, $labelonpage, $label, $this
      ->getSession()
      ->getCurrentUrl()));
  }
  $radiobutton
    ->selectOption($value, FALSE);
}