4

I have a form which, when filled out and clicked, returns a list of zip codes to a hidden field. I want to assert that the list of fields has been filled. However, I'd like to not check the fields value against any specific list, allowing for changes in census or postal information in the future. How can I simply assert that a field is not empty with Codeception's WebDriver? I've attempted to use

$set_zips = $I->grabValueFrom('#zips');
$this->assertFalse(empty($set_zips));

and

$I->cantSeeInField('#zips', '')`

but haven't been able to get this to validate, even though the field is in fact filled.

apkostka
  • 405
  • 3
  • 13
  • The `$set_zips` thing was a typo, fixed now. As for `cantSeeInField()`, it's basically an alias for `dontSeeInField()`, documented [here](http://codeception.com/docs/04-AcceptanceTests#Conditional-Assertions). – apkostka Nov 10 '14 at 23:36
  • I did some digging and found out that `cantSeeInField()` uses `assertContains`, meaning that it uses the second argument as a needle and the field's value as a haystack. Therefore, a null value as the second argument of `cantSeeInField()` will always return true. – apkostka Nov 10 '14 at 23:38

1 Answers1

6

I was able to create a helper to accomplish this:

function dontSeeFieldIsEmpty($value)
{
    $this->assertFalse(empty($value));
}

I placed this in tests/_support/AcceptanceHelper.php and called it in my Cest:

$I->dontSeeFieldIsEmpty($I->grabValueFrom('#set_zips'));
apkostka
  • 405
  • 3
  • 13