From 5e58444e07312e0febead0b6d42d2182cf6c1f75 Mon Sep 17 00:00:00 2001 From: Sriram Venkatesh Date: Wed, 7 May 2014 16:07:21 +1200 Subject: [PATCH] Adding support to fill in field in a specfic region --- .../BehatExtension/Context/BasicContext.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/SilverStripe/BehatExtension/Context/BasicContext.php b/src/SilverStripe/BehatExtension/Context/BasicContext.php index 7f78c98..fe23c19 100644 --- a/src/SilverStripe/BehatExtension/Context/BasicContext.php +++ b/src/SilverStripe/BehatExtension/Context/BasicContext.php @@ -584,6 +584,27 @@ JS; $linkObj->click(); } + /** + * Fills in a field in a specfic region similar to (@see iFollowInTheRegion or @see iSeeTextInRegion) + * + * Example: Given I fill in "Hello" with "World" + * + * @Given /^I fill in "(?P[^"]*)" with "(?P[^"]*)" in the "(?P[^"]*)" region$/ + */ + public function iFillinTheRegion($field, $value, $region){ + $context = $this->getMainContext(); + $regionObj = $context->getRegionObj($region); + assertNotNull($regionObj, "Region Object is null"); + + $fieldObj = $regionObj->findField($field); + if (empty($fieldObj)) { + throw new \Exception(sprintf('The field "%s" was not found in the region "%s" on the page %s', $field, $region, $this->getSession()->getCurrentUrl())); + } + + $regionObj->fillField($field, $value); + } + + /** * Asserts text in a specific region (an element identified by a CSS selector, a "data-title" attribute, * or a named region mapped to a CSS selector via Behat configuration).