Properly using Wait for Response

Hello Guys my first post here,

Basically I have the following situation, I need to automate a website that has some buttons on click refresh the page and put new info on a table.
So, I need to do a Click and wait until the response of this action.

I know the “Wait for response” keyword, but I fell like I am not understanding it, basically can you guys explain to me the diference between this two codes:

Click ${button}
Wait for Response

And

${promise} =    Promise To    Wait For Response
Click    ${button}
Wait For    ${promise}

What is the most correct? (if there is one)

1 Like

There is a possibility that the click related request response happens before you attach the wait if wait is done after. So with the Promise To is more correct.

Got it, but when I only use like this, seems like the promise don’t take the right response, because the “Wait for” simply pass and don’t wait the response of the button.
Any tip? How to catch the right response for this case?

You need to restrict the requests with the url they are calling https://marketsquare.github.io/robotframework-browser/Browser.html#Wait%20For%20Response

I would check from developer console network tab in the browser what traffic there is and choose the correct package url.

2 Likes

I have something similar scenario and I couldn’t get the expected output and move to the next action. Will appreciate for help. Thanks

# This will continue to the next operation after ${promise} criteria is met 
Click    ${open_selected}
Wait For    ${promise}

`Click    ${new_version}
# Click ${new_version} will initiate to check the calculations_status
Click    ${open_selected}    # This will catch the status of isCalculating
### The response to wait
# endpoint: https://{url}/api/v1/gateway/costing_versions/100171845/calculations_status
# response: {"isCalculating":false} # isCalculating should set to false to continue on next operation or click button
${promise} =     Promise To    Wait For Response    async (response) => response.url().endsWith(calculations_status') && response.status() === 200 && (await response.text()).includes('false')

# This will continue to the next operation after ${promise} criteria is met 
Click    ${open_selected}
Wait For    ${promise}`