I'm using webdriverIO, node. When I execute the following code in file1, Nothing gets printed to console. Although, I do see that the Post does add the data to the server. I noticed, that if I remove the module.exports
and do a
try{returnAddPost("1","production","1.0")}
and call the file directly with node file.js
this works. But as soon as I add the module.exports the id is not displayed. I'm trying to get the ID of the item I added. That's all I want
In file1.js
I have
function addPost(clonedCycleId,env,version) {
return new Promise((resolve, reject) => {
var options = { url: url,body: jsonDataObjt,json: true
};
request.post(options, function (error, response) {
console.dir("id of response"+response.body["id"]);
if(error){reject(error)}
resolve(response.body["id"]);
})
})
}
function returnAddPost(id,env,version) {
return new Promise((resolve, reject) => {
addPost(id,env,version)
.then( function(response) {
console.log("id of cycle that was added:"+response);
resolve(response);
//here I will continue to add additional code that requires the id that I just added
})
.catch((error) => reject(error));
} )
}
module.exports = {returnAddPost:returnAddPost};
In wdioConf.js
file I have
var cycle = require('./file1');
after: function (result, capabilities, specs) {
cycle.returnAddPost(id,env,version)
.then(function(response){
console.log("get ID "+response); //this is not displayed in console
}).catch((error) => console.log(error));
},