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

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

Open
rajchandra3 opened this issue Dec 1, 2020 · 0 comments
Open

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

rajchandra3 opened this issue Dec 1, 2020 · 0 comments

Comments

@rajchandra3
Copy link

rajchandra3 commented Dec 1, 2020

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: '[email protected]',
			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?

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

No branches or pull requests

1 participant