nightmarecodeceptjs

CodeceptJS and Nightmare - set cookie before suite in helper class


I decided use framework CodeceptJS and library Nightmare.

Mine issue is set cookie before run all test suite I read the documentation and understanding so for that to solve mine issue me need use helper classes. Maybe I'm wrong but still. Perhaps you need to use a different approach if so let me know.

It mine helper

'use strict';

class SetCookie extends Helper {

  constructor(config){
    super(config)
  }

  _beforeSuite() {
    this.client = this.helpers['Nightmare'].browser;

    this.getCookies().then((cookies) => {
      console.log(cookies);
    })
  }

getCookies(){
  return this.client.cookies.get()
  }
}

module.exports = SetCookie;

Problem Cookies return after finished test suite


Solution

  • I solved this problem: Mine Helper

        async setSplitCookies() {
            const client = this.helpers['Nightmare'];
    
            const cookie = {
              name: 'rc_web_spl', 
              value: 'on',
              url: 'http://www.nic.ru'
            }
            return client.setCookie(cookie);
    }
    

    Mine test:

    Before((I) => {
        I.setSplitCookies();
      });