在after()钩子守夜人中设置cookie

时间:2018-02-23 06:49:18

标签: nightwatch.js

我尝试在()钩子函数后的nightwatch中设置cookie,但显然它没有用。这个想法是我想将cookie的值设置为"失败"如果测试失败并且成功"如果测试通过。

export = {
  '@tags': [ 'heboh' ],

  after(browser) {
    browser
      .setCookie({ name: 'mycookie', value: 'success' })
      .getCookie('mycookie', function callback(result) {
        console.log(result); // print null
      })
      .end();
  },

  'create heboh'(browser) {
    browser
      .url('http://www.google.com')
      .waitForElementVisible('body', 1000)
      .assert.title('Facebook'); // intended to make it failed
  }
}

我指定了--verbose,这就是我得到的

FAILED:  1 assertions failed and 1 passed (5.446s)
INFO Request: POST /wd/hub/session/null/cookie
 - data:  {"cookie":{"name":"mycookie","value":"true"}}
 - headers:  {"Content-Type":"application/json; charset=utf-8","Content-Length":45}
INFO Response 404 POST /wd/hub/session/null/cookie (19ms) { sessionId: 'null',
  value:
   { error: 'invalid session id',
     message: 'No active session with ID null',
     stacktrace: '' },
  status: 6 }
LOG     → Completed command cookie (22 ms)
INFO Request: GET /wd/hub/session/null/cookie
 - data:
 - headers:  {"Accept":"application/json"}
INFO Response 404 GET /wd/hub/session/null/cookie (15ms) { sessionId: 'null',
  value:
   { error: 'invalid session id',
     message: 'No active session with ID null',
     stacktrace: '' },
  status: 6 }
null
LOG     → Completed command cookie (16 ms)
LOG     → Completed command end (0 ms)

看起来after()函数中没有会话。

0 个答案:

没有答案