问题
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?
Best regards
回答1:
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.
回答2:
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.
回答3:
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.
来源:https://stackoverflow.com/questions/52930775/robotframework-how-to-retrieve-the-answer-of-a-request