Skip to content
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

Closed
mbsryu opened this issue Dec 19, 2019 · 14 comments
Closed

Add exist() function to check for element until timeout - added in v6 #651

mbsryu opened this issue Dec 19, 2019 · 14 comments
Labels

Comments

@mbsryu
Copy link

mbsryu commented Dec 19, 2019

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:

  1. Are there specific instances where tagui does not wait by default for the result/response to the first click?
  2. Is the step "wait" appropriate when it seems that the next click is happening too fast? or does it override the default and shorten the wait time instead?
  3. What about the use of: if present('element') ? would this also result in the default waiting time being skipped?
@kensoh kensoh added the query label Dec 19, 2019
@kensoh
Copy link
Member

kensoh commented Dec 19, 2019

  1. TagUI will wait by default until the element appears before acting on it, until default timeout value of 10 seconds before error. The auto-wait happens before an element appears for the step, not after the step. Because you won't know how long after a step and click will the UI update itself to show the next thing you are looking at.

  2. The wait step has no impact on the auto-wait before error out, that one is controlled using timeout step. If an element is expected to appear but takes long, you can use the timeout step to set to a long time you think is acceptable, before failing the automation.

  3. I normally won't use above structure before the present() function will check if the element exists right now at this instance, and if it has not appear yet, it will be missed.

@kensoh
Copy link
Member

kensoh commented Dec 19, 2019

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.

@kensoh kensoh changed the title Waiting after click step Waiting after click step - some ideas depending on workflow scenario Dec 19, 2019
@siowyisheng
Copy link
Contributor

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 present(). I'll think about the API.

@kensoh
Copy link
Member

kensoh commented Dec 20, 2019

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!

@siowyisheng
Copy link
Contributor

siowyisheng commented Dec 20, 2019

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.

@kensoh
Copy link
Member

kensoh commented Dec 20, 2019

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 -

click submit with timeout 30 seconds

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 -

timeout 30 seconds
click submit
timeout 10 seconds

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.

@mbsryu
Copy link
Author

mbsryu commented Dec 20, 2019

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.

@mbsryu
Copy link
Author

mbsryu commented Dec 20, 2019

Also the "exist()" step is cool"

@siowyisheng siowyisheng added this to the TagUI v6.0.0 milestone Dec 27, 2019
@siowyisheng siowyisheng added feature and removed query labels Dec 27, 2019
@siowyisheng siowyisheng removed this from the TagUI v6.0.0 milestone Dec 27, 2019
@siowyisheng siowyisheng changed the title Waiting after click step - some ideas depending on workflow scenario Waiting after click step - in development Dec 27, 2019
@kensoh
Copy link
Member

kensoh commented Dec 27, 2019

@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.

@kensoh
Copy link
Member

kensoh commented Dec 28, 2019

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.

@kensoh kensoh changed the title Waiting after click step - in development Add exist() function to check for element until timeout - in development Dec 31, 2019
@kensoh kensoh self-assigned this Dec 31, 2019
@kensoh
Copy link
Member

kensoh commented Dec 31, 2019

As discussed @siowyisheng , scoping the change to adding exist() function for v6, and updating title.

@kensoh
Copy link
Member

kensoh commented Dec 31, 2019

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;}

@kensoh
Copy link
Member

kensoh commented Dec 31, 2019

raised PR to merge into dev, unassigning myself

@kensoh kensoh removed their assignment Dec 31, 2019
@kensoh kensoh added this to the TagUI v6.0.0 milestone Dec 31, 2019
siowyisheng added a commit that referenced this issue Jan 2, 2020
#651 - exist() function that waits until timeout
@siowyisheng
Copy link
Contributor

siowyisheng commented Jan 2, 2020

exist() function which waits until the timeout has been implemented in #675 for v6

@kensoh kensoh changed the title Add exist() function to check for element until timeout - in development Add exist() function to check for element until timeout - added in v6 Jan 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants