For now, I am only able to save requests and responses to a file by manually adding console.log(req or response body) for each of api test in script. Is there any env flag to do this automatically? This will be very useful for functional test.
You can use –http-debug. Though bear in mind that, because of some low-level implementation details that are not easy to fix, there are some issues with it: --http-debug shows incorrect "Accept-Encoding" · Issue #1042 · grafana/k6 · GitHub, --http-debug incorrectly reports http protocol · Issue #986 · grafana/k6 · GitHub