简体   繁体   中英

How to query for test cases by test folder name using Ruby REST API?

I queried test folders and have the query result. Now I need to find test cases by the test folder. Should I query by reference, or any other attribute? I would like to know the syntax I need to use.

Let's say you have the test folder name as a result of previous query:

folder_name = tf_results.first.Name

The test cases that are associated with this test folder can be found using this syntax:

tc_query.query_string = "(TestFolder.Name = \"#{folder_name}\")" 

Here is the full code that uses Rally Ruby REST API (rally_api gem).

require 'rally_api'


#Setup custom app information
headers = RallyAPI::CustomHttpHeader.new()
headers.name = "find test cases by test folder name"
headers.vendor = "Nick M RallyLab"
headers.version = "1.0"

# Connection to Rally
config = {:base_url => "https://rally1.rallydev.com/slm"}
config[:username] = "user@co.com"
config[:password] = "secret"
config[:workspace] = "W"
config[:project] = "P"
config[:headers] = headers #from RallyAPI::CustomHttpHeader.new()

@rally = RallyAPI::RallyRestJson.new(config)

tf_query = RallyAPI::RallyQuery.new()
tf_query.type = :testfolder
tf_query.fetch = "Name,FormattedID"
tf_query.workspace = {"_ref" => "https://rally1.rallydev.com/slm/webservice/1.43/workspace/11111.js" } #optional
tf_query.project = {"_ref" => "https://rally1.rallydev.com/slm/webservice/1.43/project/22222.js" } #optional
tf_query.page_size = 200 #optional - default is 200
tf_query.limit = 1000 #optional - default is 99999
tf_query.project_scope_up = false
tf_query.project_scope_down = true
tf_query.order = "Name Asc"
tf_query.query_string = "(Name = \"My Test Folder 1\")"

tf_results = @rally.find(tf_query)


tf_results.each do |t|
    puts "Name: #{t["Name"]}, FormattedID: #{t["FormattedID"]}"
    t.read
end

folder_name = tf_results.first.Name

tc_query = RallyAPI::RallyQuery.new()
tc_query.type = :testcase
tc_query.fetch = "Name,FormattedID"
tc_query.workspace = {"_ref" => "https://rally1.rallydev.com/slm/webservice/1.43/workspace/12352608129.js" } #optional
tc_query.project = {"_ref" => "https://rally1.rallydev.com/slm/webservice/1.43/project/12352608219.js" } #optional
tc_query.page_size = 200 #optional - default is 200
tc_query.limit = 1000 #optional - default is 99999
tc_query.project_scope_up = false
tc_query.project_scope_down = true
tc_query.order = "Name Asc"

tc_query.query_string = "(TestFolder.Name = \"#{folder_name}\")"  

puts "same string" if ("My Test Folder 1" == folder_name)

tc_results = @rally.find(tc_query)

tc_results.each do |t|
    puts "Name: #{t["Name"]}, FormattedID: #{t["FormattedID"]}"
    t.read
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM