示例#1
0
def pyc(test_run, py_config, request):
    """ A singleton of Pylenium to be shared in the tests of a Class.

    The tests in the class are executed sequentially and in order.

    Warnings:
        This approach is NOT recommended. You should want your tests to be modular, atomic and deterministic.

    Examples:
          class TestGoogle:
              def test_visit_google(self, pyc):
                  # first test navigates to google.com
                  pyc.visit('https://google.com')

              def test_google_search(self, pyc):
                  # second test is already on google.com, test search
                  pyc.get("[name='q']").type('puppies', Keys.ENTER)
                  assert 'puppies' in pyc.title
    """
    # init logger
    class_name = request.node.name
    file_path = f'{test_run}/{class_name}'
    if not os.path.exists(file_path):
        os.makedirs(file_path)
    logger = Logger(class_name, file_path)

    # init driver
    py = Pylenium(py_config, logger)
    yield py
    py.quit()
示例#2
0
def test_case(test_run, py_config, request) -> TestCase:
    """ Manages data pertaining to the currently running Test Function or Case.

        * Creates the test-specific logger.

    Args:
        test_run: The Test Run (or Session) this test is connected to.

    Returns:
        An instance of TestCase.
    """
    test_name = request.node.name
    test_result_path = f'{test_run}/{test_name}'
    logger = Logger(test_name, test_result_path, py_config.logging.pylog_level)

    test = {'name': test_name, 'file_path': test_result_path, 'logger': logger}
    return TestCase(**test)