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

Write files #666

Closed
if-kenn opened this issue Jun 6, 2018 · 7 comments
Closed

Write files #666

if-kenn opened this issue Jun 6, 2018 · 7 comments

Comments

@if-kenn
Copy link

if-kenn commented Jun 6, 2018

I am trying to determine why certain login tests are failing. To do so I need to examine the HTML that has been returned. While I realize that I can output this to the screen via console.log, it is cleaner and easier to read if it is output to a file. Is there anyway to write to the filesystem with k6?

Thanks

@na--
Copy link
Member

na-- commented Jun 6, 2018

Unfortunately there's no way to write directly to the filesystem. That's mostly because of security and portability concerns when dealing with the distributed cluster and cloud execution.

For easier debugging, we recently added a --logformat=raw option that doesn't output debug information in the logs. If you run k6 run --logformat=raw script.js 2> debug.html, you'd get only the things you output via console.log() in the newly created debug.html

@if-kenn
Copy link
Author

if-kenn commented Jun 6, 2018

Thanks for the reply, I will look towards that for debugging. I guess I could also setup a collector server to record html/data as well.

@na--
Copy link
Member

na-- commented Jun 6, 2018

Yes, it would probably be easier for debugging more complicated scenarios. Another possibility is passing things through JSON.stringify() before logging them and then parsing the resulting log with something like jq.

@na--
Copy link
Member

na-- commented Oct 5, 2018

Closing this for now, since we don't currently plan to introduce support for writing files or other potentially unsafe operations. Logging with the --logformat=raw and --logformat=json options and the --httpdebug flag should cover most debug needs, though we can potentially reopen this issue if there's enough user demand and we decide to add some unsafe local debug execution mode in the future.

@ofauchon
Copy link
Contributor

ofauchon commented Mar 8, 2021

Why not adding a --unsafe-operations flags in k6 for such cases ?

Writing raw files can be useful eg: when you want them to be consumed by an existing process (which expects a specific format)

Implementing a companion http server for that should work, but introduce extra overhead.

Olivier

@na--
Copy link
Member

na-- commented Mar 8, 2021

@ofauchon, we now have xk6, so you can write unsafe extensions in Go that do pretty much anything, including write files. More details:

It's a bit more involved, but at the same time it's much more flexible than what you suggest. It allows you to do anything, from writing files to apparently connecting to minecraft servers 😅

@nguyenquangtay
Copy link

Hello,
I'm a newbie on K6,
I'm facing a problem with saving the cookie to a local file then re-use it for calling another APIs...
after searching, I found this, but I don't know how to use it, so anyone could help me using the xk6 for writing the cookie to local file, thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants