Skip to content

Is there a way to share cookies between multiple agents? #278

@rajchandra3

Description

@rajchandra3

Hey, I am trying to write tests that involve making requests to hosted servers (via URL ) say(via agent1 and agent2) & local server(agent3). I want to fetch cookies from a server in agent1 and share that with agent2 and agent3. Is there a way to do it?

Sharing some code snippets for clarity in NodeJs.

import chai from 'chai';
import chaiHttp from 'chai-http';
import app from 'app.js';

let agent1 = chai.request.agent('https://server1.com/');
let agent2 = chai.request.agent('https://server2.com/');
let agent3 = chai.request.agent(app);

const getCookie = async () => {
	return await agent1
		.post('/signin')
		.send({
			email: 'abc@abc.abc',
			password: '***',
		});
};

describe('Do Checks', () => {
    it('random', async (done) => {
		const response = await getCookie();
		await agent2
			.post('/update/username')
			.send({
				"username": "rajchandra3"
			})
			.then(res=>{
			         //code is never executed
                                  //do something with res
			})
			.catch(e=>{
				throw e; //throws error because cookies are missing 
			});
		done();
    });
})

Can I share cookies between these agents?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions