/** * @Then /^I should (not )?see a button with tooltip "(.*)"$/ */ public function iShouldSeeButtonWithTooltip($verb, $text) { $expected = $verb === 'not ' ? 0 : 1; return array(new When('I should see ' . $expected . ' "xpath=//a[contains(@title, ' . $this->escape(Xpath::quote($text)) . ') or contains(@data-original-title, ' . $this->escape(Xpath::quote($text)) . ')]"')); }
/** * @Then /^I fill "((?:[^"]|"")*)" with "((?:[^"]|"")*)"$/ */ public function iFillWith($field, $value) { $field = $this->unescape($field); $value = $this->unescape($value); $selector = $this->parseSelector($field); if (is_string($selector)) { $selector = By::xpath(strtr(self::LABEL_TO_INPUT_XPATH, array('{text}' => Xpath::quote($field)))); } $field = $this->tryRepeating(function () use($selector) { return $this->getElement($selector); }); if ($field->getTagName() == 'select') { $field->element(By::xpath('.//option[contains(., ' . Xpath::quote($value) . ')]'))->click(); return; } $type = $field->getAttribute('type'); if ($type === 'checkbox') { $value = $value === '1' || $value === 'on' || $value === 'true'; $selected = $field->isSelected(); if ($value !== $selected) { $field->click(); } return; } if ($type === 'radio') { $value = $value === '1' || $value === 'on' || $value === 'true'; $selected = $field->isSelected(); if ($selected && !$value) { throw new \RuntimeException(sprintf('Cannot uncheck a radio (a user in a web browser can\'t neither')); } $field->click(); return; } // text or textarea $field->clear(); $field->type($value); }