Geb wait for element to disappear
When I perform an action on my page, a spinner is displayed which disappears once the action is completed. I want to wait for the spinner to disappear so as to execute the assert statements.
I read the documentation which tells me how to wait for an element to appear but does not give info on how to wait for the element to disappear
I don't know how to implement this in Cucumber, Geb, Groovy project.
groovy cucumber geb
add a comment |
When I perform an action on my page, a spinner is displayed which disappears once the action is completed. I want to wait for the spinner to disappear so as to execute the assert statements.
I read the documentation which tells me how to wait for an element to appear but does not give info on how to wait for the element to disappear
I don't know how to implement this in Cucumber, Geb, Groovy project.
groovy cucumber geb
add a comment |
When I perform an action on my page, a spinner is displayed which disappears once the action is completed. I want to wait for the spinner to disappear so as to execute the assert statements.
I read the documentation which tells me how to wait for an element to appear but does not give info on how to wait for the element to disappear
I don't know how to implement this in Cucumber, Geb, Groovy project.
groovy cucumber geb
When I perform an action on my page, a spinner is displayed which disappears once the action is completed. I want to wait for the spinner to disappear so as to execute the assert statements.
I read the documentation which tells me how to wait for an element to appear but does not give info on how to wait for the element to disappear
I don't know how to implement this in Cucumber, Geb, Groovy project.
groovy cucumber geb
groovy cucumber geb
edited Nov 15 '18 at 3:50
M.Ricciuti
3,5502419
3,5502419
asked Nov 14 '18 at 20:10
Varun JainVarun Jain
63
63
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I'll edit/explain this in a bit, when i have more time:
In your page object:
static content = {
loadingSpinner(wait:3, required:false) { $("mat-spinner") }
//this wait:3 is redundant (i think) if we also give the waitFor() a timeout
//required:false allows our wait !displayed to pass even if the element isnt there
}
def "Handle the loader"() {
try {
waitFor(2) { loadingSpinner.isDisplayed() }
} catch (WaitTimeoutException wte) {
//do nothing, if spinner doesnt load then thats ok
//most likely the spinner has come and gone before we finished page load
//if this is not the case, up our waitFor timeout
return true;
}
waitFor(10) { !loadingSpinner.isDisplayed() }
}
add a comment |
As described in the documentation, the waitFor
block uses Groovy Truth to know when it waited long enough. When you put a Navigator in it and the element is currently not present, it will wait for it to appear or until the maximum waiting time it elapsed.
So if want to wait for an element to disappear, you can simply put it in a waitFor
like this:
// go to the page
waitFor(2) { $(".loadingspinner").displayed }
waitFor(10) { !$(".loadingspinner").displayed }
// do your assertions
In case the loading spinner already disappeared, waitFor
will return immediately. In case it never disappears, it will throw a WaitTimeoutException
after 10 seconds, which will make your test fail.
does this address a 1second gap between page load and spinner display?
– Doug Clark
Jan 2 at 18:51
Now it does. You might want to play a bit with the timeouts...
– Michael
Jan 2 at 18:55
but now what if it never displays? im looking to improve on my solution
– Doug Clark
Jan 2 at 18:59
In that case the firstwaitFor
will throw aWaitTimeoutException
. You are in trouble if it disappeared within the 2 seconds timeout. It might be worth considering finding something that appears.
– Michael
Jan 2 at 19:02
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308043%2fgeb-wait-for-element-to-disappear%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'll edit/explain this in a bit, when i have more time:
In your page object:
static content = {
loadingSpinner(wait:3, required:false) { $("mat-spinner") }
//this wait:3 is redundant (i think) if we also give the waitFor() a timeout
//required:false allows our wait !displayed to pass even if the element isnt there
}
def "Handle the loader"() {
try {
waitFor(2) { loadingSpinner.isDisplayed() }
} catch (WaitTimeoutException wte) {
//do nothing, if spinner doesnt load then thats ok
//most likely the spinner has come and gone before we finished page load
//if this is not the case, up our waitFor timeout
return true;
}
waitFor(10) { !loadingSpinner.isDisplayed() }
}
add a comment |
I'll edit/explain this in a bit, when i have more time:
In your page object:
static content = {
loadingSpinner(wait:3, required:false) { $("mat-spinner") }
//this wait:3 is redundant (i think) if we also give the waitFor() a timeout
//required:false allows our wait !displayed to pass even if the element isnt there
}
def "Handle the loader"() {
try {
waitFor(2) { loadingSpinner.isDisplayed() }
} catch (WaitTimeoutException wte) {
//do nothing, if spinner doesnt load then thats ok
//most likely the spinner has come and gone before we finished page load
//if this is not the case, up our waitFor timeout
return true;
}
waitFor(10) { !loadingSpinner.isDisplayed() }
}
add a comment |
I'll edit/explain this in a bit, when i have more time:
In your page object:
static content = {
loadingSpinner(wait:3, required:false) { $("mat-spinner") }
//this wait:3 is redundant (i think) if we also give the waitFor() a timeout
//required:false allows our wait !displayed to pass even if the element isnt there
}
def "Handle the loader"() {
try {
waitFor(2) { loadingSpinner.isDisplayed() }
} catch (WaitTimeoutException wte) {
//do nothing, if spinner doesnt load then thats ok
//most likely the spinner has come and gone before we finished page load
//if this is not the case, up our waitFor timeout
return true;
}
waitFor(10) { !loadingSpinner.isDisplayed() }
}
I'll edit/explain this in a bit, when i have more time:
In your page object:
static content = {
loadingSpinner(wait:3, required:false) { $("mat-spinner") }
//this wait:3 is redundant (i think) if we also give the waitFor() a timeout
//required:false allows our wait !displayed to pass even if the element isnt there
}
def "Handle the loader"() {
try {
waitFor(2) { loadingSpinner.isDisplayed() }
} catch (WaitTimeoutException wte) {
//do nothing, if spinner doesnt load then thats ok
//most likely the spinner has come and gone before we finished page load
//if this is not the case, up our waitFor timeout
return true;
}
waitFor(10) { !loadingSpinner.isDisplayed() }
}
edited Jan 2 at 18:58
answered Nov 16 '18 at 16:54
Doug ClarkDoug Clark
335212
335212
add a comment |
add a comment |
As described in the documentation, the waitFor
block uses Groovy Truth to know when it waited long enough. When you put a Navigator in it and the element is currently not present, it will wait for it to appear or until the maximum waiting time it elapsed.
So if want to wait for an element to disappear, you can simply put it in a waitFor
like this:
// go to the page
waitFor(2) { $(".loadingspinner").displayed }
waitFor(10) { !$(".loadingspinner").displayed }
// do your assertions
In case the loading spinner already disappeared, waitFor
will return immediately. In case it never disappears, it will throw a WaitTimeoutException
after 10 seconds, which will make your test fail.
does this address a 1second gap between page load and spinner display?
– Doug Clark
Jan 2 at 18:51
Now it does. You might want to play a bit with the timeouts...
– Michael
Jan 2 at 18:55
but now what if it never displays? im looking to improve on my solution
– Doug Clark
Jan 2 at 18:59
In that case the firstwaitFor
will throw aWaitTimeoutException
. You are in trouble if it disappeared within the 2 seconds timeout. It might be worth considering finding something that appears.
– Michael
Jan 2 at 19:02
add a comment |
As described in the documentation, the waitFor
block uses Groovy Truth to know when it waited long enough. When you put a Navigator in it and the element is currently not present, it will wait for it to appear or until the maximum waiting time it elapsed.
So if want to wait for an element to disappear, you can simply put it in a waitFor
like this:
// go to the page
waitFor(2) { $(".loadingspinner").displayed }
waitFor(10) { !$(".loadingspinner").displayed }
// do your assertions
In case the loading spinner already disappeared, waitFor
will return immediately. In case it never disappears, it will throw a WaitTimeoutException
after 10 seconds, which will make your test fail.
does this address a 1second gap between page load and spinner display?
– Doug Clark
Jan 2 at 18:51
Now it does. You might want to play a bit with the timeouts...
– Michael
Jan 2 at 18:55
but now what if it never displays? im looking to improve on my solution
– Doug Clark
Jan 2 at 18:59
In that case the firstwaitFor
will throw aWaitTimeoutException
. You are in trouble if it disappeared within the 2 seconds timeout. It might be worth considering finding something that appears.
– Michael
Jan 2 at 19:02
add a comment |
As described in the documentation, the waitFor
block uses Groovy Truth to know when it waited long enough. When you put a Navigator in it and the element is currently not present, it will wait for it to appear or until the maximum waiting time it elapsed.
So if want to wait for an element to disappear, you can simply put it in a waitFor
like this:
// go to the page
waitFor(2) { $(".loadingspinner").displayed }
waitFor(10) { !$(".loadingspinner").displayed }
// do your assertions
In case the loading spinner already disappeared, waitFor
will return immediately. In case it never disappears, it will throw a WaitTimeoutException
after 10 seconds, which will make your test fail.
As described in the documentation, the waitFor
block uses Groovy Truth to know when it waited long enough. When you put a Navigator in it and the element is currently not present, it will wait for it to appear or until the maximum waiting time it elapsed.
So if want to wait for an element to disappear, you can simply put it in a waitFor
like this:
// go to the page
waitFor(2) { $(".loadingspinner").displayed }
waitFor(10) { !$(".loadingspinner").displayed }
// do your assertions
In case the loading spinner already disappeared, waitFor
will return immediately. In case it never disappears, it will throw a WaitTimeoutException
after 10 seconds, which will make your test fail.
edited Jan 2 at 18:54
answered Jan 1 at 10:39
MichaelMichael
1,2261912
1,2261912
does this address a 1second gap between page load and spinner display?
– Doug Clark
Jan 2 at 18:51
Now it does. You might want to play a bit with the timeouts...
– Michael
Jan 2 at 18:55
but now what if it never displays? im looking to improve on my solution
– Doug Clark
Jan 2 at 18:59
In that case the firstwaitFor
will throw aWaitTimeoutException
. You are in trouble if it disappeared within the 2 seconds timeout. It might be worth considering finding something that appears.
– Michael
Jan 2 at 19:02
add a comment |
does this address a 1second gap between page load and spinner display?
– Doug Clark
Jan 2 at 18:51
Now it does. You might want to play a bit with the timeouts...
– Michael
Jan 2 at 18:55
but now what if it never displays? im looking to improve on my solution
– Doug Clark
Jan 2 at 18:59
In that case the firstwaitFor
will throw aWaitTimeoutException
. You are in trouble if it disappeared within the 2 seconds timeout. It might be worth considering finding something that appears.
– Michael
Jan 2 at 19:02
does this address a 1second gap between page load and spinner display?
– Doug Clark
Jan 2 at 18:51
does this address a 1second gap between page load and spinner display?
– Doug Clark
Jan 2 at 18:51
Now it does. You might want to play a bit with the timeouts...
– Michael
Jan 2 at 18:55
Now it does. You might want to play a bit with the timeouts...
– Michael
Jan 2 at 18:55
but now what if it never displays? im looking to improve on my solution
– Doug Clark
Jan 2 at 18:59
but now what if it never displays? im looking to improve on my solution
– Doug Clark
Jan 2 at 18:59
In that case the first
waitFor
will throw a WaitTimeoutException
. You are in trouble if it disappeared within the 2 seconds timeout. It might be worth considering finding something that appears.– Michael
Jan 2 at 19:02
In that case the first
waitFor
will throw a WaitTimeoutException
. You are in trouble if it disappeared within the 2 seconds timeout. It might be worth considering finding something that appears.– Michael
Jan 2 at 19:02
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308043%2fgeb-wait-for-element-to-disappear%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown