def __init__(self, cfg_config): super(CfgComponent, self).__init__() self.log = Logging.get_object_logger(self) self.config = cfg_config if self.config.yaml: cfg_dir = self.find_config_directory( self.config.yaml, self.config.custom_cfg_dirs + [self.config.cfg_dir]) self.log.debug("Using config directory: %s" % cfg_dir) with open(os.path.join(cfg_dir, self.config.yaml)) as f: cfg = yaml.load(f, Loader=yaml.FullLoader) if self.config.j2_config_template is None: self.cfg = cfg else: jinja2_env = jinja2.Environment( loader=jinja2.FileSystemLoader(cfg_dir)) template = jinja2_env.get_template( self.config.j2_config_template) self.cfg = yaml.load(template.render(**cfg)) self.cfg[CfgComponent.CONFIG_FILE_PATH] = os.path.join( cfg_dir, self.config.yaml) else: self.cfg = yaml.load("") print(dir(self.cfg))
def __init__(self, webdriver, root_uri=None): assert isinstance( webdriver, WebDriver ), 'webdriver={} needs to be selenium Webdriver object'.format( webdriver) super(CSFPageObject, self).__init__(webdriver=webdriver, root_uri=root_uri) self.log = Logging.get_object_logger(self)
def __init__(self, context): """ context - provided by radish: - each feature has its own context - for each scenario and its steps context is common however different than feature context - feature context may be retrieved in scenario using scenario.parent.context code - feature context may be retrieved in step using step.parent.parent.context code """ super(StepConfig, self).__init__() self.context = context self.cfg = context.cfg setattr(self.context, 'stc_%s' % self.__class__.__name__, self) self.log = Logging.get_object_logger(self) self.test_data = TestDataBase(self.cfg)
def dot_to_dict_notation(cls, dot_notation): """ replace dot_notation to nested_python_dict_notation so that It can be later used in nested dictionary value evaluation Input: '''a.b[2].c.d['1'].e''' Output: '''['a']['b'][2]['c']['d']['1']['e']''' NOTE the list indices and 'numbers_as_keys' are kept :param dot_notation: :return: """ # https://regex101.com/r/5BhJeE/2 # https://regex101.com/r/5BhJeE/1/codegen?language=python regex = r"(?:[\.'\[])*([_a-z][_a-z0-9- ]*)(?:[\.\]'])*" subst = "['\\1']" output = re.sub(regex, subst, dot_notation, 0, re.IGNORECASE | re.DOTALL) log = Logging.get_object_logger(cls) log.debug("transform: {dot_notation} ==> {output}".format(**locals())) return output
def not_implemented_steps_stub_generator(file_to_append_steps, file_template=None, step_template=None, quoted_string='{:QuotedString}'): """Adding not implemented steps stubs to memory and to file :param file_to_append_steps: Steps stubs will be added to file if file_to_append_step is None: steps will be added to runtime only if file_to_append_step not exists it will be created based on template """ log = Logging.get_logger('csfpy.main_wrapper.NotImplementedStespStub') if file_template is None: file_template = """from radish.stepregistry import steps @steps class GeneratedSteps(object): pass """ if step_template is None: step_template = ''' def {method_name}(self, step, {argument_names}): """{sentence}""" raise NotImplementedError('This step is not implemented yet') ''' if file_to_append_steps is not None: if not os.path.exists(file_to_append_steps): log.debug('Creating steps definition file: %s' % file_to_append_steps) file_to_write_steps = open(file_to_append_steps, 'a') file_to_write_steps.write(file_template) file_to_write_steps.flush() else: file_to_write_steps = open(file_to_append_steps, 'a') def not_implemented_step_stub_method(*args, **kwargs): raise NotImplementedError('This step is not implemented yet') # merge step method replacement of original merge_step radish method def merge_step(step, steps): """ Merges a single step with the registered steps :param Step step: the step from a feature file to merge :param list steps: the registered steps """ match = match_step(step.context_sensitive_sentence, steps) if not match or not match.func: # repalced block of original method # instead of rising StepDefinitionNotFoundError adding no_implemented_step_stub_method # remove Gherkin step base words sentence = re.sub(r'^(And|Given|When|Then|But)\s*', '', step.sentence) # replace "quotedStrings" sentence = re.sub('([^"]|^)"([^"]+)"([^"]|$)', r'\1{0}\3'.format(quoted_string), sentence) if sentence not in steps: sentence = add_sentence(sentence) steps[sentence] = not_implemented_step_stub_method match = StepMatch(not_implemented_step_stub_method, ParseStepArguments(match)) step.definition_func = match.func step.argument_match = match.argument_match # radish monkey patching matcher.merge_step = merge_step def add_sentence(sentence): log.debug('Adding step defintion for sentence:\n\t%s' % sentence) method_name = re.sub('[^0-9a-zA-Z_]+', '_', sentence).lower() method_name = method_name.replace('quotedstring', '') method_name = re.sub('_+', '_', method_name) method_name = method_name.lstrip('_') method_name = method_name.rstrip('_') # replace all not expected characters from method name if file_to_append_steps is not None: step_method_args = ', '.join(['arg_%d' % i for i in range(sentence.count(quoted_string))]) step = step_template.format(method_name=method_name, argument_names=step_method_args, sentence=sentence) log.debug('Adding step definition to file:\n%s' % step) file_to_write_steps.write(step) file_to_write_steps.flush() return sentence
# © 2019 Nokia # Licensed under the BSD 3 Clause license # SPDX-License-Identifier: BSD-3-Clause import argparse import os import sys from radish.main import main as radish_main from radish_ext.radish.stub_generator import not_implemented_steps_stub_generator from radish_ext.sdk.l import Logging log = Logging.get_logger(os.path.basename(__file__)) def main_radish_ext(*argv): if argv is not None: sys.argv += argv parser = argparse.ArgumentParser("""Radish ext main method wrapper There are special user data arguments handled for configuration read --user-data=cfg=config_file.yaml Configuration file: * full path to config file or located in package etc dir --user-data=package=radish_selenium python package name to look for configuration etc dir """, add_help=False) parser.add_argument(
# © 2019 Nokia # Licensed under the BSD 3 Clause license # SPDX-License-Identifier: BSD-3-Clause import random import re import string from functools import wraps from radish_ext.radish.step_config import iter_all_context_step_configs, StepConfig from radish_ext.sdk.l import Logging log = Logging.get_logger(__name__) def _ext_step_decorator(decorator): def decorate(cls): for attr in cls.__dict__: # there's propably a better way to do this if callable(getattr(cls, attr)) and \ ((hasattr(cls, 'ignore') and attr not in cls.ignore) or not hasattr(cls, 'ignore')): setattr(cls, attr, decorator(getattr(cls, attr))) return cls return decorate def ext_steps_replace_from_test_data(): return _ext_step_decorator(replace_or_generate_test_data)
def __init__(self) -> None: super().__init__() self.log = Logging.get_object_logger(self)
def __init__(self): super(RequestsBaseSteps, self).__init__() self.log = Logging.get_object_logger(self) self.tools = RequestsBaseTools()
def __init__(self, template): super(TemplateForNestedDict, self).__init__(template) self.log = Logging.get_object_logger(self)
def __init__(self, cfg) -> None: super().__init__() self.data = {'cfg': cfg, 'generate': {}} self.log = Logging.get_object_logger(self)
def __init__(self): super(Config, self).__init__() self.log = Logging.get_object_logger(self)