示例#1
0
def main():
    # Declare TestRail API
    testrail_api = APIClient(TESTRAIL_URL)
    testrail_api.user = TESTRAIL_EMAIL_ADDRESS
    testrail_api.password = TESTRAIL_API_TOKEN

    # Retrieve all sections for the project
    all_sections = testrail_api.send_get('get_sections/' + str(PROJECT_ID))

    # all_results will hold all test results and will be the body of the result submission to TestRail
    all_results = dict()
    all_results['results'] = list()
    all_results['results'] += run_tests(all_sections, testrail_api)

    # Create test run
    new_run = testrail_api.send_post('add_run/' + str(PROJECT_ID), {
        "name": "Webinar Math Tests",
        "include_all": True
    })
    # add results
    run_results = testrail_api.send_post(
        'add_results_for_cases/' + str(new_run['id']), all_results)

    # Close test run
    testrail_api.send_post('close_run/' + str(new_run['id']), {})

    # Display some stuff
    # print(all_results)
    print('Testing Complete!\nResults available here: ' + TESTRAIL_URL +
          'index.php?/runs/view/' + str(new_run['id']))
    pass
示例#2
0
    def __init__(self,
                 host,
                 user,
                 password,
                 file_path,
                 section_id,
                 file_format='robot'):
        """
        :param host: test rail host
        :param user: user name
        :param password: password
        :param file_path: path of test case files or directory
        :param section_id: section to store auto test cases
        :param file_format: default to be .robot
        """
        testrail_url = 'http://' + host + '/testrail/'
        self.client = APIClient(testrail_url, user, password)
        self.file = list()
        # to loop through the test suites
        try:
            if os.path.isdir(file_path):
                for files in os.walk(file_path):
                    for robot_file in filter(lambda x: x.endswith('.robot'),
                                             files[2]):
                        self.file.append(
                            TestData(source=os.path.abspath(
                                os.path.join(files[0], robot_file))))
            else:
                self.file.append(TestData(source=file_path))
        except DataError as e:
            # .robot file may have no test cases in it
            logging.warn('[TestRailTagger]' + e.message)

        self.section = section_id
        self.writer = DataFileWriter(format=file_format)
示例#3
0
    def __init__(self, username='', password='', url=''):
        self.username = username
        self.password = password
        self.url = url

        if not username:
            self.username = settings.USR
        if not password:
            self.password = settings.PWD
        if not url:
            self.url = settings.URL

        client = APIClient(self.url)
        client.user = self.username
        client.password = self.password

        self.client = client
        self.parser = None
示例#4
0
    def __init__(self, server, user, password, run_id, update = None):
        """
        *Args:*\n
        _server_ - the name of TestRail server;
        _user_ - the name of TestRail user;
        _password_ - the password of TestRail user;
        _run_id -  the ID of the test run;
        _update_ - indicator to update test case in TestRail; if exist, then test will be updated.
        """

        testrail_url = 'http://' + server + '/testrail/'
        self.client = APIClient(testrail_url)
        self.client.user = user
        self.client.password = password
        self.run_id = run_id
        self.update = update
        self.results = list()
        logger.info('[TestRailListener] url: ' + testrail_url)
        logger.info('[TestRailListener] user: '******'[TestRailListener] password: '******'[TestRailListener] the ID of the test run: ' + run_id)
示例#5
0
    def __init__(self, tr_server, user_name, password):
        """
        This method will initialize the TestRail server using the user name and password provided
        :param tr_server: Name of the Test Rail server
        :param user_name: TestRail user id
        :param password:  TestRail password
        """
        file_dir = os.path.split(os.path.realpath(__file__))[0]
        logging.config.fileConfig(os.path.join(file_dir, "trlogger.ini"))
        # Configure the logger
        self._log = logging.getLogger('testrail')
        self._log.info("Starting TestRail application ")

        # TestRail Connection status
        # Note: This variable is used to ensure we have a valid TestRail Instance
        self._connection_status = False
        try:
            # Check if the URL is valid
            self._client = APIClient(tr_server)
            self._client.password = password
            self._client.user = user_name
            self._connection_status = True
            # Check if the url, user name and password is set correctly by accessing an API
            self._client.send_get(Defines.TR_API_GET_PROJ + "/" +
                                  str(Defines.TR_PROJ_ID_OTG))
            self._log.info(
                "Connected to TestRail server {} with user-id {}".format(
                    tr_server, user_name))
        except err.URLError:
            self._log.exception("Url: {} is not valid".format(tr_server))
            raise err.URLError("Error: Please check the URL")
        except APIError:
            self._log.critical(
                "User-id or Password is not correct. Failed to connect with TestRail url: {}"
                .format(tr_server))
            raise APIError("Error: Please check user id and password")
示例#6
0
import sys
import getpass
import json
import pprint
from testrail import APIClient

url = 'https://bsro.testrail.net'
client = APIClient(url)
client.user = '******'
client.password = sys.argv[1]

#def usage():
#  print("[!] Usage: tr_conn.py -p password")
#  for eachArg in sys.argv:
#        print(eachArg)


def get_creds():
    print("[<] Enter TestRail login:\n")
    if len(client.user) < 1:
        client.user = input("login: "******"[ha!] forgot something?....where's the password ?")
            sys.exit(0)

    print("[.] k, got the creds for ", client.user)


def input_yes_no(question, default="yes"):
 def __init__(self, url, user, password, project):
     self.client = APIClient(base_url=url)
     self.client.user = user
     self.client.password = password
     self.project = self._get_project(project)
示例#8
0
from creds import *
from testrail import APIClient
import sys
import datetime

client = APIClient(TESTRAIL_URL)
client.user = TESTRAIL_USER
client.password = TESTRAIL_API_TOKEN

RUN_ID = 371
project_id = 0
status_styles = {}


def make_report(test_run_id):
    indent = 1

    html_output = ''

    # Import structured header info
    with open('html_headers.html', 'r') as head_file:
        html_output += head_file.read()

    # Add body of html details
    html_output += get_run_info(test_run_id, indent + 1)

    # Add closing html elements
    html_output += close_element('div', indent)
    html_output += close_element('body', 0)
    html_output += close_element('html', 0)
def get_testrail_client():
    client = APIClient(TESTRAIL_URL)
    client.user = TESTRAIL_USER
    client.password = TESTRAIL_PASSWORD

    return client
示例#10
0
from pprint import pprint
import json
from testrail import APIClient, APIError

import requests

client = APIClient('')
client.user = ''
client.password = ''


class TestRailClient:
    def add_result(self, test_id, status: str):
        _ = client.send_post(f'add_result/{test_id}', {"status_id": 5})

    def add_result_for_case(self, run_id: int, case_id: int, status: str,
                            msg: str):
        """Add test case and update result

        """
        if status.lower() == "pass":
            result = client.send_post(
                'add_result_for_case/%d/%d' % (run_id, case_id), {
                    'status_id': 1,
                    'comment': msg
                })
            return result
        elif status.lower() == "fail":
            result = client.send_post(
                'add_result_for_case/%d/%d' % (run_id, case_id), {
                    'status_id': 5,
示例#11
0
def main():
    server = "http://SERVER.COM"
    login = "******"
    password = "******"

    START_DATE = "01/08/2018"
    END_DATE = "31/08/2018"

    TESTERS = ['USER1EMAIL', 'USER2EMAIL']

    start_date = mktime(datetime.strptime(START_DATE, "%d/%m/%Y").timetuple())
    end_date = mktime(datetime.strptime(END_DATE, "%d/%m/%Y").timetuple())

    client = APIClient(server)
    client.user = login
    client.password = password

    print "Getting testers... "
    testers = {}
    for tester_email in TESTERS:
        try:
            tester = client.send_get('get_user_by_email&email={}'.format(tester_email))
            testers.update({
                tester["id"]: {
                    'email': tester_email,
                    'created': 0,
                    'updated': 0
                }
            })
        except APIError:
            print "Tester's email is not valid", tester_email

    projects = client.send_get('get_projects/')
    for project in projects:
        print "=" * 80
        print "PROJECT", project["id"]

        project_id = project["id"]
        project_suites = client.send_get('get_suites/{}'.format(project_id))

        for suite in project_suites:
            print "-" * 80
            print "SUITE", suite["id"]

            suite_id = suite["id"]

            created = client.send_get(
                'get_cases/{0}&suite_id={1}&created_after={2}&created_before={3}'.format(
                    project_id, suite_id, int(start_date), int(end_date)))

            updated = client.send_get(
                'get_cases/{0}&suite_id={1}&updated_after={2}&updated_before={3}'.format(
                    project_id, suite_id, int(start_date), int(end_date)))

            for c in created:
                tid = c['created_by']
                if tid in testers:
                    testers[tid]['created'] += 1
                # import pdb; pdb.set_trace()

            for c in updated:
                tid = c['updated_by']
                if tid in testers:
                    testers[tid]['updated'] += 1

    # ------------------------------------------------------------------------

    print "=" * 80
    pprint(testers)
示例#12
0
 def __init__(self, TestRailURL='', user='', APIkey=''):
     self._client = APIClient(TestRailURL)
     self._client.user = user
     self._client.password = APIkey
def testrail_requester():
    config = load_configuration()
    client = APIClient("https://dromeroa.testrail.io")
    client.user = "******"
    client.password = config["TESTRAIL_TOKEN"]
    return client