Network, waits and idling
Carbonate automatically detects updates to your HTML/DOM and waits for them to finish. This guide explains what's happening under the hood.
Extractions
When testing pages that are rendered or altered dynamically - for example when using React, Vue, or even jQuery - it's important that tests wait to ensure that the element(s) they are interacting with are available before trying to interact with them.
During an extraction (an instruction that hasn't been run before), Carbonate doesn't know which element(s) to interact with. In this case, Carbonate waits for the app to idle before trying to perform any extractions.
When is the app considered idle?
The SDK uses two main metrics to determine if the app is idle...
DOM mutations
A DOM mutation is simply a change to your HTML's structure. For example, if you add a new element to the page, or change the text of an element, this will be considered a DOM mutation.
If no DOM mutations have been detected for 0.5 seconds, the SDK will consider the app to be idle.
Network requests
When a network request, such as an XHR or fetch request, is a request made by your app to the server - usually to fetch data or update a record in the database.
The SDK automatically waits for all requests to finish before it considers the app to be idle.
Whitelisting network requests
If you have a long running XHR request that is not related to the extraction you are performing, you can whitelist the request's URI before calling the load method:
self.carbonate_sdk.whitelistNetwork('/customers/poll')
# Whitelisting must happen before calling load()
self.carbonate_sdk.load('https://example.com');
You can use global wildcards (*
) to match a sequence of characters:
self.carbonate_sdk.whitelistNetwork('/customers/*/poll')
# Matches: /customers/123/poll
# Matches: /customers/123/456/poll
You can use limited wildcards (*?
) to match a sequence of characters up until a forward slash (/
):
self.carbonate_sdk.whitelistNetwork('/customers/*?/poll')
# Matches: /customers/123/poll
# Does not match: /customers/123/456/poll