Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use CodeCeption assertion in conditional (if) statement

Tags:

I'm totally new with CodeCeption.

I want to do an action/assertion depending on another assertion result, like this:

if ($I->see('message')){      $I->click('button_close');  } 

Is something like that possible? I tried, but doesn't work. Probably the assertion result doesn't apply to IF, but is there any alternative?

Thanks in advance!

IMPORTANT UPDATE:

Finally Codeception now has the function performOn!! http://codeception.com/docs/modules/WebDriver#performOn

like image 496
Borjovsky Avatar asked Oct 03 '14 17:10

Borjovsky


People also ask

Which Codeception method may be used to check that a file exists?

assertFileIsReadable. Asserts that a file exists and is readable.

What is Codeception PHP?

Codeception is a framework used for creating tests, including unit tests, functional tests, and acceptance tests. Despite the fact that it is based on PHP, the user needs only basic knowledge for starting work with the framework, thanks to the set of custom commands offered by Codeception.

What is acceptance testing in PHP?

Writing acceptance tests is like describing a tester's actions in PHP. They are quite readable and very easy to write. If you need to access the database, you can use the Db Module.


2 Answers

I had this same issue. Although it's not ideal, you can do this:

try {     $I->see('message');     // Continue to do this if it's present     // ... } catch (Exception $e) {     // Do this if it's not present.     // ... } 
like image 50
DAB Avatar answered Sep 21 '22 07:09

DAB


In tests/_support/AcceptanceHelper.php add additional method

function seePageHasElement($element) {     try {         $this->getModule('WebDriver')->_findElements($element);     } catch (\PHPUnit_Framework_AssertionFailedError $f) {         return false;     }     return true; } 

Then to test in your acceptance test use:

if ($I->seePageHasElement("input[name=address]")) {     $I->fillField("input[name=address]", "IM"); } 
like image 39
Matija Avatar answered Sep 21 '22 07:09

Matija