如何使用python工具包API在Rally中向测试用例添加步骤

如何使用python工具包API在Rally中向测试用例添加步骤,python,api,rest,rally,Python,Api,Rest,Rally,我最近开始使用Rally python REST API 我试图创建测试用例,但我遇到的问题是,我不知道如何添加步骤以及如何向这些步骤添加内容 有JSON格式吗 请在这方面帮助我以下是一个简单的示例: #!/usr/bin/env python ################################################################################################# # # createt

我最近开始使用Rally python REST API 我试图创建测试用例,但我遇到的问题是,我不知道如何添加步骤以及如何向这些步骤添加内容 有JSON格式吗


请在这方面帮助我以下是一个简单的示例:

    #!/usr/bin/env python

    #################################################################################################
    #
    #  createtestcasewithsteps.py -- Create a TestCase, add Test Steps
    #
    USAGE = """
    Usage: createtestcasewithsteps.py
    """
    #################################################################################################

    import sys, os
    from pyral import Rally, rallySettings

    my_server      = "rally1.rallydev.com"
    my_user        = "user@company.com"
    my_password    = "password"
    my_workspace   = "My Workspace"
    my_project     = "My Project"

    rally = Rally(my_server, my_user, my_password, workspace=my_workspace, project=my_project)
    rally.enableLogging('createtestcasewithsteps.log')

    # For a TestCase: Name, Method, Type are required;
    # Workspace cannot be specified in the JSON, it defaults to 
    # the logged in account's Workspace setting
    # The TestCase can optionally be associated to a WorkProduct
    # Project and WorkProduct must be object refs to relevant Rally Entity instances.
    # In this example the WorkProduct is a Defect.

    target_project = rally.getProject()
    target_defect_id = "DE4"
    target_defect   = rally.get('Defect', query='FormattedID = %s' % target_defect_id, instance=True)

    testcase_fields = {
             "Project"     : target_project.ref,
             "WorkProduct" : target_defect.ref,
             "Name"        : "Data Import Automated Test 01",
             "Method"      : "Automated",
             "Type"        : "Regression"
           }

    print "Creating Test Case ..."
    testcase = rally.put('TestCase', testcase_fields)
    print "Created  TestCase: %s   OID: %s" % (testcase.FormattedID, testcase.oid)

    # Add Test Case Steps
    #
    for i in range(3):

        input="Step Input for Step: "+str(i)
        expected_result="Expected Result for Step: "+str(i)

        testcasestep_fields = {
            "TestCase"          : testcase.ref,
            "StepIndex"         : i,
            "Input"             : input,
            "ExpectedResult"    : expected_result
        }

        testcasestep = rally.put('TestCaseStep', testcasestep_fields)
        print "===> Created  TestCaseStep: %s   OID: %s" % (testcasestep.StepIndex, testcasestep.oid)

以下是如何执行此操作的简要示例:

    #!/usr/bin/env python

    #################################################################################################
    #
    #  createtestcasewithsteps.py -- Create a TestCase, add Test Steps
    #
    USAGE = """
    Usage: createtestcasewithsteps.py
    """
    #################################################################################################

    import sys, os
    from pyral import Rally, rallySettings

    my_server      = "rally1.rallydev.com"
    my_user        = "user@company.com"
    my_password    = "password"
    my_workspace   = "My Workspace"
    my_project     = "My Project"

    rally = Rally(my_server, my_user, my_password, workspace=my_workspace, project=my_project)
    rally.enableLogging('createtestcasewithsteps.log')

    # For a TestCase: Name, Method, Type are required;
    # Workspace cannot be specified in the JSON, it defaults to 
    # the logged in account's Workspace setting
    # The TestCase can optionally be associated to a WorkProduct
    # Project and WorkProduct must be object refs to relevant Rally Entity instances.
    # In this example the WorkProduct is a Defect.

    target_project = rally.getProject()
    target_defect_id = "DE4"
    target_defect   = rally.get('Defect', query='FormattedID = %s' % target_defect_id, instance=True)

    testcase_fields = {
             "Project"     : target_project.ref,
             "WorkProduct" : target_defect.ref,
             "Name"        : "Data Import Automated Test 01",
             "Method"      : "Automated",
             "Type"        : "Regression"
           }

    print "Creating Test Case ..."
    testcase = rally.put('TestCase', testcase_fields)
    print "Created  TestCase: %s   OID: %s" % (testcase.FormattedID, testcase.oid)

    # Add Test Case Steps
    #
    for i in range(3):

        input="Step Input for Step: "+str(i)
        expected_result="Expected Result for Step: "+str(i)

        testcasestep_fields = {
            "TestCase"          : testcase.ref,
            "StepIndex"         : i,
            "Input"             : input,
            "ExpectedResult"    : expected_result
        }

        testcasestep = rally.put('TestCaseStep', testcasestep_fields)
        print "===> Created  TestCaseStep: %s   OID: %s" % (testcasestep.StepIndex, testcasestep.oid)

谢谢你的帮助,马克。这确实奏效了。但我还有一个问题。在TestCaseStep的put请求中,JSON参数具有“StepIndex”。我在中找不到有关参数的任何详细信息。请查看Rally Webservices API(WSAPI)文档:并查找左侧TestCaseStep的链接。这里介绍了WSAPI中的所有对象以及属性、必填字段等。感谢您的帮助。这确实奏效了。但我还有一个问题。在TestCaseStep的put请求中,JSON参数具有“StepIndex”。我在中找不到有关参数的任何详细信息。请查看Rally Webservices API(WSAPI)文档:并查找左侧TestCaseStep的链接。这里描述了WSAPI中的所有对象以及属性、必填字段等。