Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run custom code after Codeception suite has finished

I am aware of the _bootstrap.php file that's used to set up the testing enviroment, etc., but I'm looking for a way to run some code after the entire test suite has finished.

Note that I'm not looking for a way to run code after a single class, i.e. something like _after, but after all classes.

Is there a way to achieve this?

like image 962
Sacha Avatar asked May 14 '15 16:05

Sacha


People also ask

Does Codeception use selenium?

Codeception is very flexible framework that you can use to write your Selenium tests.

What is Cest Codeception?

Cest is a common test format for Codeception, it is “Test” with the first C letter in it. It is scenario-driven format so all tests written in it are executed step by step. Unless you need direct access to application code inside a test, Cest format is recommended.

What is Codeception selenium?

Codeception can be classified as a tool in the "Testing Frameworks" category, while Selenium is grouped under "Browser Testing". Selenium is an open source tool with 14.9K GitHub stars and 4.97K GitHub forks. Here's a link to Selenium's open source repository on GitHub.


2 Answers

Actually managed to solve this myself, here's how, if anyone is interested.

I created a new helper class inside _support.

<?php

class DataHelper extends \Codeception\Module
{
    public function _beforeSuite()
    {
        // Set up before test suite
    }

    public function _afterSuite()
    {
        // Tear down after test suite
    }
}

You can then enable this as a module in any suite configuration (the .yml files), like this:

modules:
    enabled:
        - DataHelper
like image 181
Sacha Avatar answered Oct 02 '22 06:10

Sacha


@Sacha's solution is specially useful if you want to share the same methods accross all suites.

If you're looking for a way to define the methods for a specific suite (or if you want a different method per suite), you can define those methods directly in the suite Helper class.

For instance, if you want to define a _afterSuite method for the Acceptance Suite, just go to support/AcceptanceHelper.php and define those methods there. Eg:

<?php
namespace Codeception\Module;

// here you can define custom actions
// all public methods declared in helper class will be available in $I

class AcceptanceHelper extends \Codeception\Module
{
    public function _afterSuite() {
        die('everything done');
    }
}
like image 36
Luís Cruz Avatar answered Oct 02 '22 08:10

Luís Cruz