vlucas / frisby

Frisby is a REST API testing framework built on Jest that makes testing API endpoints easy, fast, and fun.

Home Page:http://frisbyjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to save cookies in global setup

amrsa1 opened this issue · comments

How to save the cookies in global setup so it can authenticate all other test in it block

`describe ('Backend Validation', function () {

frisby.globalSetup({
    request: {
        url: 'https://example.com/EAI/Login',
        method: 'POST',
        body:{
            redirect: 'https://example.com/',
            reprompt: 'https://iotidentity.example.com/login?redirect=https://example.com/',
            username: 'username',
            password: 'password'
        },
        headers: {
            origin: 'https://iotidentity.example.com',
        }
    }
});

it('1- Verify backend and API will retrun 200', function () {
    return frisby
        .get('https://example.com/')
        .expect('status',200)
        .inspectBody()
});

it('2- Verify all user comapny service can be fetched', function () {
    return frisby
        .get('https://example.com/mcapi/users/current')
        .expect('status', 200)
        .inspectBody()
})

});
`

console error for test number 2

FAILURE Status: 403
JSON: {
    "message": "Missing Authentication Token"
}

Use beforeAll to run a frisby login that returns a cookie, then call frisby.globalSetup after that with the value of it.

Thanks for reply
can you provide sample how to return the cookies in before all and call it frisby global setup