Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.

Downloading attachments in Ruby, without API


I understand that the API does not allow exporting test attachments currently.

What I’d like is a way to do this with Ruby. I can gather the URL and file names, but when trying to do something like IO.copy_stream(open(downloadURL, fullyQualFileName) it downloads the html for the login page instead of an image for example. This is because TestRail doesn’t know I’m logged in.

So how, in Ruby, would I go about feeding my credentials or a cookie to that IO request in a way that TestRail is okay with?

I tried a few things, the most promising of which didn’t work and was “IO.copy_stream(open(downloadURL, “Cookie” => cookieString), fullyQualFileName)” where cookieString is a string containing a cookie (letters and numbers seperated by four dashes) I retrieved from Watir using “@browser.driver.manage.all_cookies”. I can’t tell if I’m doing this wrong or if TestRail wants something different from my request.