使用 Pyral api 获取测试文件夹中的所有测试用例

Getting all the test cases inside the test folder using Pyral api

我用过pyral api

rally = Rally(server, apikey=api_key, workspace=workspace, project=project)

连接到拉力赛 比 ,

  testfolders = rally.get('TestFolder', fetch=True, query=query_criteria) 

我需要提取集会中定义的所有测试用例为:

TF*****
  -TC1
  -TC2
  -TC3

我需要从返回的 formattedID 中获取所有测试用例 测试文件夹。

for tc in testfolders:
   print(tc.Name)
   print(tc.FormattedID)# this represents the TF***
   tc_link=tc._ref#url for TC's https://rally1.rallydev.com/slm/webservice 
query_criteria = 'TestSets = "%s"' % tp_name
testfolders = rally.get('TestFolder', fetch=True, query=query_criteria)

我试过寻找不同的组合集来提取测试用例 tc._ref 实际上是

https://rally1.rallydev.com/slm/webservice/v2.0/TestFolder/XXXXX/TestCases

当我试图在浏览器中打开它时,它给出了整个测试用例列表。 我需要提取那些测试用例列表。 我尝试使用 urllib 访问以使用 python 访问数据,但是说未经授权的访问,我认为如果我在同一个会话中,授权应该不是问题,因为 rally 对象已经实例化了。 对此的任何帮助将不胜感激! 提前致谢

    rally = Rally(server, apikey=api_key, workspace=workspace, project=project)
    tp_name = "specific test case "
    query_criteria = 'FormattedID = "%s"' % tp_name
    testfolders = rally.get('TestFolder', fetch=True, query=query_criteria)
    for tc in testfolders:
         print(tc.Name)
         print(tc.FormattedID)   
         query_criteria = 'TestSets = "%s"' % tc._ref
         response = rally.get('TestCase', fetch=True, query=query_criteria)
         print(response)

422 Could not read: could not read all instances of class com.f4tech.slm.domain.TestCase for class TestCase

不清楚您要实现的目标,但请查看下面的代码。可能会解决您的问题:

query = 'FormattedID = %s'

test_folder_req = rally.get('TestFolder', fetch=True, projectScopeDown=True,
                                       query=query % folder_id) # folder_id == "TF111"
if test_folder_req.resultCount == 0:
    print('Rally returned nothing for folder: %s', folder_id)
    sys.exit(1)

test_folder = test_folder_req.next()

test_cases = test_folder.TestCases
print('Start working with %s' % folder_id)
print('Test Folder %s contains %s TestCases' % (folder_id, len(test_cases)))

for test_case in test_cases:
    print(test_case.FormattedID)
    print(test_case.Name)