N
N
nepster-web2015-09-21 01:58:06
Codeception
nepster-web, 2015-09-21 01:58:06

How to get access_token before running tests?

I am learning to write tests. I'm trying to test the REST api.
Before the tests, you need to get an access_token and pass it to the amBearerAuthenticated method.
I created my helper and wrote the following:

public function _before()
    {
        $I = $this->getModule('REST');
        // get token
        $I->amBearerAuthenticated($token);
    }

The problem is that this method is executed before every test. That is, if we have 100 tests, we request 100 tokens.
There is also a _beforeSuite method, but if you place the same code in it, there will be an error:
PHP Fatal error: Call to a member function request() on null in phar:///usr/local/bin/codecept/src/Codeception/Module/REST.php

That is, not everything has been initialized there yet. Actually, how to call the method for obtaining a token only 1 time before all tests?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question