I working a test that requieres a token in order to run. This token is required to be passed to the compare function. But i'm not understanding on how to wait for the token in order to procede to execute the test. I'm new JS so apologies. Here is the code of my test:
describe('Offline Comparison', function () {
token = getToken('appName');
console.log('Token' + token);
files.forEach(function (file) {
it('Comparando file ' + file, function (done) {
this.timeout(15000);
const id = file.split('./screenshots/')[1];
compare(file, id, token, function (response) {
console.log(JSON.stringify(response, null, 4));
expect(response.TestPassed).to.be.true;
done();
});
});
});
});
function getToken(applicationName, callback) {
request.post('http://localhost:8081/token',
{
json: {
application_name: applicationName
}
},
(error, response, body) => {
console.log('Token: ' + body.Token);
return callback(body.Token)
});
}