Don't wait for a page to fully load before navigating

46 views
Skip to first unread message

Ben Frey

unread,
Oct 10, 2019, 11:49:06 AM10/10/19
to Geb User Mailing List
I have a logon script that goes to the login page, enters the user's credentials, then once we hit the member home page, I want to navigate to a specific URL. This works fine, but Geb is waiting for all of the content on the home page to load before it navigates away, which is unnecessary. Is there a way to tell Geb "once you're at HomePage, immediately navigate to TargetPage"?

jc

unread,
Oct 10, 2019, 12:07:43 PM10/10/19
to Geb User Mailing List
This could be a couple things. Do you have atCheckWaiting set to true in GebConfig?  If so, it will wait for everything in your pages static at {} block.  The other thing could be the driver's page load strategy.  I know Chrome and Firefox drivers you can set different levels of page load strategy with capabilities.  For example, my firefox driver uses
capabilities.setCapability("pageLoadStrategy","eager")
 

pageLoadStrategy supports the following values :

  1. normal

    This stategy causes Selenium to wait for the full page loading (html content and subresources downloaded and parsed).

  2. eager

    This stategy causes Selenium to wait for the DOMContentLoaded event (html content downloaded and parsed only).

  3. none

    This strategy causes Selenium to return immediately after the initial page content is fully received

Be careful when you change this though as you can introduce a lot of timing errors.

Ben Frey

unread,
Oct 10, 2019, 12:16:29 PM10/10/19
to Geb User Mailing List
I don't have atCheckWaiting set at all, so it's whatever the default is (can't find what it is in the documentation). The only thing in the at block is a title check, and I see the title long before Geb decides to continue navigation. The pageLoadStrategy sounds promising, but is there a way to set it only for a given page?

jc

unread,
Oct 10, 2019, 12:39:57 PM10/10/19
to Geb User Mailing List

As for pageLoadStrategy this is set by the driver and not Geb, so I do not believe that is possible.  You could maybe try to play around with that page launching it's own instance of the driver with that capability but I'm not entirely sure about that.

Ben Frey

unread,
Oct 10, 2019, 12:48:36 PM10/10/19
to Geb User Mailing List
Well, setting atCheckWaiting=false for that page didn't help. Since it's just a "nice-to-have", I'll leave it be for now.

jc

unread,
Oct 10, 2019, 12:54:35 PM10/10/19
to Geb User Mailing List
The default for atCheckWaiting is false so that is why you didn't see a difference.  My guess is the pageLoadStrategy is going to be your only solution,

Ben Frey

unread,
Oct 10, 2019, 1:08:15 PM10/10/19
to Geb User Mailing List
Ok, I'll try that. Where do I put the driver.capabilities.setCapability("pageLoadStrategy", "none") line? I tried in both GebConfig.groovy, in the page's class definition, and in my login trait, but it doesn't seem to have an effect.

jc

unread,
Oct 10, 2019, 1:15:38 PM10/10/19
to Geb User Mailing List
You put it in GebConfig when creating the driver.  It's not driver.capabilities. it's just capabilities but you have to create a DesiredCapabilities object to use it.  DesiredCapabilities capabilities = new DesiredCapabilities().  You should be able to google this as it's not specific to Geb.

Trinidad Esparza

unread,
Oct 10, 2019, 6:58:51 PM10/10/19
to Geb User Mailing List

Trinidad Esparza

unread,
Oct 10, 2019, 7:00:11 PM10/10/19
to Geb User Mailing List
dont change your waiting capabilities for your browsers

Ben Frey

unread,
Oct 11, 2019, 8:49:25 AM10/11/19
to Geb User Mailing List
Those are all good options to know about, but those settings didn't address my issue.

Trinidad Esparza

unread,
Oct 11, 2019, 1:47:24 PM10/11/19
to geb-...@googlegroups.com
Do you have a Page Object for this page is it part of your project or separate script?

-- Trinidad Esparza "Opportunity for Wisdom, Wisdom for Culture" 616-890-0453
--
You received this message because you are subscribed to a topic in the Google Groups "Geb User Mailing List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/geb-user/KHAf373sQVI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to geb-user+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/a36b87f1-c42c-4f73-a1f4-82ea49d30034%40googlegroups.com.

Ben Frey

unread,
Oct 11, 2019, 3:41:52 PM10/11/19
to Geb User Mailing List
Yes, I have a Page Object for the page in question.
To unsubscribe from this group and all its topics, send an email to geb-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages