Skip to content

Variables available in multiple scenarios #39

Open
@kevin-verschaeve

Description

Hi,

Let me explain :)

I'm profiling an api, and I need to call my login page which return a token I need to pass to all my next calls.

Currently, to do this, I call /login, then set token json('token') and use that token in my header of the next requests in the same scenario. The issue is that I need that token for all my scenarios, so I have to login at the begining of each one.

That would be great to call only once the /login page and set my token as a variable available in all my next scenarios.

May be some code would be more explicit :

currenlty:

group login
    visit url('/login')
        header 'accept: "application/json"'
        method 'POST'
        body
        """
        {
            "username": "user",
            "password": "pass"
        }
        """
        expect status_code() == 200
        set token json('token')

scenario
    name "Feature 1"
    include login
    visit url('/feature-1')
        header 'content-type: "application/json"'
        header 'X-TOKEN: ' ~ token
        expect status_code() == 200

scenario
    name "Feature 2"
    include login
    visit url('/feature-2')
        header 'content-type: "application/json"'
        header 'X-TOKEN: ' ~ token
        expect status_code() == 200

include login is repeated and increase the time of the whole blackfire profile.

What would be great:

scenario
     name "Login"
     visit url('/login')
        header 'accept: "application/json"'
        method 'POST'
        body
        """
        {
            "username": "user",
            "password": "pass"
        }
        """
        expect status_code() == 200
        setGlobal token json('token')

scenario
    name "Feature 1"
    visit url('/feature-1')
        header 'content-type: "application/json"'
        header 'X-TOKEN: ' ~ token
        expect status_code() == 200

scenario
    name "Feature 2"
    visit url('/feature-2')
        header 'content-type: "application/json"'
        header 'X-TOKEN: ' ~ token
        expect status_code() == 200

What do you think ?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions