Full error: Failed to send test result to Zephyr. Response: {"error": "Failed to parse Connect Session Auth Token"}
I'm a newbie and trying to learn how to execute a rspect script and change the results to a zephyr test case. I found the example below but when I execute it, I get the following result
Failed to send test result to Zephyr. Response: {"error": "Failed to parse Connect Session Auth Token"} . Finished in 4.86 seconds (files took 0.05997 seconds to load) 1 example, 0 failures
Here's the code (I'm not including the actual test file being executed) and I faked the token information
require 'net/http'
require 'uri'
require 'json'
require 'selenium-webdriver'
require 'rspec'
# Define the Zephyr API token and test execution details
JIRA_API_TOKEN = 'blah-blah-blah-blah'
TEST_EXECUTION_KEY = 'ACQ-Blah' # Replace with your actual test execution key
# This method sends the test results to Zephyr (Jira)
def report_to_zephyr(test_case_id, status, execution_time)
# Define Zephyr API endpoint URL
uri = URI.parse("#{JIRA_URL}/rest/api/2.0/testexec/#{TEST_EXECUTION_KEY}/result")
# Create HTTP headers for the request (including authentication)
headers = {
'Authorization' => "Bearer #{JIRA_API_TOKEN}",
'Content-Type' => 'application/json'
}
# Define the payload for the test result (use "PASS" or "FAIL")
result = {
'testCaseId' => test_case_id, # The Test Case ID from Jira
'status' => status, # 'PASS' or 'FAIL'
'executionTime' => execution_time, # Time the test took
'comments' => 'Automated test result via Selenium and Ruby' # Optional comment
}
# Convert the result to JSON
request_body = result.to_json
# Set up the HTTP POST request
request = Net::HTTP::Post.new(uri.path, headers)
request.body = request_body
# Make the HTTP request
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true # Ensure SSL is used for the connection (important for Jira Cloud)
response = http.request(request)
# Print the response from the API (for debugging)
if response.is_a?(Net::HTTPSuccess)
puts "Test result successfully sent to Zephyr!"
else
puts "Failed to send test result to Zephyr. Response: #{response.body}"
end
end
RSpec::Core::Runner.run(['JUNK2.rb']) # Replace 'test_script.rb' with your actual test file name
Thanks for any guidance on where I should start looking.