API Documentation¶
This page contains description of all classes and functions which are part of the framework.
main module¶
Main module which contains main function for start of the test exectuion.
-
selenium_generator.main.main()¶ The MAIN method of the framework. It is used for start of execution of test scenarios. The method calls classes for loading configuration according to which the tests are executed. Based to loaded allowed drivers for configuration, the scenarios are run for all specified drivers.
exceptions module¶
Module contains implementation of all custom exceptions.
-
exception
selenium_generator.base.exceptions.InvalidConfiguration(errors)¶ Bases:
ExceptionException is raised when configuration doesn’t match its schema.
- Parameters
errors (
cerberus.errors.ErrorList) – List of allowed drivers
-
__init__(errors)¶ Initialize self. See help(type(self)) for accurate signature.
-
exception
selenium_generator.base.exceptions.InvalidScenario(errors)¶ Bases:
ExceptionException is raised when scenario doesn’t match its schema.
- Parameters
errors (
cerberus.errors.ErrorList) – List of allowed drivers
-
__init__(errors)¶ Initialize self. See help(type(self)) for accurate signature.
-
exception
selenium_generator.base.exceptions.MissingDriverConfiguration(driver)¶ Bases:
Exception- Exception is raised when in test scenario there is specified driver
which is not configured in configuration.
- Parameters
driver (str) – Name of a driver whose configuration is missing
-
__init__(driver)¶ Initialize self. See help(type(self)) for accurate signature.
-
exception
selenium_generator.base.exceptions.UnsupportedDriver(allowed_drivers)¶ Bases:
ValueErrorException is raised when in configuration there is configured local driver which is not supported.
- Parameters
allowed_drivers (list(str)) – List of allowed drivers
-
__init__(allowed_drivers)¶ Initialize self. See help(type(self)) for accurate signature.
singleton module¶
Module contains decerator which is an implementation of singleton design pattern.
-
selenium_generator.base.singleton.__instances= {}¶ List of class instances created with singleton decorator.
-
selenium_generator.base.singleton.singleton(cls)¶ Decorator for singleton design pattern. Function decorates a class and stores its instance to a list of instances from which is later returned if the class is called again.
- Parameters
cls – Decorated class
- Returns
Instance of a decorated class
file_manager module¶
Module contains static class which is used for file and folder management.
-
class
selenium_generator.base.file_manager.FileManager¶ Bases:
objectClass for file manipulation.
-
static
check_extension(file_path, extension)¶ Method checks extension of a given file path.
- Returns
Path to a file extension (str): Required extension of a file
- Return type
file_patch (str)
- Returns
True - Correct extension, False - Incorrect extension
- Return type
bool
-
static
file_exists(path)¶ Method checks if file of a given path exists.
- Parameters
path (str) – Path of a file to check
- Returns
Instance of Remote driver.
-
static
get_list_of_files(dir_path)¶ Methods load all files from given directory and its subdirectories recursively.
- Parameters
dir_path (str) – Path to a dir to load files from
- Returns
List of all loaded files
- Return type
list(str)
-
static
load_json(file_path)¶ Method parses json file into Python dict
- Returns
Parsed json file
- Return type
dict
-
static
load_yaml(file_path)¶ Method parses yaml file into Python dict
- Returns
Parsed yaml file
- Return type
dict
-
static
mkdir(path, parents=True, exists_ok=True)¶ Method creates dir of a given path
- Parameters
path (str) – Path to a dir
parents (bool) – Create all subdirectories recursively
exists_ok (bool) – Firstly checks if dir is already exists
-
static
remove_tree(path)¶ Methods deletes file/directory and its subdirectories of a given path.
- Parameters
path (str) – Path to a file/dir
-
static
base_driver module¶
Module contains base class for WebDrivers and constant with default url for hub.
-
class
selenium_generator.factories.drivers.base_driver.BaseDriver(driver_name, params)¶ Bases:
objectClass Base Driver.
- Parameters
driver_name (str) – Driver name.
params (dict) – Parameters of a driver from configuration.
-
driver_name¶ Driver name.
- Type
str
-
url¶ URL of a remote driver.
- Type
str
-
version¶ Version of a local driver.
- Type
str
-
options¶ Driver Options from configuration.
- Type
list(str)
-
desired_caps¶ Desired capabilities from configuration.
- Type
dict
-
REMOTE= None¶ Class attribute for determination of a type of a driver [True - remote, False - local]
- Type
bool
-
__init__(driver_name, params)¶ Initialize self. See help(type(self)) for accurate signature.
-
classmethod
check_type(driver_type)¶ Method check if type of driver corresponds with a given type in args.
- Parameters
driver_type (str) – Type of a driver to check.
- Returns
True if corresponds, False otherwise.
- Return type
bool
-
selenium_generator.factories.drivers.base_driver.DEFAULT_EXECUTOR= 'http://127.0.0.1:4444/wd/hub'¶ URL of a default executor for running tests on remote machine
driver_factory module¶
Module contains factory class for WebDrivers.
-
selenium_generator.factories.drivers.driver_factory.DEFAULT_DRIVER_CLASSES= [<class 'selenium_generator.factories.drivers.local_driver.LocalDriver'>, <class 'selenium_generator.factories.drivers.remote_driver.RemoteDriver'>]¶ List of class which
DriverFactoryuses for creating of required driver.
-
selenium_generator.factories.drivers.driver_factory.DEFAULT_LOCAL_DRIVERS= ['chrome', 'firefox']¶ List of names of allowed local drivers. In other words driver which are by default supported with
selenium_generator.factories.drivers.local_driver.LocalDriver
local_driver module¶
Module contains class for running local WebDriver.
-
class
selenium_generator.factories.drivers.local_driver.LocalDriver(driver_name, params)¶ Bases:
selenium_generator.factories.drivers.base_driver.BaseDriverClass used for initialization of local WebDriver
-
REMOTE= False¶ Class attribute signifies that class is for local driver
-
_add_option(options)¶ Method adds items to instance of Options for the required driver from configuration.
- Parameters
options – Instance of Options class for required browser
-
_run_chrome()¶ Method runs instance of driver for Chrome.
- Returns
Instance of driver for Chrome.
-
_run_firefox()¶ Method runs instance of driver for Firefox.
- Returns
Instance of driver for Firefox.
-
run()¶ Method calls individual method for running specific driver based on driver name.
- Returns
Instance of required driver.
-
remote_driver module¶
Module contains class for running remote WebDriver.
-
class
selenium_generator.factories.drivers.remote_driver.RemoteDriver(driver_name, params)¶ Bases:
selenium_generator.factories.drivers.base_driver.BaseDriverClass used for initialization of remote WebDriver
-
REMOTE= False¶ Class attribute signifies that class is for remote driver
-
run()¶ Method runs instance of Remote WebDriver.
- Returns
Instance of Remote driver.
-
base_test module¶
Module contains base test class which serves as template for test class generating.
-
class
selenium_generator.factories.tests.base_test.BaseTest(methodName='runTest')¶ Bases:
unittest.case.TestCaseBase class which serves as a template for generating of a test class from test scenario.
-
errors¶ Errors which are present in a test scenario
- Type
dict
-
scenario¶ Loaded test scenario in dictionary format
- Type
dict
-
handler¶ Instance of a class for executing of steps from test scenario
- Type
EventHandler
-
driver¶ Instance of a WebDriver
- Type
selenium.webdriver.remote.webdriver.WebDriver
-
screen_shot_path¶ Path to a screenshot taken on fail
- Type
str
-
driver_name¶ Name of a driver to be used
- Type
str
-
config_parser¶ Class for parsing of a configuration
- Type
ConfigParser
-
_screen_shot_on_error()¶ Method takes and saves a screen shot of a driver page on fail.
-
base_method(**data)¶ Base method which serves as a template for generation of a test method from test scenario.
-
setUp()¶ Method is executed before each test methods in the class.
- Raises
InvalidScenario – It is raised when a test scenario is invalid
-
classmethod
setUpClass()¶ Method is executed before all test methods in the class
-
tearDown()¶ Method is executed after each test methods in the class
-
classmethod
tearDownClass()¶ Method is executed after all test methods in the class
-
test_factory module¶
Module contains factory class for test classes.
page_factory module¶
Module contains function and constants which are used for implementation of Page Factory design pattern.
-
selenium_generator.factories.page_factory._find_by(how, using, multiple, cacheable, context, driver_attr, **kwargs)¶ Decorator used for function which search for web element in used driver.
- Parameters
how (str) – Attribute by which we want to search a web element
using (str) – Value of an attribute by which we want to search a web element
multiple (bool) – Specifies if we are searching multiple web elements
cacheable (bool) – Specifies if we want to store found web element in cache
driver_attr (str) – Name of an attribute where instance of driver is stored
**kwargs (dict) – Key-value pair which specify attribute and value by which we want to search for web element
- Returns
Fuction which search for web element in used driver.
- Return type
function
-
selenium_generator.factories.page_factory._strategy_kwargs= ['id_', 'xpath', 'link_text', 'partial_link_text', 'name', 'tag_name', 'class_name', 'css_selector']¶ Constan which stores allowed values by which a web element can be searched.
-
selenium_generator.factories.page_factory.cacheable_decorator(lookup)¶ Decorator used for cacheable elements.
- Parameters
lookup (type) – Decorated function
- Returns
Fuction which search for element in cache
- Return type
function
-
selenium_generator.factories.page_factory.find_by(how=None, using=None, multiple=False, cacheable=False, context=None, driver_attr='_driver', **kwargs)¶ Public function which returns a correct function for searching for web element. The base one or chacheable, based on given parameters.
- Parameters
how (str) – Attribute by which we want to search a web element
using (str) – Value of an attribute by which we want to search a web element
multiple (bool) – Specifies if we are searching multiple web elements
cacheable (bool) – Specifies if we want to store found web element in cache
driver_attr (str) – Name of an attribute where instance of driver is stored
**kwargs (dict) – Key-value pair which specify attribute and value by which we want to search for web element
- Returns
Function which is used for searching of web element in driver. The base one or chacheable, based on given parameters.
- Return type
function
event_handler module¶
Module contains class which executes steps from given objects from test scenario.
keywords module¶
Module contains class which stores implementation of keywords and related class for calling methods of classes.
-
class
selenium_generator.handlers.keywords.Keywords¶ Bases:
objectClass stores all keywords which can be used in test scenario and its implementation.
-
pages¶ Module with all Page Objects loaded from directory specified in configuration
- Type
module
-
test¶ Instance of BaseTest class
- Type
unittest.TestCase
-
data¶ Test data
- Type
dict
-
__init__()¶ Initialize self. See help(type(self)) for accurate signature.
-
close_driver(*args, **kwargs)¶ Method close instance of a driver
-
maximize(*args, **kwargs)¶ Method maximizes window of a driver
-
page_object(command)¶ Method executes required method of a given Page Object and parse data in it.
- Parameters
command (dict) – Object with specification of a keyword for Page Object
-
run_driver(*args, **kwargs)¶ Method initializes instance of required driver.
-
-
class
selenium_generator.handlers.keywords.MethodExecutor¶ Bases:
objectClass executes method of a required class with given data based on a type of data specification
-
classmethod
_call_method(instance, method, arguments=None, data=None)¶ Method for calling given method based on the given parameters.
- Parameters
instance – Instance of the class whose method we want to execute
method (str) – Name of a class method to execute.
arguments (dict) – Arguments of a method to be called
data (dict) – Test data
-
classmethod
_feed_params(arguments, data)¶ Method feeds method with given data based on method arguments.
- Parameters
arguments (dict) – Arguments of a method to be called with
data (dict) – Test data
- Returns
Parameters to be parsed in a given method
- Return type
dict
-
classmethod
execute_method(instance, method, params, data)¶ The main method of a class. Gets arguments of a method to be run and calls method for calling itself with the right parameters.
- Parameters
instance – Instance of the class whose method we want to execute
method (str) – Name of a class method to execute.
params (dict) – Data from params in scenario step
data (dict) – Data from DDT
-
classmethod
arg_parser module¶
Module contains class which parses CLI parameters.
-
class
selenium_generator.parsers.arg_parser.ArgParser¶ Bases:
objectClass for parsing CLI arguments
-
args¶ Parsed arguments
- Type
Namespace
-
__init__()¶ Initialize self. See help(type(self)) for accurate signature.
-
get_config()¶ Method for getting argument for configuration.
- Returns
Path to configuration
- Return type
str
-
config_parser module¶
Module contains classes which are used for parsing of configuration and constant with default configuration.
-
selenium_generator.parsers.config_parser.DEFAULT_CONFIG= {'data': 'data', 'drivers': {'chrome': {'remote': False}, 'firefox': {'remote': False}}, 'pages': 'pages', 'report': {'clean': True, 'screenshots': True}, 'scenarios': 'scenarios', 'tags': []}¶ Constant with default configuration
loader module¶
Module contains class loads required test scenarios and generate test classes based on given parameters.
test_runner module¶
Module contains classes needed for running the tests and storing the result in the test report.
-
selenium_generator.test_runner.runner.DEFAULT_OUTPUT= './reports/'¶ Default directory where test report should be generated.
-
selenium_generator.test_runner.runner.DEFAULT_TEMPLATE= '/home/docs/checkouts/readthedocs.org/user_builds/selenium-generator/checkouts/master/selenium_generator/test_runner/template/report_template.html'¶ Path to a default template for test report
-
class
selenium_generator.test_runner.runner.Result(stream, descriptions, verbosity)¶ Bases:
HtmlTestRunner.result.HtmlTestResultClass which is used for generating of test result.
- Parameters
stream (
unittest.runner._WritelnDecorator) –descriptions (bool) –
verbosity (int) – Arg specify how detailed information we want to write in the console
-
__init__(stream, descriptions, verbosity)¶ Initialize self. See help(type(self)) for accurate signature.
-
_create_test_info(test, err)¶ Base method for creating of instance of _TestInfo class based on given parameters.
- Parameters
test_method (type) – Executed test method
err (tuple) – Holds detailed information about occurred error
- Returns
Instance of a _TestInfo class which holds information about execution of a test
- Return type
-
addError(test, err)¶ Method which create information about failed tests on error.
- Parameters
test_method (type) – Executed test method
err (tuple) – Holds detailed information about occurred error
-
addFailure(test, err)¶ Method which create information about failed tests on fail.
- Parameters
test_method (type) – Executed test method
err (tuple) – Holds detailed information about occurred error
-
class
selenium_generator.test_runner.runner.Runner(driver_name='', output='./reports/', report_title='Test results', report_name='TestReport', template='/home/docs/checkouts/readthedocs.org/user_builds/selenium-generator/checkouts/master/selenium_generator/test_runner/template/report_template.html', resultclass=<class 'selenium_generator.test_runner.runner.Result'>)¶ Bases:
HtmlTestRunner.runner.HTMLTestRunnerClass for running test scenarios.
- Parameters
driver_name (str) – Name of a driver
output (str) – Path to folder for storing test report
report_title (str) – Title of a generated test report
report_name (str) – Name of a html file with test report
template (str) – Path to file with test report template
resultclass (Result) – Test result class
-
driver_name¶ Name of a driver
- Type
str
-
output¶ Path to folder for storing test report
- Type
str
-
report_title¶ Title of a generated test report
- Type
str
-
report_name¶ Name of a html file with test report
- Type
str
-
template¶ Path to file with test report template
- Type
str
-
__init__(driver_name='', output='./reports/', report_title='Test results', report_name='TestReport', template='/home/docs/checkouts/readthedocs.org/user_builds/selenium-generator/checkouts/master/selenium_generator/test_runner/template/report_template.html', resultclass=<class 'selenium_generator.test_runner.runner.Result'>)¶ Construct a TextTestRunner.
Subclasses should accept **kwargs to ensure compatibility as the interface changes.
-
class
selenium_generator.test_runner.runner.TestInfo(test_result, test_method, outcome=0, err=None, sub_test=None, screen_shot=None)¶ Bases:
HtmlTestRunner.result._TestInfoClass which stores information about executed test.
- Parameters
test_result (Result) – Test result class
test_method (type) – Executed test method
outcome (int) – Index which takes test correct value for test result type from _TestInfo class
err (tuple) – Holds detailed information about occurred error
sub_test –
screen_shot (str) – Path to screen shot of a failed test
-
screen_shot¶ Path to screen shot of a failed test
- Type
str
-
__init__(test_result, test_method, outcome=0, err=None, sub_test=None, screen_shot=None)¶ Initialize self. See help(type(self)) for accurate signature.
validator module¶
Module contains classes and constants which are used for validation of dictionaries against schema.
-
selenium_generator.validators.validator.DEFAULT_CONFIG_SCHEMA= '/home/docs/checkouts/readthedocs.org/user_builds/selenium-generator/checkouts/master/selenium_generator/validators/schemas/config_schema.json'¶ Path to a file with a default schema for configuration`
-
selenium_generator.validators.validator.DEFAULT_DRIVER_SCHEMA= '/home/docs/checkouts/readthedocs.org/user_builds/selenium-generator/checkouts/master/selenium_generator/validators/schemas/driver_schema.json'¶ Path to a file with a default schema for configuration of drivers`
-
selenium_generator.validators.validator.DEFAULT_SCENARIO_SCHEMA= '/home/docs/checkouts/readthedocs.org/user_builds/selenium-generator/checkouts/master/selenium_generator/validators/schemas/scenario_schema.json'¶ Path to a file with a default schema for test scenario`
-
class
selenium_generator.validators.validator.ExtendedValidator(*args, **kwargs)¶ Bases:
cerberus.validator.ValidatorClass extends Validator class from Cerberus framework
cerberus.validator.Validator-
validate_presence_if_value(document, field, value, required_field)¶ Method checks presence of key based on another field and its value.
- Parameters
document (dict) – Dictionary to check
field (str) – Dependent field for required field
value – Value of a dependent field
required_field (str) – Field which should be present
- Returns
True - valid (required field is in document), False - invalid (required field is not in document)
- Return type
bool
-