Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variables available in multiple scenarios #39

Open
kevin-verschaeve opened this issue Feb 7, 2019 · 2 comments
Open

Variables available in multiple scenarios #39

kevin-verschaeve opened this issue Feb 7, 2019 · 2 comments

Comments

@kevin-verschaeve
Copy link
Contributor

kevin-verschaeve commented Feb 7, 2019

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 ?

@iamluc
Copy link
Contributor

iamluc commented Feb 11, 2019

I liked the idea.

The issue is that currently, scenarios can be run concurently.
So we have to find a way to mark the scenario as a requirement.

@scyzoryck
Copy link
Contributor

Most of the testing framework has some hooks to stick before / after scenarios. What do you think about something similar that are not executed concurently? For example:

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

beforeEach
     visit url('/refersh-token?token=' ~ token)
        header 'accept: "application/json"'
        method 'POST'
        expect status_code() == 200
        set token json('token')

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

WDYT?

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

No branches or pull requests

3 participants