Closed ghilainm closed 2 years ago
In fact I just gave it a try and it works like described above. However, it is not what is written in the doc. Is it because it does not work all the time?
Send response using specified HTTP code and body. This function should be called after Wait For Request.
Hello @ghilainm ,
Thanks for the issue. It makes sense to reply to a specific request. But I need a bit more information. As I understand you want to implement the following behavior, correct me if I am wrong:
Because it can be covered by the following test (haven't run this test - do not have a backend with a callback, just a draft):
*** Settings ***
Library HttpCtrl.Client
Library HttpCtrl.Server
Test Setup Initialize HTTP Client And Server
Test Teardown Terminate HTTP Server
*** Test Cases ***
Callback Test
${request body}= Set Variable { "callback": "/api/v1/callback1" }
Send HTTP Request POST /api/v1/set_callback1 ${request body}
${response status}= Get Response Status
${expected status}= Convert To Integer 200
Should Be Equal ${response status} ${expected status}
Wait For Request
${url}= Get Request Url
Should Be Equal ${url} /api/v1/callback1
Reply By 200
Or does the server receive other requests during that time? And you need something like:
Wait For Request With URI /api/v1/callback1
Reply By 200
@ghilainm your request is more clear for in the morning. Make sense. I think it is much better to introduce new keyword for that purpose.
Hello, just to make it a bit more clear, that's the kind of interaction I would like to implement.
I don't know if it is what you understood from my original post :).
Hi @ghilainm ,
I have introduced new keywords:
Set Stub Reply
- to set server stub function (link to the documentation: https://annoviko.github.io/robotframework-httpctrl/server.html#Set%20Stub%20Reply)Get Stub Count
- to get server stub statistic (link to the documentation: https://annoviko.github.io/robotframework-httpctrl/server.html#Get%20Stub%20Count).Both are available in HttpCtrl release 0.2.5
:
$ pip3 install robotframework-httpctrl
There is a usage example:
*** Settings ***
Library HttpCtrl.Client
Library HttpCtrl.Server
Test Setup Initialize HTTP Client And Server
Test Teardown Terminate HTTP Server
*** Test Cases ***
Set Signle Stub And Send Request
# Set server stub to reply automatically to POST /api/v1/post
Set Stub Reply POST /api/v1/post 200 Post Message
# Send HTTP request to the server
Send HTTP Request POST /api/v1/post
# Check that the client receives pre-defined values by the stub
${status}= Get Response Status
${body}= Get Response Body
Should Be Equal ${status} ${200}
Should Be Equal ${body} Post Message
# Check that the server receives a single request
${count}= Get Stub Count POST /api/v1/post
Should Be Equal ${count} ${1}
*** Keywords ***
Initialize HTTP Client And Server
Initialize Client 127.0.0.1 8000
Start Server 127.0.0.1 8000
Terminate HTTP Server
Stop Server
Lets consider it as done since no feedback.
@annoviko Sorry mate, no time to work on this now :). Thx a lot for having a look at the proposal. I'll give it a try as soon as I can ;).
Is your feature request related to a problem? Please describe. I would like to define in advance a response to a future request.
Example:
Describe the solution you'd like I should be able to define a Reply By for any future request matching some criteria.
Describe alternatives you've considered Using another library that seems to implement this: https://github.com/ravihuang/robotframework-stublibrary