Created
January 12, 2015 14:16
-
-
Save wouterj/e9385f76f2e5cc11d951 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // BEFORE | |
| // ... | |
| class FeatureContext | |
| { | |
| public function assertFieldHasErrorMessage($message, $locator) | |
| { | |
| // find fieldset by locator for field | |
| $field = $this->getSession()->getPage()->findField($locator); | |
| if (!$field) { | |
| // find fieldset by label (e.g. a radiobutton field) | |
| $field = $this->findLabel($locator); | |
| if (!$field) { | |
| throw new Exception\ElementNotFoundException($this->getSession(), 'field', null, $locator); | |
| } | |
| $field = $field->getParent(); | |
| } | |
| $fieldWrapper = $field->getParent(); | |
| $actual = $fieldWrapper->getText(); | |
| $regex = '/'.preg_quote($message, '/').'/ui'; | |
| if (!preg_match($regex, $actual)) { | |
| throw new Exception\ElementTextException(sprintf('Field "%s" did not have the error message "%s".', $locator, $message), $this->getSession(), $fieldWrapper); | |
| } | |
| } | |
| protected function findLabel($locator) | |
| { | |
| return $this->getSession()->getPage()->find( | |
| 'xpath', | |
| "//label[contains(text(), '".$locator."')]" | |
| ); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // AFTER | |
| // ... | |
| class FeatureContext | |
| { | |
| public function assertFieldHasErrorMessage($message, $locator) | |
| { | |
| // how can I implement the same search as above for the $locator fieldset? | |
| expect($this->currentPage->getElement($locator.' fieldset'))->toNotHaveErrorMessage($message); | |
| } | |
| } |
jakzal
commented
Jan 12, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment