Search code examples
phpwebdriverphantomjsacceptance-testingcodeception

How can I assert that a field is not empty with Codeception/PhantomJS?


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.


Solution

  • 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'));