-
Notifications
You must be signed in to change notification settings - Fork 580
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
Add exist() function to check for element until timeout - added in v6 #651
Comments
|
A situation where your structure above is useful is when you want to handle scenarios differently depending if something appears or not. Then you can do something like if ... do this, else .. do that. And in that situation, present() is not so good. You can try copying below code and save it as tagui_global.js to put in the tagui\src folder. This function is similar to present(), except that it will auto-wait for the timeout duration until the element appears, before returning true or false. function exist(element_identifier) {
var exist_timeout = Date.now() + casper.options.waitTimeout;
while (Date.now() < exist_timeout) {
if (present(element_identifier))
return true;
else
sleep(100);
}
return false;
} Fyi @siowyisheng above function I wrote it for use in TagUI for Python project. But I didn't add it into TagUI because I'm not sure if it will be useful here. Copying for your review to see if this is something interesting that you'll want to add this in v6. |
Yea it seems useful and common. We should allow an argument for timeout with natural language, then that API would cover both this case and |
Ok great! For the timeout I'll prefer using timeout step to control the value for the whole automation sequence instead of putting as a parameter. The reason for this preference is if we add timeout as parameter for this, then why not add timeout as a parameter for all the remaining UI automation steps, so can easily go into rabbit hole. Rationale is bit like if you look at programming languages, the keywords usually try to cover very basic building blocks that users combine to build complex stuffs, but don't add additional layers that do what other keywords do. But in this case it may be different because TagUI is part domain specific language and part create to make it convenient for users - so you see things like save step which contradicts with the no overlap idea. Because save is actually can be done with read followed by dump step. So I'll defer the choice to you, since v6 is about moving ahead instead of being held back by 100% backward compatibility! |
I strongly think it should also have an optional argument. This is from my experience previously doing a full web test suite with the excellent Cypress library, because it was a feature I often used. But I agree that we have to pick and choose our rabbit holes and limits. |
Great, let's go for it! I can see the value of having very personalised timeout for different UI steps, and being presented in 1 line instead of having to type 3 lines base on current design. I've chewed over it, implementation is not that diff even for current architecture, there is a way to implement without changing all the steps and functions. For eg below -
In tagui_parse.php, after creating the .raw file which expands the submodules, code can be added there. To scan for the string ' with timeout '. And convert those lines to -
This would result in the .raw being parsed with the effect of having custom timeout without having to update all the step definitions and parsing there. Above is still rough, for eg, need to store default timeout somewhere to use and restore back, instead of assuming it is a 10 seconds currently. And selection criteria needs to be stricter to apply only to relevant TagUI steps, for eg to check the front of the string whether it is an appropriate step for this option. Otherwise if I define a variable string with that string inside, will trigger a match and mess up script. |
I found your response, and the subsequent discussions helpful in understanding how tagui behaves in these situations. I've rid my flow of most of "wait" steps, and the use of "if present()" steps to when I have a useful "else" steps to choose from. |
Also the "exist()" step is cool" |
@siowyisheng for this issue, shall we scope it just to include the exist() function in v6? If yes I can create a PR so that you can review and see the entry point for this new function. |
I will self-assign issues pending my action so it's easier to see what to work on, but probably remove my assignment after i'm done. |
As discussed @siowyisheng , scoping the change to adding exist() function for v6, and updating title. |
Adding below to tagui_header.js // present() function that waits until timeout before returning result
function exist(element_identifier) {var exist_timeout = Date.now() + casper.options.waitTimeout;
while (Date.now() < exist_timeout) {if (present(element_identifier)) return true; else sleep(100);}; return false;} |
raised PR to merge into dev, unassigning myself |
#651 - exist() function that waits until timeout
|
When automating some web page actions using multiple consecutive "click" steps on button-like elements, the flow appears to exit when it cannot find the button or the item to be clicked next.
As the appearance of the next item can be delayed and/or not appear at all, I've tried to compensate by using the following:
if present('changeJobStatus')
{
click changeJobStatus
wait .2
}
if present('submit')
{
click submit
wait .2
}
Questions:
The text was updated successfully, but these errors were encountered: