Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeception, don't print a specific action to report

In codeception, I want check if an element exist in the page and do another test if the first element exist. I can do that simply :

// $I is a AcceptanceTester Object and extends \Codeception\Actor class
try{
    $I->see('.firstElement');
}catch(ElementNotFound $e){
    // do some actions
}
    // do some anothers actions

But If I do that, in the report file I can see the line "I see '.firstElement'". I don't want see this test in this report.

My question : How can I call a \Codeception\Actor method quietly ? I just want do a simple DOM element html check and not print this action into the generated report

like image 224
spacecodeur Avatar asked Nov 06 '22 19:11

spacecodeur


1 Answers

You can create a simple helper module to check elements existence. It can use WebDriver module or PhpBrowser module to elements finding. For example:

class ElementChecker extends \Codeception\Module
{
    public function checkExistence($locator)
    {
        $elements = $this->getModule('WebDriver')->_findElements($locator);
        return !empty($elements);
    }
},

After it, you should add this helper to your codeception configuration. For example:

actor: SomeTester
modules:
    enabled:
        # some modules
        - ElementChecker

And new methods will be included in the tester class. You can use them:

if ($I->checkExistence('.firstElement')) {
    // some code
}

Also, you can read more about helpers in the official documentation

like image 117
Maksym Fedorov Avatar answered Dec 05 '22 22:12

Maksym Fedorov