2

I would like to test the activation of a user. To validate the creation of a user, I click on a "Valid" button and the front-end requests the back-end to send a POST request.
My goal is to retrieve the answer to this query.

I have tried these keywords:

*** Setting ***
Library    SeleniumLibrary
Library    HttpLibrary.HTTP    

*** Keyword ***
!Confirm entry
    [Arguments]    ${id_button}
    Wait Until Element Is Visible    ${id_button}
    Click Element    ${id_button}
    Response Status Code Should Equal    200

Or

*** Setting ***
Library    SeleniumLibrary

*** Keyword ***
!Confirm entry
    [Arguments]    ${id_button}
    Wait Until Element Is Visible    ${id_button}
    ${status}    Run Keyword And Return    Click Element    ${id_button}

These two solutions don't give me satisfaction.
Would you, please, have an idea of the keywords to use in Robotframework to solve my problem?

Bence Kaulics
  • 6,335
  • 7
  • 27
  • 54
Christophe C.
  • 99
  • 1
  • 9

3 Answers3

3

Click Element will not return status code as you expected. You can't get the status code using selenium.

Response Status Code Should Equal is HTTP library and it will work for only when it is followed HTTP Request like GET,POST keywords in HTTP library.

Example      
    HTTP Context    httpstat.us
    GET  /302
    Response Status Code Should Equal   302

It will not work with selenium keywords.

Navarasu
  • 5,221
  • 2
  • 17
  • 29
  • I take note of your remark. Do you know an alternative to my problem? @Navarasu – Christophe C. Oct 22 '18 at 15:40
  • What you are trying to do? Test http request or selenium? If you want to verify http api, purely use HTTP library and do post request and you can verify response as in the answer. If you want to verify UI , to confirm a post request check with UI directly for success message or check the db whether it is added something which to confirm post action is successful – Navarasu Oct 22 '18 at 17:19
  • I thought we could juggle both libraries. I would like to retrieve the answer of the POST command sent. So if I understand correctly, I have to connect to the reception and listen to the port in order to receive the message?The receiver of the message is http://127.0.0.1:1234. Could you, please, help me write the correct syntax? @Navarasu – Christophe C. Oct 23 '18 at 08:21
0

As highlighted by the already given answers mixing HttpLibrary and SeleniumLibrary will not give you access to the status code of the http exchanges between the UI and the webserver.

If you want to ensure that all calls from the browser are given a http 200, then you have to route the traffic through a proxy. In this Stackoverflow Answer working example for the use of BrowserMob proxy is given.

A. Kootstra
  • 6,331
  • 3
  • 17
  • 38
0

To repeat what the others have already said, the browser's requests cannot be intercepted by selenium.
For the purpose of different alternatives, another option to do that is to use Service Workers - that'll get the network traffic and call js in your control that can store (or even modify) the transferred data.

The setup for that can be quite complicated (injecting the worker and the js, then communicating with it from robotframework), here's a very through SO answer to get started on it.

Todor Minakov
  • 14,867
  • 2
  • 44
  • 49