|
| 1 | +#! /usr/bin/python |
| 2 | +# -*- coding: UTF-8 -*- |
| 3 | + |
| 4 | +# Copyright 2013 Luiko Czub, TestLink-API-Python-client developers |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +# |
| 18 | +# ------------------------------------------------------------------------ |
| 19 | + |
| 20 | + |
| 21 | +""" |
| 22 | +
|
| 23 | +Shows how to use the TestLinkAPIGeneric. |
| 24 | +- does same steps as Example TestLinkAPI in TestLinkExample.py |
| 25 | +
|
| 26 | +=> Counts and lists the Projects |
| 27 | +=> Create a new Project with the following structure: |
| 28 | +
|
| 29 | +
|
| 30 | +NewProject |
| 31 | + | |
| 32 | + ----NewTestPlan |
| 33 | + | |
| 34 | + ------ Test Suite A |
| 35 | + | | |
| 36 | + | ------- Test Suite AA |
| 37 | + | | |
| 38 | + | --------- Test Case AA |
| 39 | + | | |
| 40 | + ------ Test Suite B --- 5 manual test steps |
| 41 | + | |
| 42 | + --------- Test Case B |
| 43 | + | |
| 44 | + --- 5 automated test steps |
| 45 | +""" |
| 46 | +from testlink import TestlinkAPIGeneric, TestLinkHelper |
| 47 | +import sys |
| 48 | + |
| 49 | +# precondition a) |
| 50 | +# SERVER_URL and KEY are defined in environment |
| 51 | +# TESTLINK_API_PYTHON_SERVER_URL=http://YOURSERVER/testlink/lib/api/xmlrpc.php |
| 52 | +# TESTLINK_API_PYTHON_DEVKEY=7ec252ab966ce88fd92c25d08635672b |
| 53 | +# |
| 54 | +# alternative precondition b) |
| 55 | +# SERVEUR_URL and KEY are defined as command line arguments |
| 56 | +# python TestLinkExample.py --server_url http://YOURSERVER/testlink/lib/api/xmlrpc.php |
| 57 | +# --devKey 7ec252ab966ce88fd92c25d08635672b |
| 58 | +# |
| 59 | +# ATTENTION: With TestLink 1.9.7, cause of the new REST API, the SERVER_URL |
| 60 | +# has changed from |
| 61 | +# (old) http://YOURSERVER/testlink/lib/api/xmlrpc.php |
| 62 | +# to |
| 63 | +# (new) http://YOURSERVER/testlink/lib/api/xmlrpc/v1/xmlrpc.php |
| 64 | +tl_helper = TestLinkHelper() |
| 65 | +tl_helper.setParamsFromArgs('''Shows how to use the TestLinkAPI. |
| 66 | +=> Counts and lists the Projects |
| 67 | +=> Create a new Project with the following structure:''') |
| 68 | +myTestLink = tl_helper.connect(TestlinkAPIGeneric) |
| 69 | + |
| 70 | + |
| 71 | +NEWPROJECT="NEW_PROJECT_API_GENERIC" |
| 72 | +NEWTESTPLAN="TestPlan_API_GENERIC" |
| 73 | +NEWTESTSUITE_A="A - First Level" |
| 74 | +NEWTESTSUITE_B="B - First Level" |
| 75 | +NEWTESTSUITE_AA="AA - Second Level" |
| 76 | +NEWTESTCASE_AA="TESTCASE_AA" |
| 77 | +NEWTESTCASE_B="TESTCASE_B" |
| 78 | + |
| 79 | + |
| 80 | +if myTestLink.checkDevKey() != True: |
| 81 | + print "Error with the devKey." |
| 82 | + sys.exit(-1) |
| 83 | + |
| 84 | +# NOT GENERIC |
| 85 | +#print "Number of Projects in TestLink: %s " % (myTestLink.countProjects(),) |
| 86 | +# print "" |
| 87 | +# myTestLink.listProjects() |
| 88 | +# print "" |
| 89 | +# GENERIC |
| 90 | +print "Number of Projects in TestLink: %i " % len(myTestLink.getProjects()) |
| 91 | +print "" |
| 92 | +for project in myTestLink.getProjects(): |
| 93 | + print "Name: %(name)s ID: %(id)s " % project |
| 94 | +print "" |
| 95 | + |
| 96 | + |
| 97 | +# # Creates the project |
| 98 | +# NOT GENERIC |
| 99 | +# newProject = myTestLink.createTestProject(NEWPROJECT, "NPROAPI", |
| 100 | +# "notes=This is a Project created with the API", "active=1", "public=1", |
| 101 | +# "options=requirementsEnabled:0,testPriorityEnabled:1,automationEnabled:1,inventoryEnabled:0") |
| 102 | +# GENERIC |
| 103 | +newProject = myTestLink.createTestProject( |
| 104 | + testprojectname=NEWPROJECT, testcaseprefix='GPROAPI', |
| 105 | + notes='This is a Project created with the Generic API', active=1, public=1, |
| 106 | + requirementsEnabled=0, testPriorityEnabled=1, automationEnabled=1, |
| 107 | + inventoryEnabled=0) |
| 108 | +print(newProject) |
| 109 | +isOk = newProject[0]['message'] |
| 110 | +if isOk=="Success!": |
| 111 | + newProjectID = newProject[0]['id'] |
| 112 | + print "New Project '%s' - id: %s" % (NEWPROJECT,newProjectID) |
| 113 | +else: |
| 114 | + print "Error creating the project '%s': %s " % (NEWPROJECT,isOk) |
| 115 | + sys.exit(-1) |
| 116 | + |
| 117 | +# # Creates the test plan |
| 118 | +# newTestPlan = myTestLink.createTestPlan(NEWTESTPLAN, NEWPROJECT, |
| 119 | +# "notes=New TestPlan created with the API","active=1", "public=1") |
| 120 | +# isOk = newTestPlan[0]['message'] |
| 121 | +# if isOk=="Success!": |
| 122 | +# newTestPlanID = newTestPlan[0]['id'] |
| 123 | +# print "New Test Plan '%s' - id: %s" % (NEWTESTPLAN,newTestPlanID) |
| 124 | +# else: |
| 125 | +# print "Error creating the Test Plan '%s': %s " % (NEWTESTPLAN, isOk) |
| 126 | +# sys.exit(-1) |
| 127 | +# |
| 128 | +# #Creates the test Suite A |
| 129 | +# newTestSuite = myTestLink.createTestSuite(newProjectID, NEWTESTSUITE_A, |
| 130 | +# "Details of the Test Suite A") |
| 131 | +# isOk = newTestSuite[0]['message'] |
| 132 | +# if isOk=="ok": |
| 133 | +# newTestSuiteID = newTestSuite[0]['id'] |
| 134 | +# print "New Test Suite '%s' - id: %s" % (NEWTESTSUITE_A, newTestSuiteID) |
| 135 | +# else: |
| 136 | +# print "Error creating the Test Suite '%s': %s " % (NEWTESTSUITE_A, isOk) |
| 137 | +# sys.exit(-1) |
| 138 | +# |
| 139 | +# FirstLevelID = newTestSuiteID |
| 140 | +# |
| 141 | +# #Creates the test Suite B |
| 142 | +# newTestSuite = myTestLink.createTestSuite(newProjectID, NEWTESTSUITE_B, |
| 143 | +# "Details of the Test Suite B") |
| 144 | +# isOk = newTestSuite[0]['message'] |
| 145 | +# if isOk=="ok": |
| 146 | +# TestSuiteID_B = newTestSuite[0]['id'] |
| 147 | +# print "New Test Suite '%s' - id: %s" % (NEWTESTSUITE_B, TestSuiteID_B) |
| 148 | +# else: |
| 149 | +# print "Error creating the Test Suite '%s': %s " % (NEWTESTSUITE_B, isOk) |
| 150 | +# sys.exit(-1) |
| 151 | +# |
| 152 | +# #Creates the test Suite AA |
| 153 | +# newTestSuite = myTestLink.createTestSuite(newProjectID, NEWTESTSUITE_AA, |
| 154 | +# "Details of the Test Suite AA","parentid="+FirstLevelID) |
| 155 | +# isOk = newTestSuite[0]['message'] |
| 156 | +# if isOk=="ok": |
| 157 | +# TestSuiteID_AA = newTestSuite[0]['id'] |
| 158 | +# print "New Test Suite '%s' - id: %s" % (NEWTESTSUITE_AA, TestSuiteID_AA) |
| 159 | +# else: |
| 160 | +# print "Error creating the Test Suite '%s': %s " % (NEWTESTSUITE_AA, isOk) |
| 161 | +# sys.exit(-1) |
| 162 | +# |
| 163 | +# MANUAL = 1 |
| 164 | +# AUTOMATED = 2 |
| 165 | +# |
| 166 | +# #Creates the test case TC_AA |
| 167 | +# myTestLink.initStep("Step action 1", "Step result 1", MANUAL) |
| 168 | +# myTestLink.appendStep("Step action 2", "Step result 2", MANUAL) |
| 169 | +# myTestLink.appendStep("Step action 3", "Step result 3", MANUAL) |
| 170 | +# myTestLink.appendStep("Step action 4", "Step result 4", MANUAL) |
| 171 | +# myTestLink.appendStep("Step action 5", "Step result 5", MANUAL) |
| 172 | +# |
| 173 | +# newTestCase = myTestLink.createTestCase(NEWTESTCASE_AA, TestSuiteID_AA, |
| 174 | +# newProjectID, "admin", "This is the summary of the Test Case AA", |
| 175 | +# "preconditions=these are the preconditions") |
| 176 | +# isOk = newTestCase[0]['message'] |
| 177 | +# if isOk=="Success!": |
| 178 | +# newTestCaseID = newTestCase[0]['id'] |
| 179 | +# print "New Test Case '%s' - id: %s" % (NEWTESTCASE_AA, newTestCaseID) |
| 180 | +# else: |
| 181 | +# print "Error creating the Test Case '%s': %s " % (NEWTESTCASE_AA, isOk) |
| 182 | +# sys.exit(-1) |
| 183 | +# |
| 184 | +# #Creates the test case TC_B |
| 185 | +# myTestLink.initStep("Step action 1", "Step result 1", AUTOMATED) |
| 186 | +# myTestLink.appendStep("Step action 2", "Step result 2", AUTOMATED) |
| 187 | +# myTestLink.appendStep("Step action 3", "Step result 3", AUTOMATED) |
| 188 | +# myTestLink.appendStep("Step action 4", "Step result 4", AUTOMATED) |
| 189 | +# myTestLink.appendStep("Step action 5", "Step result 5", AUTOMATED) |
| 190 | +# |
| 191 | +# newTestCase = myTestLink.createTestCase(NEWTESTCASE_B, TestSuiteID_B, |
| 192 | +# newProjectID, "admin", "This is the summary of the Test Case B", |
| 193 | +# "preconditions=these are the preconditions", |
| 194 | +# "executiontype=%i" % AUTOMATED) |
| 195 | +# isOk = newTestCase[0]['message'] |
| 196 | +# if isOk=="Success!": |
| 197 | +# newTestCaseID = newTestCase[0]['id'] |
| 198 | +# print "New Test Case '%s' - id: %s" % (NEWTESTCASE_B, newTestCaseID) |
| 199 | +# else: |
| 200 | +# print "Error creating the Test Case '%s': %s " % (NEWTESTCASE_B, isOk) |
| 201 | +# sys.exit(-1) |
| 202 | +# |
| 203 | +print "" |
| 204 | +# NOT GENERIC |
| 205 | +# print "Number of Projects in TestLink: %s " % (myTestLink.countProjects(),) |
| 206 | +# print "" |
| 207 | +# myTestLink.listProjects() |
| 208 | +# GENERIC |
| 209 | +print "Number of Projects in TestLink: %i " % len(myTestLink.getProjects()) |
| 210 | +print "" |
| 211 | +for project in myTestLink.getProjects(): |
| 212 | + print "Name: %(name)s ID: %(id)s " % project |
| 213 | +print "" |
| 214 | +# |
| 215 | +# |
| 216 | +# |
| 217 | +# |
0 commit comments