lundi 7 décembre 2020

Behat - Organize behat.yml file (separate authenticated contexts from others)

I am testing my PHP REST API. Some methods require the user to be authenticated, some do not. How can I separate my differents contexts in behat.yml to separate my two needs? In addition, for the moment for each method where the user needs to be authenticated I use the following type of feature:

    Feature: Get things
        @login
        Scenario: I want to get a list of things
            When I request a list of things from "/myendpoint"
            Then The result should include a thing with id "myID"

where @login is a BeforeScenario method. Is this a good way to go?

Finally, I would like to store my base url somewhere so that it is accessible by all my contexts. My behat.yml looks like this for the moment:

    default:
      suites:
        default:
          paths:
            features: 'features'
            bootstrap: 'features/bootstrap'
          contexts:
            - MyFirstContext:
                - 'http://localhost:8080'
            - MySecondContext:
                - 'http://localhost:8080'
            - MyThirdContext:
                - 'http://localhost:8080'

I access http://localhost:8080 in each context thanks to the context constructor:

    public function __construct($baseUrl)
    {
        $this->base_url = $baseUrl;
    }

I want to store http://localhost:8080 so that I don't have to rewrite it for each new context in my behat.yml. And if it is possible to store it in behat.yml, how can I access it in my context.php?

Aucun commentaire:

Enregistrer un commentaire