Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postman to k6 issue - Postman sends value as number, k6 sends value as string #137

Open
Adrian-2705 opened this issue Aug 9, 2024 · 10 comments
Assignees
Labels
question/validate Further information or Validation is requested from the reporter

Comments

@Adrian-2705
Copy link

Hi all!
I have an issue with a converted test from Postman to k6.
In Postman I am sending a payload body that has a number as a value, and the test passes, but the converted test in k6, sends the value as a string and the test fails.
The issue here is that it needs to be a number, not a string, for the test to pass.

@thim81
Copy link
Collaborator

thim81 commented Aug 9, 2024

Hi @Adrian-2705

That is indeed not the desired behaviour. Would it be possible to share your postman collection so we can use it for debugging the conversion?

I ll look into it when back from vacation.

@Adrian-2705
Copy link
Author

Hello @thim81 ,
I've attached the Postman collection for you to look over.
testing k6.postman_collection.json
Hopefully, you guys manage to fix the issue, or at least give me a pointer to where I am doing something wrong on my end. I've depleted all of my thoughts on how to fix the code and make it work.

@thim81 thim81 self-assigned this Aug 17, 2024
@thim81 thim81 added the Investigate Needs more investigation, before next steps can be defined. label Aug 17, 2024
@thim81
Copy link
Collaborator

thim81 commented Aug 18, 2024

hi @Adrian-2705

The reason it is using "string" values, is because in your Postman request you wrapped the Postman variables in "" which makes them strings.

image

If you remove the "" around your variables, Postman and K6 will handle them as Number values.

Postman
image

K6 Script
image

K6 Request Execution
image

@thim81 thim81 added question/validate Further information or Validation is requested from the reporter and removed Investigate Needs more investigation, before next steps can be defined. labels Aug 18, 2024
@Adrian-2705
Copy link
Author

Hello @thim81,
I've tested what you showed me.
I have the following results:

  1. for validation_request_id, it needs to be a string, if not it will result in a 422 Unprocessable Entity error.
  2. I've removed the quotes from event_timestamp and document_id, and on Postman it sends them as numbers, but in k6 I still get invalid event_timestamp. It sends the values as strings.
  3. I have started manually writing the whole script/test in k6 and got the desired results.
    There is a possibility that Postman libraries have an issue when converting the collection to k6.
    Anyway, thank you for the help.
    If I encounter other issues, I will report them and let you know.

@thim81
Copy link
Collaborator

thim81 commented Aug 22, 2024

hi @Adrian-2705

The goal of the postman-to-k6 converter is that it generates the correct K6 scripts.

When doing the investigation, I used your Postman collection and made the elements unquoted, which led to the expected K6 scripts. So I'm surprised that you still ran into issues.

If you have more info to share, on what you had to correct so that I can review any changes in the postman-to-k6 converter?

@Adrian-2705
Copy link
Author

Hi @thim81
I understand the purpose of postman-to-k6, and it should generate the correct scripts, but believe me, I still got the same result, issue in k6.
I will do some digging to see if I can change anything else in my Postman test and not break it, and test the conversion to k6.
I will share what I find tomorrow.

@thim81
Copy link
Collaborator

thim81 commented Aug 22, 2024

It might be helpfull for your debugging to trigger k6 with --http-debug="full"

example => k6 run k6/marvel.k6.js --http-debug="full"

@Adrian-2705
Copy link
Author

Adrian-2705 commented Aug 22, 2024

Will use it, thank you

@thim81
Copy link
Collaborator

thim81 commented Aug 27, 2024

hi @Adrian-2705

Did you find anything that explains the behaviour or were able to reproduce or overcome it?

@Adrian-2705
Copy link
Author

Hi @thim81 ,
Sorry for the delay, I've been testing, and trying different approaches, but I get the same result.
This is the debug:
`k6 run possible-fix.js --http-debug="full"

      /\      |‾‾| /‾‾/   /‾‾/   
 /\  /  \     |  |/  /   /  /    
/  \/    \    |     (   /   ‾‾\  

/ \ | |\ \ | (‾) |
/ __________ \ |__| _\ ____/ .io

 execution: local
    script: possible-fix.js
    output: -

 scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
          * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

INFO[0000] Request:
POST /event/ HTTP/1.1
Host: localhost:5000
User-Agent: k6/0.53.0 (https://k6.io/)
Content-Length: 167
Authorization: Basic aW5zcGlydXM6amU0cW9zM3cwMDc=
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip

event_data=map%5Bdocument_id%3A81890+validation_request_id%3A545851+validation_status%3Avalidated%5D&event_timestamp=1724861529&event_type=document.validation.response group= iter=0 request_id=cfa91ce2-1536-44dd-5c77-8934a4de151b scenario=default source=http-debug vu=1
INFO[0000] Response:
HTTP/1.1 422 Unprocessable Entity
Content-Length: 38
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Type: application/json; charset=utf-8
Date: Wed, 28 Aug 2024 16:12:09 GMT
Etag: W/"26-ax897zOYepat8NqDEV12s361pqA"
Keep-Alive: timeout=5
X-Powered-By: Express

{"errors":["Invalid event timestamp"]} group= iter=0 request_id=cfa91ce2-1536-44dd-5c77-8934a4de151b scenario=default source=http-debug vu=1
`

Hope it helps,
Also I've change the pre-request-scripts from Postman.
Screenshot from 2024-08-28 19-11-00

As I said, I've managed to write the code manually for what I am testing without the convertion. It would've been a time saver if it worked.
Please let me know what else I can provide to help fixing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question/validate Further information or Validation is requested from the reporter
Projects
None yet
Development

No branches or pull requests

2 participants