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

waitUntil not working as expected #594

Closed
hardikdangar opened this issue Dec 22, 2018 · 11 comments
Closed

waitUntil not working as expected #594

hardikdangar opened this issue Dec 22, 2018 · 11 comments

Comments

@hardikdangar
Copy link

hardikdangar commented Dec 22, 2018

Hello,

i am testing App via dusk. it has this button which checks validation and fires ajax and gives form if suceeses and error message if fails. To intercept ajax request i am adding variable AppdataLoaded = false and when ajax finishes it will be true using $browser->script. this works but i am having trouble checking AppdataLoaded variable via waitUntil, as per document i should be able to check if AppdataLoaded == true but it does not work. Here is the code,

        $browser->type('#search_value',$searchtext);

        $test = $browser->script('

            var AppdataLoaded = false;
            $( document ).ajaxComplete(function() {
                AppdataLoaded = true;
                $(".subheadingtext").text("loaded");
            });
        
        ');

        $browser->press('Continue');

        $browser->waitUntil('AppdataLoaded == true',10);

Facebook\WebDriver\Exception\TimeOutException: Waited 10 seconds for callback. I am not sure if i am understanding docs wrong or there is issue with waituntill. I tried $browser->waitUntil('AppdataLoaded',10); first but it also it did not work.

Can anyone point me what i am missing here. If its not right way to test then any other way to test this ?

@staudenmeir
Copy link
Contributor

Each script() call is a separate execution context, so AppdataLoaded is undefined when you try to access it in waitUntil().

Try this:

$browser->type('#search_value', $searchtext);

$browser->press('Continue');

$browser->waitUntil('!$.active');

@hardikdangar
Copy link
Author

Hey @staudenmeir ,

Thanks for the reply.

But i am actually confused what is $.active?

@staudenmeir
Copy link
Contributor

https://stackoverflow.com/a/25520719/4848587

@hardikdangar
Copy link
Author

Wow. This is one of those Aha moment. Never heard of $.active. Really awesome solution :) 👍

I was wondering do you know anything where i can actually intercept ajax response and evalute what to do.

@staudenmeir
Copy link
Contributor

Do you want to intercept the AJAX response in the test?

@hardikdangar
Copy link
Author

The actual code fires $.get() request and based on response does diffrent things based on error or success response. I want to get that response so i don't have to work with html as responses vary so much in the old legacy app i am working with.

@staudenmeir
Copy link
Contributor

I'm not sure this is possible and even if it is, it's not really a good approach.

Browser tests are meant to be high-level and should only test user interaction. This is also the reason why you don't have access to the HTTP status code.

@hardikdangar
Copy link
Author

hardikdangar commented Dec 24, 2018

the thing is this legacy app we are testing results error in span like,
<span style="color:red;">Not Found</span>
I am not sure how can i get that element. as by default it is present like,
<span style="color:red;"></span>
and when error happens it adds "Not found". I want to test this case using dusk. for success i am able to find the div with id but for error how do i check element as it does not have id or class.

I can use assertsee but how do i check like in if condition that is bit confusing. i.e. i wish i could test it like,
if($browser->assertsee('Not Found') but this will generate error when sucess response will be there.

@driesvints
Copy link
Member

Like @staudenmeir said I don't think this is really possible with Dusk. Can you first please try one of the following support channels? If after that you still feel that this should be added, feel free to report back.

@nbyloff
Copy link

nbyloff commented Jan 3, 2019

So that works for jQuery AJAX calls, what about axios & vue? Check out my axios interceptors in this SO ticket, but it isn't working. It works similar to $.active, but I still have to use pause instead.

@boogiefromzk
Copy link

boogiefromzk commented Oct 16, 2023

After this fix waitFor and others stopped waiting and just check for the condition.
On 7.11.1 it works alright.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants