sakuli icon indicating copy to clipboard operation
sakuli copied to clipboard

patch Sahi synchron status calls to asynchron calls

Open toschneck opened this issue 10 years ago • 4 comments

In sahi v4 it was necessary to implement a delay for syncron status calls from the browser side javascript part, see property sahi.proxy.requestDelayOnSikuliInput.delayTime. Due to the upgrade to sahi5, see #7 , it may be possible, that this feature isn't needed any more.

TODO:

  • check if browser calls are still syncron
  • check problem with a example testcase

toschneck avatar May 07 '15 13:05 toschneck

  • Try to overwrite the sendstatus function in Sahis javascript to avoid the synchron calls
  • Check that the Sahi dashboard also use this

toschneck avatar Jun 08 '16 08:06 toschneck

Starting point for @Radon-bla: file src/common/src/main/resources/org/sakuli/common/libs/js/internal/inject.js

var origSendToServer = Sahi.prototype.sendToServer;
Sahi.prototype.sendToServer = function (url, isAsync) {
    if (isAsync == undefined){
        isAsync = true;
        debugger;
    }
    return origSendToServer(url, isAsync);
}

toschneck avatar Nov 09 '17 15:11 toschneck

Hallo Tobi,

zu den Libs in VisualStudioCode:

Im Projektverzeichnis eine Datei jsconfig.json mit folgendem Inhalt anlegen:

{ "compilerOptions": { "target": "ES6" }, "exclude": [ "node_modules", "**/node_modules/*" ], "include": [ "/lib" ] }

Die ersten zwei Einträge sind default und wurden mir generiert. Mit Include konnte ich dann den lib-Pfad angeben und er hat die darin liegenden .js-Files gleich mit indiziert. Ich habe das getestet mit einer simplen lib, in der ich eine Funktion definiert habe und mit dem Aufruf dieser Funktion aus einem src-file.

In Lib: const Bla = function () {}; Bla.prototype.foo = function () {};

In src: const b = new Bla(); b.foo();

Klasse und Methode erkannt.

Für Libs in IntelliJ gibts auch ne Lösung:

https://www.jetbrains.com/help/idea/configuring-javascript-libraries.html https://www.jetbrains.com/help/idea/configuring-javascript-libraries.html in Kurz: Klicke auf Hector (das Männchen ganz unten rechts) und gehe auf Libraries in Scope. Der Rest ist selbsterklärend. Danach steht die Lib auch in der Projekt-Config, allerdings als „Release“ und nicht als „Debug“. Keine Ahnung, wie man das anders als über Hector hinbekommt.

Für den synchronen Call wird es etwas schwieriger. Es gibt seit ES6 verschiedene Lösungen, die aber die Funktion immer anders verwenden lassen. Eine Funktion, die sich wie ES5 sync anfühlt aus einem asynchronen Aufruf zu zaubern, hab ich nicht geschafft. Das Thema ist viel gefragt, aber nie zufriedenstellend beantwortet.

  1. Promises Scheint mir der gangbarste Weg, wird aber etliches an Code-Änderungen nach sich ziehen.

function httpGet(url, async) { return new Promise((resolve, reject) => { const xhr = new XMLHttpRequest(); xhr.open('GET', url, async); xhr.onload = () => resolve(xhr.responseText); xhr.onerror = () => reject(xhr.statusText); xhr.send(); }); }

httpGet('https://www.google.de', true) .then(response => console.log(response.length));

Die Aufrufer müssten dann den Folgecode jeweils mit .then anfügen.

  1. sync/await

macht letztendlich das gleiche, da eine async function dann ein Promise zurückgibt.

  1. yield/generator

ist ähnlich, nur dass dann das element mit .next statt .then aufgerufen wird.

Bleibt also letztendlich nur der Umbau mit Promise - zumindest für die eine störende Funktion. Ich hoffe, das hilft Dir weiter.

Viele Grüße Norbert

PS: Ich hätte Dir eigentlich schon früher geantwortet, aber mich hat eine Ohrenentzündung aus der Bahn geworfen. Ich bin die Woche auch noch krank zu Hause.

Am 09.11.2017 um 16:10 schrieb Tobias Schneck [email protected]:

Starting point for @Radon-bla https://github.com/radon-bla: file src/common/src/main/resources/org/sakuli/common/libs/js/internal/inject.js

var origSendToServer = Sahi.prototype.sendToServer; Sahi.prototype.sendToServer = function (url, isAsync) { if (isAsync == undefined){ isAsync = true; debugger; } return origSendToServer(url, isAsync); } — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ConSol/sakuli/issues/83#issuecomment-343183638, or mute the thread https://github.com/notifications/unsubscribe-auth/AFItoQozflhaRDM9wiRsp30raOQ4c5yXks5s0xXIgaJpZM4EScfK.

nferc avatar Nov 15 '17 11:11 nferc

Current workaround: http://consol.github.io/sakuli/latest/index.html#_missing_keystrokes_on_type_or_failing_paste

toschneck avatar Jun 12 '18 19:06 toschneck