Danp2 / au3WebDriver

Web Driver UDF for AutoIt
MIT License
107 stars 21 forks source link

Add _WD_WaitScript function #431

Closed ye7iaserag closed 1 year ago

ye7iaserag commented 1 year ago

Pull request

Proposed changes

Add a new function that takes JavaScript code and waits until the code returns true

Checklist

Put an x in the boxes that apply. If you're unsure about any of them, don't hesitate to ask. We are here to help!
This is simply a reminder of what we are going to look for before merging your code.

Types of changes

Please check x the type of change your PR introduces:

What is the current behavior?

New function

What is the new behavior?

New function

Additional context

Add any other context about the problem here.

System under test

Please complete the following information.

Danp2 commented 1 year ago

@ye7iaserag Thanks for your submission. A few questions for you --

Danp2 commented 1 year ago

Another thought would be to modify your submission as follows --

IMO, these changes would make your function more dynamic / useful to the user.

ye7iaserag commented 1 year ago

Please let me know what you think of the above points.

Danp2 commented 1 year ago

Hi @ye7iaserag,

The current implementation only works with a True/False result from the Javascript, and "success" is only achieved when True is returned. I was suggesting that the function could be more powerful if it allowed other return values to indicate success. For example --

Let me know if this helps explain why I suggested adding $vWaitReturn.

Regards, Dan

ye7iaserag commented 1 year ago

But you can manipulate that in the JS expression, still don't get your point

an example of usage is:

_WD_WaitScriptTrue($sSession, 'return window.getComputedStyle(document.querySelector("div#div1")).getPropertyValue("opacity") === "0" || document.querySelector("div#div2").innerText === "Completed!"')

and in the same way you can achieve any required result by manipulating the expression an example would be changing the above code to be:

_WD_WaitScriptTrue($sSession, 'return window.getComputedStyle(document.querySelector("div#div1")).getPropertyValue("opacity") === "0.5"')

Let me know if we are still not on the same page

Danp2 commented 1 year ago

OIC. That makes sense now. Thanks for clarifying.

Danp2 commented 1 year ago

Validation: You are right maybe a simple StringRight call can be used here.

I think you meant StringLeft, correct?

I do not think _WD_ExecuteScriptEx would reflect what the function is actuallu doing, it's close in functionaly to _WD_WaitElement, so I followed the same convention.

Agreed. What about dropping the True from the function name? It sticks out like a sore thumb IMNSHO.

ye7iaserag commented 1 year ago

I agree on both points

ye7iaserag commented 1 year ago

I think I have to remove the check for the return string on the left of script. One use cases that I had going was something like

let name = document.querySelector(".success");if(!!name){return name.innerText.includes("' & $usernameValue & '")}else{return false;}

Now this fails It still can be written in the form:

return document.querySelector(".success") && document.querySelector(".success").innerText.includes("' & $usernameValue & '")

But is restrictive

Danp2 commented 1 year ago

@ye7iaserag It's fine if you want to remove that check.