Karate: window is not defined

Created on 15 Nov 2018  路  3Comments  路  Source: intuit/karate

Using: karate-netty

Calling script bellow results in error: javascript function call failed: ReferenceError: "window" is not defined.

function () { 
    var token = karate.callSingle('file:src/util/get_jwt.feature').response.get('id_token')
    var base64Url = token.split('.')[1];
    var base64 = base64Url.replace('-', '+').replace('_', '/');
    return JSON.parse(window.atob(base64))['a'][0]['id'];
}

Any ideas on how to get around this?

invalid

All 3 comments

Karate's JS is not the one you are expecting and JSON.parse is never recommended and window certainly won't work.

Can you look at this example and the docs, that should get you on your way:

1) https://github.com/intuit/karate#http-basic-authentication-example
2) https://stackoverflow.com/a/52541026/143475

sorry - just realized you need a JWT example. this is new so you may have missed this in the existing docs: https://github.com/intuit/karate/blob/cukexit/karate-demo/src/test/java/demo/jwt/jwt.feature

Thanks, looks perfect! :)

Was this page helpful?
0 / 5 - 0 ratings