【问题标题】:Rally APIs: How to Move A Test FolderRally API:如何移动测试文件夹
【发布时间】:2012-11-18 04:38:59
【问题描述】:

我使用过以下答案中概述的脚本:

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

它很方便,但我真正想做的是将整个测试文件夹移动到另一个项目中。通过 Rally 用户界面,这几乎是不可能的。根据 Rally Support 的说法,在 UI 中执行此操作的唯一方法是:

  • 取消分配当前测试文件夹中的测试用例
  • 在仪表板上设置自定义网格应用
  • 使用自定义网格批量编辑更新测试用例的项目
  • 最后使用自定义网格批量编辑来更新 测试文件夹 - 现在您位于测试用例的目标项目中

尽管上述过程很笨拙,但现在比在自定义网格中进行批量编辑之前更容易了。在您必须逐一编辑每个测试用例之前,这非常手动且速度慢。

但是,我们需要移动数千个测试用例,而自定义网格对我们来说有一个致命的缺陷。它只会显示查询中的前 200 条记录。因此,我们必须以逐步的方式手动更改我们的网格查询以完成我们需要的移动。这比一个接一个地编辑测试用例好不了多少。有没有办法使用脚本移动带有测试用例的测试文件夹从一个项目到另一个项目?请告诉我有。

【问题讨论】:

    标签: ruby rally


    【解决方案1】:

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

    对于那些需要安装和配置 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       = "user@company.com"
    $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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-29
      相关资源
      最近更新 更多