2012-11-18 46 views
0

我在以下答案中列出的脚本工作:拉力赛的API:如何将一个测试文件夹

Rally APIs: How to copy Test Folder and member Test Cases

和它的方便,但我真正想要做的是移动整个测试文件夹放入不同的项目中。通过拉力赛用户界面几乎是不可能的。据拉力赛的支持,在UI做到这一点的唯一方法是:

  • 取消分配从目前的测试文件夹
  • 设置自定义网格的应用程序的测试案例在仪表板
  • 使用自定义网格批量编辑更新项目的测试案例的
  • 最后使用自定义网格批量编辑更新测试文件夹 - 现在你在目标项目中,测试用例的

即使上述过程笨重,现在也比在自定义网格中出现批量编辑之前更容易一些。在您必须逐一编辑每个测试用例之前,这是非常手动和缓慢的。然而,我们有几千个我们需要移动的测试用例,而定制网格对我们来说有一个致命的缺陷。它只会显示查询中的前200条记录。因此,我们必须手动更改我们的网格查询,以逐步完成我们所需的移动。这比编辑测试用例一个接一个好。有没有办法移动测试文件夹与测试用例从一个项目到另一个,使用脚本?请告诉我有。

回答

0

以下脚本将执行此任务 - 它会将所有测试用例从由FormattedID标识的源测试文件夹移动到也由FormattedID标识的目标测试文件夹。源测试文件夹和目标测试文件夹可以位于不同的项目中(尽管它们必须位于同一工作区内)。与问题中引用的复制脚本类似,目标测试文件夹必须存在,即如果未找到目标,脚本将不会为您创建测试文件夹。

对于那些需要安装和配置Ruby的REST工具包,链接在此:

Developer Portal: Rally REST API for Ruby

Github

# Copyright 2002-2012 Rally Software Development Corp. All Rights Reserved. 

require 'rally_api' 

$my_base_url  = "https://rally1.rallydev.com/slm" 
$my_username  = "[email protected]" 
$my_password  = "password" 
$my_workspace  = "My Workspace" 
$my_project  = "My Project" 
$wsapi_version  = "1.39" 

# Test Folders 
$source_test_folder_formatted_id = "TF8" 
$target_test_folder_formatted_id = "TF11" 

#==================== Make a connection to Rally ==================== 
config     = {:base_url => $my_base_url} 
config[:username]  = $my_username 
config[:password]  = $my_password 
config[:workspace]  = $my_workspace 
config[:project]  = $my_project 
config[:version]  = $wsapi_version 

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

begin 

    # Lookup source Test Folder 
    source_test_folder_query = RallyAPI::RallyQuery.new() 
    source_test_folder_query.type = :testfolder 
    source_test_folder_query.fetch = true 
    source_test_folder_query.query_string = "(FormattedID = \"" + $source_test_folder_formatted_id + "\")" 

    source_test_folder_result = @rally.find(source_test_folder_query) 

    # Lookup Target Test Folder 
    target_test_folder_query = RallyAPI::RallyQuery.new() 
    target_test_folder_query.type = :testfolder 
    target_test_folder_query.fetch = true 
    target_test_folder_query.query_string = "(FormattedID = \"" + $target_test_folder_formatted_id + "\")" 

    target_test_folder_result = @rally.find(target_test_folder_query) 

    if source_test_folder_result.total_result_count == 0 
    puts "Source Test Folder: " + $source_test_folder_formatted_id + "not found. Exiting." 
    exit 
    end 

    if target_test_folder_result.total_result_count == 0 
    puts "Target Test Folder: " + $target_test_folder_formatted_id + "not found. Target must exist before moving." 
    exit 
    end 

    source_test_folder = source_test_folder_result.first() 
    target_test_folder = target_test_folder_result.first() 

    # Populate full object for both Source and Target Test Folders 
    full_source_test_folder = source_test_folder.read 
    full_target_test_folder = target_test_folder.read 

    # Grab collection of Source Test Cases 
    source_test_cases = source_test_folder["TestCases"] 

    # Loop through Source Test Cases and Move to Target 
    source_test_cases.each do |source_test_case| 
    begin 

     test_case_to_update = source_test_case.read 
     source_test_case_formatted_id = test_case_to_update["FormattedID"] 

     target_project = full_target_test_folder["Project"] 
     target_project_full_object = target_project.read 
     target_project_name = target_project_full_object["Name"] 

     source_project = full_source_test_folder["Project"] 
     source_project_full_object = source_project.read 
     source_project_name = source_project_full_object["Name"] 

     puts "Source Project Name: #{source_project_name}" 
     puts "Target Project Name: #{target_project_name}" 

     # Test if the source project and target project are the same 
     source_target_proj_match = source_project_name.eql?(target_project_name) 

     # If the target Test Folder is in a different Project, we have to do some homework first: 
     # "un-Test Folder" the project 
     # Assign the Test Case to the Target Project 
     # Assign the Test Case to the Target Test Folder 
     if !source_target_proj_match then 
     fields = {} 
     fields["TestFolder"] = "" 
     test_case_updated = @rally.update(:testcase, test_case_to_update.ObjectID, fields) #by ObjectID 
     puts "Test Case #{source_test_case_formatted_id} successfully dissociated from: #{$source_test_folder_formatted_id}" 

     # Get full object on Target Project and assign Test Case to Target Project 
     fields = {} 
     fields["Project"] = target_project_full_object 
     test_case_updated = @rally.update(:testcase, test_case_to_update.ObjectID, fields) #by ObjectID 
     puts "Test Case #{source_test_case_formatted_id} successfully assigned to Project: #{target_project_name}" 
     end 

     # Change the Test Folder attribute on the Test Case 
     fields = {} 
     fields["TestFolder"] = target_test_folder 
     test_case_updated = @rally.update(:testcase, test_case_to_update.ObjectID, fields) #by ObjectID 
     puts "Test Case #{source_test_case_formatted_id} successfully moved to #{$target_test_folder_formatted_id}" 
    rescue => ex 
     puts "Test Case #{source_test_case_formatted_id} not updated due to error" 
     puts ex 
    end 
    end 
end 
+0

这会帮助我们,谢谢! – user1373451

相关问题