I have a crude solution for this problem for now, before Codeception guys give you reliable method for this.
Just create another Actor above all your existing actors (test cases) like this:
class MyCest
{
function _before(AcceptanceTester $I)
{
$I->amOnPage('/mypage.php');
}
public function _after(AcceptanceTester $I)
{
}
function beforeAllTests(AcceptanceTester $I,\Page\MyPage $myPage,\Helper\myHelper $helper){
//Do what you have to do here - runs only once before all below tests
//Do something with above arguments
}
public function myFirstTest(AcceptanceTester $I){
$I->see('Hello World');
}
function afterAllTests(){
//For something after all tests
}
}
You can put the function beforeAllTests as public but not protected nor should start with "_", for it to run before all your tests.
Another bunch of functions which will only run once before all tests begin which should be instantiated in /tests/_support/Helper/Acceptance.php for acceptance and so on. In this you can call the function :
// HOOK: used after configuration is loaded
public function _initialize()
{
}
// HOOK: before each suite
public function _beforeSuite($settings = array())
{
}
For more functions , go to : https://codeception.com/docs/06-ModulesAndHelpers#Hooks