Example #1
0
def add_cass(user, password, section_id, case_data):
    '''
    增加testrail测试用例
    :param user: testrail用户名
    :param password: testrail密码
    :param case_data: 需要添加的case
    :return: None
    '''

    client = testrail.APIClient('http://172.17.3.70/testrail/')
    client.user = user
    client.password = password

    result = []
    try:
        for case_id, testrailcaseid, data in case_data:
            if testrailcaseid not in ('', None, 'None'):
                client.send_post('update_case/%s' % testrailcaseid, data)
            else:
                testrailcaseid_new = client.send_post(
                    'add_case/%s' % section_id, data).get('id', '')
                result.append((case_id, testrailcaseid_new))
    except Exception as e:
        print(e)
    finally:
        return result
Example #2
0
def get_testrail_client(args):
    testrail_username = args['testrail_username']
    testrail_password = args['testrail_password']
    client = testrail.APIClient('https://openebs.testrail.io')
    client.user = testrail_username
    client.password = testrail_password
    return client
Example #3
0
def get_testrail_client(args):
    testrail_username = args['testrail_username']
    testrail_password = args['testrail_password']
    client = testrail.APIClient('https://cloudbyte.testrail.com')
    client.user = testrail_username
    client.password = testrail_password
    return client
 def get_run_id(self):
     method = 'add_run/'
     run_name = datetime.now().strftime('%Y%m%d%H%M%S')
     client = testrail.APIClient(TestRailParams.base_url)
     post = client.send_post(method + TestRailParams.project_id,
                             {'name': run_name})
     run_id = post['id']
     return run_id
    def get_testrail_client(self):
        # Get the TestRail Url
        testrail_url = TESTRAIL_URL
        client = testrail.APIClient(testrail_url)
        # Get and set the TestRail User and Password
        client.user = TESTRAIL_USER
        client.password = TESTRAIL_PASSWORD

        return client
Example #6
0
def get_testrail_client():

    # Get the TestRail Url
    testrail_url = CF.get('Default_TestRail', 'TESTRAIL_URL')
    client = testrail.APIClient(testrail_url)
    # Get and set the TestRail User and Password
    client.user = CF.get('Default_TestRail', 'TESTRAIL_USER')
    client.password = CF.get('Default_TestRail', 'TESTRAIL_PASSWORD')
    return client
Example #7
0
def get_client(args):
    """
    returns api client
    :param args:
    :return: api client
    """
    client = testrail.APIClient("https://cloudbyte.testrail.com")
    client.user, client.password = args['testrail_username'], args[
        "testrail_password"]
    return client
    def set_testrail_conf(self):
        "Set the TestRail URL and username, password"

        #Set the TestRail URL
        self.testrail_url = conf_file.testrail_url
        self.client = testrail.APIClient(self.testrail_url)

        #TestRail User and Password
        self.client.user = conf_file.testrail_user
        self.client.password = conf_file.testrail_password
Example #9
0
def get_testrail_conf():
    "Get the testrail account credentials from the testrail.env file"
    testrail_file = os.path.join(os.path.dirname(__file__), 'testrail.env')
    #TestRail Url
    testrail_url = Conf_Reader.get_value(testrail_file, 'TESTRAIL_URL')
    client = testrail.APIClient(testrail_url)
    #TestRail User and Password
    client.user = Conf_Reader.get_value(testrail_file, 'TESTRAIL_USER')
    client.password = Conf_Reader.get_value(testrail_file, 'TESTRAIL_PASSWORD')

    return client
Example #10
0
    def get_client(cls):
        '''
        获取testrail接口对象
        :return: 返回testrail接口对象
        '''
        if cls.client is None:
            cls.client = testrail.APIClient('http://172.17.3.70/testrail/')
            cls.client.user = cls.user
            cls.client.password = cls.password

        return cls.client
Example #11
0
def create_plan_resources(args, create_plan_resources_args):
    plans_info, path = create_plan_resources_args[
        'plans_info'], create_plan_resources_args['path']
    # Adding testrail client and path to args for reuse
    client, client.user, client.password = testrail.APIClient(
        args['test_rail_api']
    ), args['testrail_username'], args['testrail_password']
    args['client'] = client

    # Iterating over platforms
    for platform in plans_info['Platform']:

        # Iterating over platform dictionary
        for platform_name, platform_info in platform.items():
            print("Setting up " + platform_name + ":")
            plan_util_args = {
                'platform_name': platform_name,
                'platform_info': platform_info,
                'path': path
            }
            temp_path, plan, err = plan_util(args, plan_util_args)
            if err == -1:
                return err
            # creating a map of suite id run id and cases
            create_suite_resources_args = {
                'suites': platform_info['Test Suite'],
                'path': temp_path,
                'plan_id': str(plan['id'])
            }
            map_src_id, master_playbook_map, err = create_suite_resources(
                args, create_suite_resources_args)

            if err == -1:
                return err

            # writing maps to file
            maps = {
                'mapping.json':
                json.dumps(map_src_id),
                'master.yml':
                yaml.dump(master_playbook_map, default_flow_style=False)
            }
            err = write_maps(temp_path, maps)
            if err == -1:
                return err
    return 0
 def send_result(self, context, status, case_id):
     method = 'add_result_for_case/'
     status_id = TestRailParams.testrail_status(status)
     client = testrail.APIClient(TestRailParams.base_url)
     client.send_post(method + str(context.run_id) + '/' + case_id,
                      status_id)
Example #13
0
import urllib2, urllib, os
from jira.client import JIRA
from jira import exceptions
import testrail, json

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'qa_report_2.settings')
from report_view.models import Jira, Bug, Report, Testrail

jira = JIRA(options={'server': 'https://tabtale.atlassian.net'},
            basic_auth=('shmulika', 'cECxWccn16'))
tr_client = testrail.APIClient('https://tabtale.testrail.com/')
tr_client.user = '******'
tr_client.password = '******'


def URLRequest(url, params, method="GET"):
    if method == "POST":
        return urllib2.Request(url, data=urllib.urlencode(params))
    else:
        return urllib2.Request(url + "?" + urllib.urlencode(params))


def create_report(name, jql, testrail):
    r = Report.objects.get_or_create(name=name,
                                     jira_jql=jql,
                                     testrail_plan_id=testrail)[0]
    return r


def create_jira_connector(report):
    j = Jira.objects.get_or_create(report=report)[0]
Example #14
0
def get_client(args):
    client = testrail.APIClient("https://cloudbyte.testrail.com")
    client.user, client.password = args['testrail_username'], args["testrail_password"]
    return client
Example #15
0
import testrail

if __name__ == "__main__":
    client = testrail.APIClient('http://myserver/testrail/')
    client.user = "******"
    client.password = "******"

    status_mapper = testrail.StatusMapper(client.get_statuses())

    projects = client.get_projects()
    for p in projects:
        print(p.name)
        suites = p.get_suites()
        for s in suites:
            print("    [S] " + s.name)
            cases = s.get_cases()
            for c in cases:
                print("        [C] " + c.title)

        runs = p.get_runs()
        for r in runs:
            print("    [R] " + r.name)
            tests = r.get_tests()
            for t in tests:
                print("        [T] %s - > %s" %
                      (t.title, status_mapper[t.status_id].name))
Example #16
0
# -*- coding:utf-8 -*-
from pprint import pprint

__author__ = 'ray'

import testrail

client = testrail.APIClient('http://172.17.3.70/testrail/')
client.user = '******'
client.password = '******'
"""  更新Testrun 结果

add_result_for_case/[runid]/[caseid]
status_id:
{
  1 : Passed
  4 : Retest
  5 : Failed
}

"""
result = client.send_post('add_result_for_case/1047/1036925', {
    'status_id': 1,
    'comment': 'AutoMagic Flag.'
})
# pprint(result)
"""  获取用例信息

get_case/[caseid]
"""
case = client.send_get('get_case/1036925')
Example #17
0
import testrail,pprint

client=testrail.APIClient('http://openebs.testrail.io/testrail/')
client.user="******"
client.password="******"
result=client.send_post('add_results_for_cases/17',
{
	"results": [
		{
			"case_id": 13,
			"status_id": 5,
			"comment": "This test failed",
			"defects": "TR-7"

		},
		{
			"case_id": 15,
			"status_id": 1,
			"comment": "This test passed",
			"elapsed": "5m",
			"version": "1.0 RC1"
		},
	]
}
)

pprint.pprint(result)
Example #18
0
def main():
    parser = argparse.ArgumentParser(
        description='Issuer cli used to comment on github issues')
    parser.add_argument('-gun',
                        '--gusername',
                        help='username for github',
                        required=True)
    parser.add_argument('-gpass',
                        '--gpassword',
                        help='password for github',
                        required=True)
    parser.add_argument('-tun',
                        '--tusername',
                        help='username for testrail',
                        required=True)
    parser.add_argument('-tpass',
                        '--tpassword',
                        help='password for testrail',
                        required=True)
    parser.add_argument('-bn',
                        '--buildnumber',
                        help='buildnumber',
                        required=True)
    args = vars(parser.parse_args())
    gusername, gpassword, tusername, tpassword = args['gusername'], args[
        'gpassword'], args['tusername'], args['tpassword']
    now = datetime.datetime.now()
    date = str(now)[:10]
    path = '/tmp/' + date + '/' + args['buildnumber'] + '/testrail'
    g = github.Github(gusername, gpassword)
    file = open(path + '/mapping.json', 'r')
    map_src_id = json.loads(file.read())

    client = testrail.APIClient('https://openebs.testrail.io')
    client.user = tusername
    client.password = tpassword

    for k, v in map_src_id.items():
        for t in v['cases']:
            # pprint.pprint(t)
            file = open(path + "/cases/" + str(t['case_id']) + "/result.json",
                        'r')
            result_json = json.loads(file.read())
            file.close()
            client.send_post(
                'add_results_for_cases/' + str(v['run_id']), {
                    'results': [{
                        'case_id': t['case_id'],
                        'status_id': str(result_json['status_id'])
                    }]
                })
            # pprint.pprint(req)

            # file=open(path+"/cases/"+str(t['case_id'])+"/logs",'r')
            # comment=file.read()
            # file.close()
            # print(comment)
            # print(t['reponame'])
            # print(t['issue_number'])
            print(g.get_user().get_repo(t['reponame']).get_issue(
                int(t['issue_number'])).create_comment(str(result_json)))
Example #19
0
path = '/tmp/' + date + '/' + build_number + '/testrail'

access_rights = 0o755

# suite_file=open(path+'test.json','r')

# suites=json.loads(suite_file.read())
# suite_ids=suites['suite_ids']
# suite_id=suite_ids.split(',')
# suite_file.close()

file = open(path + "/test.yml", "r")
suites = yaml.load(file.read())
file.close()

client = testrail.APIClient('https://openebs.testrail.io')
client.user = username
client.password = password

plan_name = date + '-build-' + build_number
plan = client.send_post('add_plan/1', {
    'name': plan_name,
    'description': 'creating from API call'
})

#Get the Plan ID
plan_id = str(plan['id'])
# pprint.pprint(plan)
print('Plan created.\nPlan id:', plan_id)

#Add entries to Plan
Example #20
0
import testrail
import json

client = testrail.APIClient('https://jonathan.testrail.com/')
client.user = '******'
client.password = '******'

case = client.send_get('get_case/1')
cleanedcase = json.dumps(case)
print(cleanedcase)

# result = client.send_post(
# 	'add_result_for_case/1/1',
# 	{ 'status_id': 1, 'comment': 'This test worked fine!' }
# )

# result = client.send_post(
# 	'add_result_for_case/1/2',
# 	{ 'status_id': 5, 'comment': 'This test failed miserably' }
# )

# result = client.send_post(
# 	'add_result_for_case/1/3',
# 	{ 'status_id': 5, 'comment': 'Could be worth looking at' }
# )

# print(result)
Example #21
0
#TEST CASE SORT AUTOMATION
#Neon

import testrail
import subprocess
import ssl
import argparse

if hasattr(ssl, '_create_unverified_context'):
    ssl._create_default_https_context = ssl._create_unverified_context

#Credentials to access y Testrail
tr_client = testrail.APIClient('')
tr_client.user = ''
tr_client.password = ''

parser = argparse.ArgumentParser()
parser.add_argument(
    "-a",
    "--add",
    help=
    "add any test cases in the General Regression test run or test plan from a MILESTONE into the Partial Regression suite",
    type=int,
    metavar='')
parser.add_argument("-c",
                    "--check",
                    help="Display info about a test PLAN",
                    type=int,
                    metavar='')
parser.add_argument(
    "--remove",
Example #22
0
	def __init__(self, url, user, password):
	    self.client = testrail.APIClient(url)
	    self.client.user = user
	    self.client.password = password
Example #23
0
##########################
# HOW TO USE THIS SCRIPT #
######################################################################################################################
# 1. Edit testrailAPIClient, suite_id, project_id, type_of_case values to match your criteria
# where:  testrailApiClient - get from TestRail web-site,
# suite_id - get from  TestRail web-site, which cases you want to use in TestRun,
# project_id -  get from  TestRail web-site, where you want to add TestRun,
# type_of_case =  get from  TestRail web-site, take from title of case in TestSuite (for example it will be regression
# or smoke).
# 2. Run the script
# 3. createdRunId is ID of created new run. You can use it everywhere

######################################################################################################################

# Details needed to make the API request
client = testrail.APIClient(
    'https://ustudiocompany.testrail.io')  # do not include index.php?/api/v2
client.user = '******'  # TestRail email address
client.password = '******'  # TestRail password or API token
suite_id = 283
project_id = 13
# type_of_case = 'smoke'

sections_id = client.send_get(f'/get_sections/13&suite_id={suite_id}')
print("What section do you need? Set it, please in 'section_id'.")
print("Warning! The default value is 'sections_id[0]['id']'")
print(sections_id)
# What section do you need?
section_id = sections_id[0]["id"]

cases = client.send_get(
    f'/get_cases/13&suite_id={suite_id}&section_id={section_id}')