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

Getting {"error"=>"Field :suite_id is a required field."}


#1

So, I keep getting the error above and I am confused. I am currently using HTTParty to perform PUT requests, attaching test cases to test plans. Here is the full code:

require "httparty"
require 'uri'
require 'json'
require "pry"
require "pp"

class TestrailConnect
  include HTTParty
  format :json

  base_uri 'http://testrail.wowzaquality.com/index.php?/api/v2'
  debug_output

  def initialize(username, password)
    @options = {
      basic_auth: {
        username: username,
        password: password
      },
      headers: {
        "Content-Type" => "application/json"
          }
    }
  end


  def add_cases_to_plan(plan_id)
    options = @options.merge({
        "suite_id": "422",
        "include_all": false,
        "runs": [
          "include_all": false,
          "case_ids": ["59361", "61217","61215"]
        ]
    })
    self.class.post("/add_plan_entry/#{plan_id}", options)
  end

end

testrail = TestrailConnect.new('edward.mccarthy@wowza.com', '#{password}')
p testrail.add_cases_to_plan(1541)

Now, these requests all work in Postman, but I can’t seem to run it from my Ruby code. The full debug message:

<- "POST /index.php?/api/v2/add_plan_entry/1541 HTTP/1.1\r\nContent-Type: application/json\r\nAuthorization: Basic ZWR3YXJkLm1jY2FydGh5QHdvd3phLmNvbTpMdkU1OUZnU29XSjJJNWJzT1hLcy1XWU53Ull0RVljRUR6Z3dOTTRmOA==\r\nConnection: close\r\nHost: testrail.wowzaquality.com\r\nContent-Length: 0\r\n\r\n"
<- ""
-> "HTTP/1.1 400 Bad Request\r\n"
-> "Date: Mon, 23 Apr 2018 17:39:05 GMT\r\n"
-> "Server: Apache/2.2.15 (CentOS)\r\n"
-> "X-Powered-By: PHP/5.4.45\r\n"
-> "Content-Length: 48\r\n"
-> "Connection: close\r\n"
-> "Content-Type: application/json; charset=utf-8\r\n"
-> "\r\n"
reading 48 bytes...
-> "{\"error\":\"Field :suite_id is a required field.\"}"
read 48 bytes
Conn close
=> #<HTTParty::Response:0x7fd6b4b62028 parsed_response={"error"=>"Field :suite_id is a required field."}, @response=#<Net::HTTPBadRequest 400 Bad Request readbody=true>, @headers={"date"=>["Mon, 23 Apr 2018 17:39:05 GMT"], "server"=>["Apache/2.2.15 (CentOS)"], "x-powered-by"=>["PHP/5.4.45"], "content-length"=>["48"], "connection"=>["close"], "content-type"=>["application/json; charset=utf-8"]}>
  • Please let me know if I need to add more detail. I’m also happy to clarify.

#2

Try to remove quotes in the suite_id json value like :

“suite_id”: 422


#3

Made some adjustments below:

def add_cases_to_plan(plan_id)
    options = @options.merge({
        "suite_id": 422,
        "include_all": false,
        "runs": [
          "include_all": false,
          "case_ids": ["59361", "61217","61215"]
        ]
    })
    self.class.post("/add_plan_entry/#{plan_id}", options)
  end

Still does not work. Same error message. It simply does not want to see the suite_id


#4

Any other ideas? Anyone from Gurock have any ideas for me to try?


#5

You can use this—

def add_cases_to_plan(plan_id)
options = @options.merge({
“suite_id”: 422,
“include_all”: false,
“runs”: [
“include_all”: false,
“case_ids”: [“59361”, “61217”,“61215”]
]
})
self.class.post("/add_plan_entry/#{plan_id}", options)
end Appvn Jio4GVoice


#6

See below 3DS Emulator


#7

Bro.

That’s exactly what I typed earlier and tried. It doesn’t work