jenkins execute protractor with robojs can't handle mouse - jenkins

I'm calling protractor from jenkins with pipeline
protractor conf.js --suite SetUpTPs
in the code I have call to get mouse location
browser.sleep(1000).then(() => {
var robot = require("robotjs");
robot.setMouseDelay(1000);
var mouse = robot.getMousePos();
var screenSize = robot.getScreenSize();
console.log("getMousePos " + mouse.x + " " + mouse.y);
robot.moveMouseSmooth(FromXCordinate, FromYCordinate);
robot.mouseClick("left");
mouse = robot.getMousePos();
console.log("getMousePos " + mouse.x + " " + mouse.y);
robot.mouseToggle('down');
robot.moveMouseSmooth(xStart, 235 + YCordinate);
robot.mouseToggle("up");
mouse = robot.getMousePos();
console.log("getMousePos " + mouse.x + " " + mouse.y);
});
when I look on the log on jenkins I got
getMousePos -1173274063 32758
how to fix the mouse coordinates ?

Related

print method in lua script/redis is not working

I am trying to execute the following script and getting the below error. Redis is running in docker
Exception in thread "main" org.redisson.client.RedisException: ERR
user_script:1: Script attempted to access nonexistent global variable
'print' script: 6f736423f082e141036b833d1f86b5a36a494611, on
#user_script:1..
I get the same error when I execute using redis CLI
127.0.0.1:6379> eval "print("Comparison is_made b/w minimum_value out of two is: ")" 0 (error) ERR user_script:1: Script attempted to
access nonexistent global variable 'print' script:
8598b7f0db450c711d3a9e73a296e331bd1ef945, on #user_script:1.
127.0.0.1:6379>
Java code. I am using Redison lib to connect to Redis and execute script.
String script = "local rate = redis.call('hget', KEYS[1], 'rate');"
+ "local interval = redis.call('hget', KEYS[1], 'interval');"
+ "local type = redis.call('hget', KEYS[1], 'type');"
+ "assert(rate ~= false and interval ~= false and type ~= false, 'RateLimiter is not initialized')"
+ "local valueName = KEYS[2];"
+ "local permitsName = KEYS[4];"
+ "if type == '1' then "
+ "valueName = KEYS[3];"
+ "permitsName = KEYS[5];"
+ "end;"
+"print(\"rate\"..rate) ;"
+"print(\"interval\"..interval) ;"
+"print(\"type\"..type); "
+ "assert(tonumber(rate) >= tonumber(ARGV[1]), 'Requested permits amount could not exceed defined rate'); "
+ "local currentValue = redis.call('get', valueName); "
+ "local res;"
+ "if currentValue ~= false then "
+ "local expiredValues = redis.call('zrangebyscore', permitsName, 0, tonumber(ARGV[2]) - interval); "
+ "local released = 0; "
+ "for i, v in ipairs(expiredValues) do "
+ "local random, permits = struct.unpack('Bc0I', v);"
+ "released = released + permits;"
+ "end; "
+ "if released > 0 then "
+ "redis.call('zremrangebyscore', permitsName, 0, tonumber(ARGV[2]) - interval); "
+ "if tonumber(currentValue) + released > tonumber(rate) then "
+ "currentValue = tonumber(rate) - redis.call('zcard', permitsName); "
+ "else "
+ "currentValue = tonumber(currentValue) + released; "
+ "end; "
+ "redis.call('set', valueName, currentValue);"
+ "end;"
+ "if tonumber(currentValue) < tonumber(ARGV[1]) then "
+ "local firstValue = redis.call('zrange', permitsName, 0, 0, 'withscores'); "
+ "res = 3 + interval - (tonumber(ARGV[2]) - tonumber(firstValue[2]));"
+ "else "
+ "redis.call('zadd', permitsName, ARGV[2], struct.pack('Bc0I', string.len(ARGV[3]), ARGV[3], ARGV[1])); "
+ "redis.call('decrby', valueName, ARGV[1]); "
+ "res = nil; "
+ "end; "
+ "else "
+ "redis.call('set', valueName, rate); "
+ "redis.call('zadd', permitsName, ARGV[2], struct.pack('Bc0I', string.len(ARGV[3]), ARGV[3], ARGV[1])); "
+ "redis.call('decrby', valueName, ARGV[1]); "
+ "res = nil; "
+ "end;"
+ "local ttl = redis.call('pttl', KEYS[1]); "
+ "if ttl > 0 then "
+ "redis.call('pexpire', valueName, ttl); "
+ "redis.call('pexpire', permitsName, ttl); "
+ "end; "
+ "return res;";
RedissonClient client = null;
try {
client = Redisson.create();
client.getRateLimiter("user1:endpoint1").setRate(
RateType.PER_CLIENT, 5, 1, RateIntervalUnit.SECONDS);
String sha1 = client.getScript().scriptLoad(script);
List<Object> keys =
Arrays.asList("user1:endpoint1", "{user1:endpoint1}:value",
"{user1:endpoint1}:value:febbb04d-6365-4cb8-b32b-8d90800cd4e6",
"{user1:endpoint1}:permits", "{user1:endpoint1}:permits:febbb04d-6365-4cb8-b32b-8d90800cd4e6");
byte[] random = new byte[8];
ThreadLocalRandom.current().nextBytes(random);
Object args[] = {1, System.currentTimeMillis(), random};
boolean res = client.getScript().evalSha(READ_WRITE, sha1, RScript.ReturnType.BOOLEAN, keys, 1,
System.currentTimeMillis(), random);
System.out.println(res);
}finally {
if(client != null && !client.isShutdown()){
client.shutdown();
}
}
checked the Lua print on the same line thread but io.write also is giving same error.
As in the comments wrote return() seems* the only way.
Example for redis-cli (set redis DB and use it in Lua)
(Collect Data and return as one string)
set LuaV 'local txt = "" for k, v in pairs(redis) do txt = txt .. tostring(k) .. " => " .. tostring(v) .. " | " end return(txt)'
Now the eval
eval "local f = redis.call('GET', KEYS[1]) return(loadstring(f))()" 1 LuaV
...shows whats in table: redis
(One long String no \n possible)
Exception: eval 'redis.log(2, _VERSION)' 0 gives out without ending the script but only on the server.
Than \n will work when you do...
set LuaV 'local txt = "" for k, v in pairs(redis) do txt = txt .. tostring(k) .. " => " .. tostring(v) .. "\n" end return(txt)'
...and the eval
eval 'local f = redis.call("GET", KEYS[1]) f = loadstring(f)() redis.log(2, f)' 1 LuaV

get dom element by attribute in ionic 4

I'm upgrading my Ionic 3 app to Ionic 4.
I'm working google maps and markers. I added few buttons in infoWindow and declared an attirbute data-id. Now I want to get these buttons using this attribute data-id
Here's the related code:
let content = '<b>' + locations[i].name + '</b><br/>' + locations[i].street + "<br/>";
content += "<button id='edit-customer-" + i + "' class='edit-customer button button-md button-default-secondary button-default-md' ion-button data-id='" + locations[i].id + "'>Editar</button>";
content += "<button id='order-customer-" + i + "' class='order-customer button button-md button-default-secondary button-default-md' ion-button data-id='" + locations[i].id + "'>Pedido</button>";
content += "<button id='event-customer-" + i + "' class='event-customer button button-md button-default-secondary button-default-md' ion-button data-id='" + locations[i].id + "'>Evento</button>";
infowindow.setContent(content);
google.maps.event.addListenerOnce(infowindow, 'domready', () => {
let infoWindow = infowindow;
document.getElementById('edit-customer-' + i).addEventListener('click', (event) => {
var targetElement = (<HTMLButtonElement>event.target || event.srcElement);
var id = targetElement.getAttribute("data-id"); //getAttribute shows syntax error 'Property "getAttribute" does not exist on type "EventTarget"'
infoWindow.close();
me.editCustomer(id);
});
});
var id = targetElement.getAttribute("data-id");
syntax error 'Property getAttribute does not exist on type EventTarget'
Am I doing something wrong?
Any alternate way to getAttribute?

Store environment variables within declared environment variable, Jenkins Pipeline 2.0

This code is giving me error in jenkins
groovy.lang.MissingPropertyException: No such property: Metrics for class: java.lang.String
def init_metrics(){
env.previousStageEnd = 0
env.stageDuration
env.stageTimes = [:]
}
init_metrics()
node{
stage('Metrics'){
println " - " + env.previousStageEnd + " - " + env.stageTimes + " - " + env.stageDuration + " - " + env.STAGE_NAME
env.stageTimes[env.STAGE_NAME] = currentBuild.duration - (env.previousStageEnd as int)
previousStageEnd = currentBuild.duration
}
}
the problem with this guy here env.stageTimes[env.STAGE_NAME] for some reasons I can't add environment stage_name in another environment declared by me. it works only if those variables are not environment but local.
solution to this would be to define environment = []
def init_metrics(){
environment = [
previousStageEnd = 0,
stageDuration = null,
stageTimes = [:]
]
}
init_metrics()
node{
stage('Metrics'){
println " - " + env.previousStageEnd + " - " + env.stageTimes + " - " + env.stageDuration + " - " + env.STAGE_NAME
env.stageTimes[env.STAGE_NAME] = currentBuild.duration - (env.previousStageEnd as int)
previousStageEnd = currentBuild.duration
}
}

ERR value is not an integer or out of range

I have this code in a lua script which I run from .net.
const string script = " if redis.call('EXISTS', '{0}') == 1 then" +
" local user = redis.call('get','{0}')" +
" local value = cjson.decode(user)" +
" value['UserPreferences'] = cjson.decode('{1}')" +
" value['Timestamp'] = cjson.decode('{2}')" +
" local val=cjson.encode(value)" +
" redis.call('set', '{0}', val)" +
" redis.call('EXPIRE', '{0}','{3}')" +
" end";
var redisScript = string.Format(script, "User_" + userId, JsonConvert.SerializeObject(userPreferences), JsonConvert.SerializeObject(DateTime.UtcNow), ConfigurationManager.AppSettings["RedisKeyExpiryTime"]);
await Cache.ScriptEvaluateAsync(redisScript);
This returns the error :
Error: ERR value is not an integer or out of range
please give some feedback to solve the issue.

Vaadin Desktop Notifications

Is there any support for html5 browser 'desktop notifications' in Vaadin? I've looked for this and can't find anything specific.
I've tried something like this with no luck.
JavaScript.getCurrent().execute(
"if (window.webkitNotifications) {" +
"if (window.webkitNotifications.checkPermission() == 0) { // 0 is PERMISSION_ALLOWED" +
" window.webkitNotifications.createNotification(" +
" 'icon.png', 'Notification Title', 'Notification content...');" +
" } else {\n" +
" window.webkitNotifications.requestPermission();" +
" } " +
"} else { " +
" console.log('no notifications')" +
"}");
Using vaadin 8
You tried with the old api, it hasn't been supported for many versions. The new api should work:
JavaScript.getCurrent().execute(
" if (!(\"Notification\" in window)) { " +
" alert(\"This browser does not support system notifications\"); " +
" } else if (Notification.permission === \"granted\") { " +
" new Notification(\"Hi there!\"); " +
" } else if (Notification.permission !== 'denied') { " +
" Notification.requestPermission(function (permission) { " +
" if (permission === \"granted\") { " +
" Notification(\"Hi there!\"); " +
" } " +
" }); " +
" } "
);
Can't say this is a good way to do it though.
There is a plugin for vaadin 7 https://vaadin.com/directory#!addon/webnotifications you can adopt it to 8. Or create a JavaScript component or at at least a JavaScript function that will make using it easier.

Resources