1

I am running angular tests using protractor and trying to set cookies but doesn't seem to work. How can I add waiting until cookie is set?

  public async visit() {
    await navigateTo();
    return this.whenReady();
  }

export async function navigateTo() {
   browser.get('http://' + 'localhost' + ':4200');
   browser.manage().addCookie({ name: 'auth', value: 'true', path: '/', domain: 'localhost' });
   await browser.manage().getCookie('auth');
}

it always return null and cookie is not set.

user1298426
  • 3,467
  • 15
  • 50
  • 96

1 Answers1

0

Add await right before both browser.get() and browser.manage().getCookie() because they return a Promise.

export const navigateTo = async () => {
   await browser.get('http://localhost:4200');
   await browser.manage().addCookie({ name: 'auth', value: 'true', path: '/', domain: 'localhost' });
   await browser.manage().getCookie('auth');
};
Francesco
  • 405
  • 3
  • 15