0

How can I check if the site is up without actually opening the browser using Robot ?

This is what I've got so far:

*** Keywords ***
Load staging server if available
Create Session  localhost  ${STAGING_SERVER}
${response}=  get request  localhost  /
Run Keyword If  ${response.status_code} == 200
...  Open Browser  ${STAGING_SERVER}  ${BROWSER}
...  ELSE
...  Open Browser  ${DEVELOPMENT_SERVER}  ${BROWSER}

I'm using Robot's RequestsLibrary. The problem with my code is that it won't even manage to get status code of the response if the site is down because it will fail to establish http connection.

Mark
  • 1,385
  • 3
  • 16
  • 29
  • I think maybe duplicated to this question https://stackoverflow.com/questions/52930775/robotframework-how-to-retrieve-the-answer-of-a-request – Sidara KEO Aug 21 '19 at 03:05
  • @SidaraKEO Not a duplicate. The topic you attached deals with completely different problem. It was a problem concerning Robot Framework but that's where similarity ends. – Mark Aug 21 '19 at 07:21

1 Answers1

1

Probably you should use keyword Run Keyword And Ignore Error and based on the status check for status code or open browser using ${DEVELOPMENT_SERVER} url. Something like that:

Create Session  localhost  ${STAGING_SERVER}
${status}  ${response}  Run Keyword And Ignore Error  get request  localhost  /
Run Keyword And Return If  '${status}' == 'FAIL'  Open Browser  ${DEVELOPMENT_SERVER}  ${BROWSER}
Run Keyword If  ${response.status_code} == 200
...  Open Browser  ${STAGING_SERVER}  ${BROWSER}
...  ELSE
...  Open Browser  ${DEVELOPMENT_SERVER}  ${BROWSER}
JaPyR
  • 1,367
  • 7
  • 14