UPDATE: After some troubleshooting, I believe I have identified the issue causing it not to work. It seems that I am unable to pass arguments along when calling flow.execute(getSpendermeldung). Does anyone have a better solution than wrapping the ApiCall in another function and using "global" variables? My intention is to have this function in a separate file and use require when necessary.
Original Message: In my Protractor tests, I am trying to retrieve test data from a database. I achieved this using the nodejs http module, which has been successful so far. However, while testing with this data, I encountered synchronization issues. I managed to circumvent them with Jasmine's callback solution. Nevertheless, I find this approach too rigid and would prefer to utilize promises and the control flow. Unfortunately, whenever I run my code, I encounter an Error: fn is not a function buried deep within webdriver/lib/promise.js
Below is the function in question:
function getSpendermeldung(kennnummer) {
var http = require('http');
var defer = protractor.promise.defer();
var options = {
host: 'localhost',
path: '/blabla/' + kennnummer
};
var callback = function (response) {
var body = '';
response.on('data',
function (chunk) {
body += chunk;
});
response.on('end',
function () {
spendermeldung = JSON.parse(body);
defer.fulfill('json parsed');
});
};
http.get(options, callback).end();
return defer.promise;
}
I invoke it like this:
var flow = browser.controlFlow();
flow.execute(getSpendermeldung('D0000001'));
If anyone has any insights on what might be missing or improving, please let me know. Thank you.
PS: I would like to provide the stacktrace, but I am having trouble formatting it correctly.