Skip to content

Commit

Permalink
ENHANCEMENT Allow negation of some steps, and qualifying by "in the f…
Browse files Browse the repository at this point in the history
…orm…"
  • Loading branch information
chillu committed Jan 22, 2012
1 parent e233883 commit d4a39e9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
42 changes: 35 additions & 7 deletions features/step_definitions/basic/BasicSteps.php
Expand Up @@ -39,32 +39,60 @@ public function stepIWaitNSeconds($seconds) {


/**
* Then /^I can see the content "([^"]*)"$/
* Then /^I (can|cannot) see the content "([^"]*)"$/
**/
public function stepICanSeeTheContentParameter($text) {
$this->assertTrue($this->natural->textIsVisible($text));
public function stepICanSeeTheContentParameter($maybe, $text) {
$assert = ($maybe == 'can') ? 'assertTrue' : 'assertFalse';
$this->$assert($this->natural->textIsVisible($text));
}

/**
* Then /^I can see the headline "([^"]*)"$/
*/
public function stepICanSeeTheHeadlineParameter($content) {
$matched = false;
foreach(range(1,6) as $level) {
$headers = $this->natural->wd()->elements('css selector', 'h' . $level);
foreach($headers as $header) {
if(trim($header->text()) == $content) $matched = true;
}
}

if(!$matched) throw new LogicException("Couldn't find '$content' in preview panel");
}

/**
* Then /^I can see a "([^"]*)" field in the "([^"]*)" form$/
**/
public function stepICanSeeAParameterFieldInTheParameterForm($field, $form) {
$this->stepICanSeeAParameterField($field, $form);
}

/**
* Then /^I can see a "([^"]*)" field$/
**/
public function stepICanSeeAParameterField($field) {
public function stepICanSeeAParameterField($field, $form = null) {
try {
$this->natural->field($field);
$this->natural->field($field, $form);
$success = true;
} catch(LogicException $e) {
$success = false;
}
$this->assertTrue($success);
}

/**
* When /^I put "([^"]*)" into the "([^"]*)" field in the "([^"]*)" form$/
**/
public function stepIPutParameterIntoTheParameterFieldInTheParameterForm($value, $field, $form) {
$this->stepIPutParameterIntoTheParameterField($value, $field, $form);
}

/**
* When /^I put "([^"]*)" into the "([^"]*)" field$/
**/
public function stepIPutParameterIntoTheParameterField($value, $field) {
$this->natural->field($field)->setTo($value);
public function stepIPutParameterIntoTheParameterField($value, $field, $form = null) {
$this->natural->field($field, $form)->setTo($value);
}

/**
Expand Down
7 changes: 4 additions & 3 deletions features/support/NaturalWebDriver.php
Expand Up @@ -47,10 +47,11 @@ function visit($url) {
/**
* Return a field by its label
*/
function field($label) {
function field($label, $form = null) {
$rootEl = ($form) ? $this->wd()->element('css selector', '#Form_' . $form . 'Form') : $this->el;
try {
$labelEl = null;
$potentialLabels = $this->el->elements("xpath", "//label[text()='$label']");
$potentialLabels = $rootEl->elements("xpath", "//label[text()='$label']");
foreach($potentialLabels as $potentialLabel) {
if($potentialLabel->displayed()) {
$labelEl = $potentialLabel;
Expand All @@ -64,7 +65,7 @@ function field($label) {

$id = $labelEl->attribute('for');
try {
$el = $this->el->element("id", $id);
$el = $rootEl->element("id", $id);
} catch(NoSuchElementWebDriverError $e) { $el = null; }

if(!$el) throw new LogicException("Can't find a field for the '$label' (expected ID: $id)");
Expand Down

0 comments on commit d4a39e9

Please sign in to comment.