-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
patch Sahi synchron status calls to asynchron calls #83
Labels
Milestone
Comments
|
Starting point for @Radon-bla:
|
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.
2. sync/await
macht letztendlich das gleiche, da eine async function dann ein Promise zurückgibt.
3. 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 ***@***.***>:
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 <#83 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AFItoQozflhaRDM9wiRsp30raOQ4c5yXks5s0xXIgaJpZM4EScfK>.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
The text was updated successfully, but these errors were encountered: