How to scroll by pixels in karate framework - user-interface

I want to scroll by pixels in karate framework.
I have tried this:
* def scrollDown =
"""
function () {
var results = window.scrollTo(0,500);
return results;
}
"""
* call scrollDown
And I got this error:
org.graalvm.polyglot.PloyglotException: ReferenceError: "window" is not defined

You can use script function to execute any JavaScript snippet.
function () {
var results = script('window.scrollTo(0,500)');
return results;
}
More information can be found at https://github.com/karatelabs/karate/tree/master/karate-core#script

Related

How does request.context in Parse Cloud Code work?

Back in Parse Server 3.0 update, there was an addition of request.context to pass data between BeforeSave and AfterSave as documented here:
https://docs.parseplatform.org/cloudcode/guide/#using-request-context
However, I'm having a bit of trouble understanding how and when Parse runs this code in the example.
const beforeSave = function beforeSave(request) {
const { object: role } = request;
// Get users that will be added to the users relation.
const usersOp = role.op('users');
if (usersOp && usersOp.relationsToAdd.length > 0) {
// add the users being added to the request context
request.context = { buyers: usersOp.relationsToAdd };
}
};
const afterSave = function afterSave(request) {
const { object: role, context } = request;
if (context && context.buyers) {
const purchasedItem = getItemFromRole(role);
const promises = context.buyers.map(emailBuyer.bind(null, purchasedItem));
item.increment('orderCount', context.buyers.length);
promises.push(item.save(null, { useMasterKey: true }));
Promise.all(promises).catch(request.log.error.bind(request.log));
}
};
in other examples, cloud code functions are run via Parse.Cloud.beforeSave or Parse.Cloud.afterSave. In this example above, the function beforeSave is assigned to a
const beforeSave.
Why was this done and is this supposed to be placed inside main.js top level or inside another function?

Does Jasmine have an after-advice spy?

When spying on a method, we can either callThrough (use original implementation) or callFake (use a custom implementation).
What I want is a behaviour similar to callThrough but inspect/modify its return value before returning it to the caller.
So I can do something like this:
spyOn(foo, "fetch").and.afterCall(function(result) {
expect(result).toBeDefined();
result.bar = "baz";
return result;
});
Right now the simplest way is doing something like this:
var original = foo.fetch;
foo.fetch = function() {
var result = original.apply(this, arguments);
expect(result).toBeDefined();
result.bar = "baz";
return result;
}
Which is somewhat annoying because now I have to manually restore the spy instead of having the framework automatically does it for me.
Does Jasmine have an after-advice spy?
Generally: no.
You could extend the SpyStrategy object with such a function though:
this.callThroughAndModify = function(resultModifier) {
var result;
plan = function() {
result = originalFn.apply(this, arguments);
return resultModifier(result);
};
return getSpy();
};
You've to clone the above SpyStrategy file and insert that method.
Usage:
var obj = {
fn: function(a) { return a * 2; }
};
spyOn(obj, "fn").and.callThroughAndModify(function(result) {
console.log("Original result: ", result);
return 1;
});
expect(obj.fn(2)).toBe(1);
Drawbacks:
You've to replace the whole SpyStrategy.js
You've to load that script before Jasmine initializes the original SpyStrategy at boot

d3.js return value of function always undefined

I am calling a function from my index.html file. The function is defined in a javascript file which i have referred to in the html. However the return value is always undefined. When i debug i could see the value in the return string.
Follwing is the code in index.html
<script type="text/javascript">
function readQueryStringparam(name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if (results == null)
return "";
else
return results[1];
}
function getDiDataUrlPrefix()
{
diDataUrlPrefix = diGlobal.instanceInfo.getDiDataUrlPrefix();
//alert(diDataUrlPrefix);
sbu = readQueryStringparam('sbu');
appid = readQueryStringparam('appid');
if (sbu.length > 0)
{
sbu = sbu.trim();
CreateChart(diDataUrlPrefix,sbu,0,appid);
}
else if (appid.length > 0)
{
sbu = GetSBUForApplication(appid);
CreateChart(diDataUrlPrefix,0,0,appid);
}
}
</script>
I get the value for the parameters supplied in the url as well as diDataUrlPrefix.
Following is the code in the javascript file:
function GetSBUForApplication(appid)
{
setTimeout(function() { }, 10000);
var string;
var file = diDataUrlPrefix + "/oss/csvs/Consolidated_RAG.csv";
d3.text(file, function(datasetText)
{
parsedCSVapp = d3.csv.parseRows(datasetText);
if (appid >0)
{
parsedCSVapp = parsedCSVapp.filter(function(row)
{
//alert(parsedCSVapp);
return row[0] == appid
})//parsed fileter ends here
returnstring = parsedCSVapp[0][4];
}
})
return returnstring;
}
However the value of sbu is always undefined.However i can see the values in parsedCSVapp. The csv file looks like this:
Application_Id,Application Name,Status,Name,Business Unit
200039,DEALING,RED,Marc Begun,Financial&Risk
200070,NGTX,RED,Marc Begun,Financial&Risk
200097,WORLD-CHECK,RED,Graham Fisher,Financial&Risk
200009,BOARDLINK,RED,Jennifer Simon,Financial&Risk
200088,THOMSON ONE,RED,Jonathan Weinberg,Financial&Risk
200037,DATASTREAM,RED,Ian Brocklehurst,Financial&Risk
200044,EIKON,RED,Olivier Martin,Financial&Risk
200011,COLLABORATION,RED,Frank Tarsillo,Financial&Risk
d3.text (and d3.csv, d3.json and similar) make asynchronous calls. That is, when you run the code, the call is made and execution resumes without waiting for the call to return.
The second argument to those functions is a function that gets executed when the call returns -- the callback.
This function will not be executed at the same time as you run d3.text, but later. You cannot determine at what time exactly it will be run. Any code that you want to call as a result of one of those calls needs to be run as part of the callback function, or called from there.

Node module imported via require has no methods

I'm having a problem with node modules that I cannot resolve. I have the following three files. I've included the basic methods of interest but have excluded the rest of the methods and the actual guts of the methods.
The problem that I'm struggling with is that when the publish_event method is called on the event_queue object from events.js node crashes with the following error:
FATAL TypeError: Object # has no method 'publish_event', stack:
TypeError: Object # has no method 'publish_event'
at Events.publish_event (/Users/mburbidg/stormcloud/ccapi/cloud_pipes/node_modules/f5/server/services/event/events.js:137:15)
I cannot figure this out, you can see that I can use methods of the EventQueue object from index.js, another module, in our system just fine. I've checked names other obvious things several times.
Any suggestions as to how to proceed?
File 1 - f5/server/notifications/sqs_event_queue.js
function EventQueue() {
this.queue_name = 'notification_queue';
this.queue_url = null;
this.sqs = null;
}
EventQueue.prototype.publish_event = function(event_data, registration_id, log, callback) {
...
}
EventQueue.prototype.start = function(callback) {
...
}
module.exports = new EventQueue();
File 2 - f5/server/index.js
var event_queue = require('f5/server/notifications/sqs_event_queue');
var start_notifications = function()
{
event_queue.start(on_start);
function on_start(error)
{
}
}
File 3 - f5/server/services/event/events.js
var event_queue = require('f5/server/notifications/sqs_event_queue');
function Events () {
}
Events.prototype.publish_event = function(event_data, registration_id, log, callback) {
event_queue.publish_event(event_data, registration_id, log, callback);
};
module.exports = new Events();

Nothing happens with my event listener on click in javascript

I have these functions :
createTreeItem: function (num, val)
{
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var i = document.createElementNS(XUL_NS, "treeitem");
var r = document.createElementNS(XUL_NS, "treerow");
var c1 = document.createElementNS(XUL_NS, 'treecell');
var c2 = document.createElementNS(XUL_NS, 'treecell');
var c3 = document.createElementNS(XUL_NS, 'treecell');
i.setAttribute("container", true);
i.setAttribute("open", true);
c1.setAttribute("label", num);
c2.setAttribute("label", val);
c3.setAttribute("value", false);
r.appendChild(c1);
r.appendChild(c2);
r.appendChild(c3);
i.appendChild(r);
i.addEventListener("click", test, false);
return i;
}
test: function ()
{
alert("zero");
}
func: function (liste)
{
try
{
root = document.getElementById("treeRoot");
var current;
for(o in liste)
{
current = createTreeItem(liste[o].id, liste[o].nom_scenario);
root.appendChild(current);
}
}
catch(e)
{
alert(e);
}
}
I am creating elements in a tree and I would like to add event listeners on each element created. The problem is that nothing happens.
In the code, Liste is the response of a json request. It contains all the elements I want to create in my xul file.
I'm not super familiar with this syntax, but my bet is that the test function isn't being 'hoisted' because of how it's being defined. try moving the 'test' function above the 'createTreeItem' function or just defining test like so:
function test() {
...
}
That way when it gets evaluated it will be 'hoisted' to the top so that when you try to add it as the action for the click event, it'll be defined. Not 100% sure this is correct but if I had to bet...

Resources