_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 31 13.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q19600 | Utils.wait_until_element_stops | train | def wait_until_element_stops(self, element, times=1000, timeout=None):
"""Search element and wait until it has stopped moving
:param element: PageElement or element locator as a tuple (locator_type, locator_value) to be found
:param times: number of iterations checking the element's location that must be the same for all of them
in order to considering the element has stopped
:returns: the web | python | {
"resource": ""
} |
q19601 | Utils.wait_until_element_contains_text | train | def wait_until_element_contains_text(self, element, text, timeout=None):
"""Search element and wait until it contains the expected text
:param element: PageElement or element locator as a tuple (locator_type, locator_value) to be found
:param text: text expected to be contained into the element
:param timeout: max time to wait
:returns: the web element if it contains the expected text
| python | {
"resource": ""
} |
q19602 | Utils.wait_until_element_not_contain_text | train | def wait_until_element_not_contain_text(self, element, text, timeout=None):
"""Search element and wait until it does not contain the expected text
:param element: PageElement or element locator as a tuple (locator_type, locator_value) to be found
:param text: text expected to be contained into the element
:param timeout: max time to wait
:returns: the web element if it does not contain the given | python | {
"resource": ""
} |
q19603 | Utils.wait_until_element_attribute_is | train | def wait_until_element_attribute_is(self, element, attribute, value, timeout=None):
"""Search element and wait until the requested attribute contains the expected value
:param element: PageElement or element locator as a tuple (locator_type, locator_value) to be found
:param attribute: attribute belonging to the element
:param value: expected value for the attribute of the element
:param timeout: max time to wait
:returns: the web element if | python | {
"resource": ""
} |
q19604 | Utils.get_remote_node | train | def get_remote_node(self):
"""Return the remote node that it's executing the actual test session
:returns: tuple with server type (local, grid, ggr, selenium) and remote node name
"""
logging.getLogger("requests").setLevel(logging.WARNING)
remote_node = None
server_type = 'local'
if self.driver_wrapper.config.getboolean_optional('Server', 'enabled'):
# Request session info from grid hub
session_id = self.driver_wrapper.driver.session_id
self.logger.debug("Trying to identify remote node")
try:
# Request session info from grid hub and extract remote node
url = '{}/grid/api/testsession?session={}'.format(self.get_server_url(),
session_id)
proxy_id = requests.get(url).json()['proxyId']
remote_node = urlparse(proxy_id).hostname if urlparse(proxy_id).hostname else proxy_id
server_type = 'grid'
self.logger.debug("Test running in remote node %s", remote_node)
except (ValueError, KeyError):
try:
# Request session info from GGR and extract remote node
from toolium.selenoid import Selenoid
remote_node = Selenoid(self.driver_wrapper).get_selenoid_info()['Name']
server_type = 'ggr'
self.logger.debug("Test running in a GGR remote node %s", remote_node)
except Exception:
try:
# The remote node is a Selenoid node
| python | {
"resource": ""
} |
q19605 | Utils.get_server_url | train | def get_server_url(self):
"""Return the configured server url
:returns: server url
"""
server_host = self.driver_wrapper.config.get('Server', 'host')
server_port = self.driver_wrapper.config.get('Server', 'port')
server_username = self.driver_wrapper.config.get_optional('Server', 'username')
server_password = self.driver_wrapper.config.get_optional('Server', 'password')
| python | {
"resource": ""
} |
q19606 | Utils.download_remote_video | train | def download_remote_video(self, remote_node, session_id, video_name):
"""Download the video recorded in the remote node during the specified test session and save it in videos folder
:param remote_node: remote node name
:param session_id: test session id
:param video_name: video name
"""
try:
video_url = self._get_remote_video_url(remote_node, session_id) | python | {
"resource": ""
} |
q19607 | Utils._get_remote_node_url | train | def _get_remote_node_url(self, remote_node):
"""Get grid-extras url of a node
:param remote_node: remote node name
:returns: grid-extras url
"""
| python | {
"resource": ""
} |
q19608 | Utils._get_remote_video_url | train | def _get_remote_video_url(self, remote_node, session_id):
"""Get grid-extras url to download videos
:param remote_node: remote node name
:param session_id: test session id
:returns: grid-extras url to download videos
"""
url = '{}/video'.format(self._get_remote_node_url(remote_node))
timeout = time.time() + 5 # 5 seconds from now
# Requests videos list until timeout or the video url is found
video_url = None
while time.time() < timeout:
| python | {
"resource": ""
} |
q19609 | Utils._download_video | train | def _download_video(self, video_url, video_name):
"""Download a video from the remote node
:param video_url: video url
:param video_name: video name
"""
filename = '{0:0=2d}_{1}'.format(DriverWrappersPool.videos_number, video_name)
filename = '{}.mp4'.format(get_valid_filename(filename))
| python | {
"resource": ""
} |
q19610 | Utils.is_remote_video_enabled | train | def is_remote_video_enabled(self, remote_node):
"""Check if the remote node has the video recorder enabled
:param remote_node: remote node name
:returns: true if it has the video recorder enabled
"""
enabled = False
if remote_node:
url = '{}/config'.format(self._get_remote_node_url(remote_node))
try:
response = requests.get(url, timeout=5).json()
record_videos = response['config_runtime']['theConfigMap']['video_recording_options'][
'record_test_videos']
| python | {
"resource": ""
} |
q19611 | Utils.get_center | train | def get_center(self, element):
"""Get center coordinates of an element
:param element: either a WebElement, PageElement or element locator as a tuple (locator_type, locator_value)
:returns: dict with center coordinates
"""
web_element = self.get_web_element(element)
| python | {
"resource": ""
} |
q19612 | Utils.get_safari_navigation_bar_height | train | def get_safari_navigation_bar_height(self):
"""Get the height of Safari navigation bar
:returns: height of navigation bar
"""
status_bar_height = 0
| python | {
"resource": ""
} |
q19613 | Utils.get_window_size | train | def get_window_size(self):
"""Generic method to get window size using a javascript workaround for Android web tests
:returns: dict with window width and height
"""
if not self._window_size:
if self.driver_wrapper.is_android_web_test() and self.driver_wrapper.driver.current_context != 'NATIVE_APP':
window_width = self.driver_wrapper.driver.execute_script("return window.innerWidth")
| python | {
"resource": ""
} |
q19614 | Utils.get_native_coords | train | def get_native_coords(self, coords):
"""Convert web coords into native coords. Assumes that the initial context is WEBVIEW and switches to
NATIVE_APP context.
:param coords: dict with web coords, e.g. {'x': 10, 'y': 10}
:returns: dict with native coords
"""
web_window_size = self.get_window_size()
self.driver_wrapper.driver.switch_to.context('NATIVE_APP')
native_window_size = self.driver_wrapper.driver.get_window_size()
scale = native_window_size['width'] / web_window_size['width']
| python | {
"resource": ""
} |
q19615 | Utils.swipe | train | def swipe(self, element, x, y, duration=None):
"""Swipe over an element
:param element: either a WebElement, PageElement or element locator as a tuple (locator_type, locator_value)
:param x: horizontal movement
:param y: vertical movement
:param duration: time to take the swipe, in ms
"""
if not self.driver_wrapper.is_mobile_test():
raise Exception('Swipe method is not implemented in Selenium')
# Get center coordinates of element
center = self.get_center(element)
initial_context = self.driver_wrapper.driver.current_context
if self.driver_wrapper.is_web_test() or initial_context != 'NATIVE_APP':
center = self.get_native_coords(center)
# Android needs absolute end coordinates and ios needs movement
| python | {
"resource": ""
} |
q19616 | Utils.get_web_element | train | def get_web_element(self, element):
"""Return the web element from a page element or its locator
:param element: either a WebElement, PageElement or element locator as a tuple (locator_type, locator_value)
:returns: WebElement object
"""
from toolium.pageelements.page_element import PageElement
if isinstance(element, WebElement):
web_element = element
| python | {
"resource": ""
} |
q19617 | Utils.get_first_webview_context | train | def get_first_webview_context(self):
"""Return the first WEBVIEW context or raise an exception if it is not found
:returns: first WEBVIEW context
| python | {
"resource": ""
} |
q19618 | DriverWrappersPool.capture_screenshots | train | def capture_screenshots(cls, name):
"""Capture a screenshot in each driver
:param name: screenshot name suffix
"""
screenshot_name = '{}_driver{}' if len(cls.driver_wrappers) > 1 else '{}'
driver_index = 1
for driver_wrapper in cls.driver_wrappers:
if not driver_wrapper.driver:
continue
from toolium.jira import add_attachment
try:
| python | {
"resource": ""
} |
q19619 | DriverWrappersPool.connect_default_driver_wrapper | train | def connect_default_driver_wrapper(cls, config_files=None):
"""Get default driver wrapper, configure it and connect driver
:param config_files: driver wrapper specific config files
:returns: default driver wrapper
:rtype: toolium.driver_wrapper.DriverWrapper
"""
driver_wrapper = cls.get_default_wrapper()
| python | {
"resource": ""
} |
q19620 | DriverWrappersPool.close_drivers | train | def close_drivers(cls, scope, test_name, test_passed=True, context=None):
"""Stop all drivers, capture screenshots, copy webdriver and GGR logs and download saved videos
:param scope: execution scope (function, module, class or session)
:param test_name: executed test name
:param test_passed: True if the test has passed
:param context: behave context
"""
if scope == 'function':
# Capture screenshot on error
if not test_passed:
cls.capture_screenshots(test_name)
# Execute behave dynamic environment
if context and hasattr(context, 'dyn_env'):
context.dyn_env.execute_after_scenario_steps(context)
| python | {
"resource": ""
} |
q19621 | DriverWrappersPool.stop_drivers | train | def stop_drivers(cls, maintain_default=False):
"""Stop all drivers except default if it should be reused
:param maintain_default: True if the default driver should not be closed
"""
# Exclude first wrapper if the driver must be reused
driver_wrappers = cls.driver_wrappers[1:] if maintain_default else cls.driver_wrappers
for driver_wrapper in driver_wrappers:
if not driver_wrapper.driver:
continue
try:
| python | {
"resource": ""
} |
q19622 | DriverWrappersPool.download_videos | train | def download_videos(cls, name, test_passed=True, maintain_default=False):
"""Download saved videos if video is enabled or if test fails
:param name: destination file name
:param test_passed: True if the test has passed
:param maintain_default: True if the default driver should not be closed
"""
# Exclude first wrapper if the driver must be reused
driver_wrappers = cls.driver_wrappers[1:] if maintain_default else cls.driver_wrappers
video_name = '{}_driver{}' if len(driver_wrappers) > 1 else '{}'
video_name = video_name if test_passed else 'error_{}'.format(video_name)
driver_index = 1
for driver_wrapper in driver_wrappers:
if not driver_wrapper.driver:
continue
try:
# Download video if necessary (error case or enabled video)
if (not test_passed or driver_wrapper.config.getboolean_optional('Server', 'video_enabled', False)) \
and driver_wrapper.remote_node_video_enabled:
if driver_wrapper.server_type in ['ggr', 'selenoid']:
name = get_valid_filename(video_name.format(name, driver_index))
| python | {
"resource": ""
} |
q19623 | DriverWrappersPool.save_all_webdriver_logs | train | def save_all_webdriver_logs(cls, test_name, test_passed):
"""Get all webdriver logs of each driver and write them to log files
:param test_name: test that has generated these logs
:param test_passed: True if the test has passed
"""
log_name = '{} [driver {}]' if len(cls.driver_wrappers) > 1 else '{}'
driver_index = 1
for driver_wrapper in cls.driver_wrappers:
if not driver_wrapper.driver or driver_wrapper.server_type in ['ggr', 'selenoid']:
continue
if driver_wrapper.config.getboolean_optional('Server', 'logs_enabled') or not test_passed:
try:
| python | {
"resource": ""
} |
q19624 | DriverWrappersPool.save_all_ggr_logs | train | def save_all_ggr_logs(cls, test_name, test_passed):
"""Get all GGR logs of each driver and write them to log files
:param test_name: test that has generated these logs
:param test_passed: True if the test has passed
"""
log_name = '{} [driver {}]' if len(cls.driver_wrappers) > 1 else '{}'
driver_index = 1
for driver_wrapper in cls.driver_wrappers:
if not driver_wrapper.driver or driver_wrapper.server_type not in ['ggr', 'selenoid']:
continue
try:
if driver_wrapper.config.getboolean_optional('Server', 'logs_enabled') or not test_passed:
| python | {
"resource": ""
} |
q19625 | DriverWrappersPool.get_configured_value | train | def get_configured_value(system_property_name, specific_value, default_value):
"""Get configured value from system properties, method parameters or default value
:param system_property_name: system property name
:param specific_value: test case specific value
:param default_value: default value
| python | {
"resource": ""
} |
q19626 | DriverWrappersPool.configure_common_directories | train | def configure_common_directories(cls, tc_config_files):
"""Configure common config and output folders for all tests
:param tc_config_files: test case specific config files
"""
if cls.config_directory is None:
# Get config directory from properties
config_directory = cls.get_configured_value('Config_directory', tc_config_files.config_directory, 'conf')
prop_filenames = cls.get_configured_value('Config_prop_filenames',
tc_config_files.config_properties_filenames, 'properties.cfg')
cls.config_directory = cls._find_parent_directory(config_directory, prop_filenames.split(';')[0])
# Get output directory from properties and create it
cls.output_directory = cls.get_configured_value('Output_directory', tc_config_files.output_directory,
'output')
if not os.path.isabs(cls.output_directory):
# If output directory is relative, we use the same path as config directory
cls.output_directory = os.path.join(os.path.dirname(cls.config_directory), cls.output_directory)
if not os.path.exists(cls.output_directory):
| python | {
"resource": ""
} |
q19627 | DriverWrappersPool.get_default_config_directory | train | def get_default_config_directory():
"""Return default config directory, based in the actual test path
:returns: default config directory
"""
| python | {
"resource": ""
} |
q19628 | DriverWrappersPool._find_parent_directory | train | def _find_parent_directory(directory, filename):
"""Find a directory in parent tree with a specific filename
:param directory: directory name to find
:param filename: filename to find
:returns: absolute directory path
"""
parent_directory = directory
absolute_directory = '.'
while absolute_directory != os.path.abspath(parent_directory):
absolute_directory = os.path.abspath(parent_directory)
if os.path.isfile(os.path.join(absolute_directory, filename)):
return absolute_directory
if os.path.isabs(parent_directory):
| python | {
"resource": ""
} |
q19629 | DriverWrappersPool.configure_visual_directories | train | def configure_visual_directories(cls, driver_info):
"""Configure screenshots, videos and visual directories
:param driver_info: driver property value to name folders
"""
if cls.screenshots_directory is None:
# Unique screenshots and videos directories
date = datetime.datetime.now().strftime('%Y-%m-%d_%H%M%S')
folder_name = '%s_%s' % (date, driver_info) if driver_info else date | python | {
"resource": ""
} |
q19630 | DriverWrappersPool.initialize_config_files | train | def initialize_config_files(tc_config_files=None):
"""Initialize config files and update config files names with the environment
:param tc_config_files: test case specific config files
:returns: initialized config files object
"""
# Initialize config files
if tc_config_files is None:
tc_config_files = ConfigFiles()
# Update properties and log file names if an environment is configured
env = DriverWrappersPool.get_configured_value('Config_environment', None, None)
if env:
# Update config properties filenames
prop_filenames = tc_config_files.config_properties_filenames
new_prop_filenames_list = prop_filenames.split(';') if prop_filenames else ['properties.cfg']
base, ext = os.path.splitext(new_prop_filenames_list[0])
new_prop_filenames_list.append('{}-{}{}'.format(env, base, ext))
| python | {
"resource": ""
} |
q19631 | before_all | train | def before_all(context):
"""Initialization method that will be executed before the test execution
:param context: behave context
"""
# Use pytest asserts if behave_pytest is installed
install_pytest_asserts()
# Get 'Config_environment' property from user input (e.g. -D Config_environment=ios)
env = context.config.userdata.get('Config_environment')
# Deprecated: Get 'env' property from user input (e.g. -D env=ios)
env = env if env else context.config.userdata.get('env')
if env:
os.environ['Config_environment'] = env
if not hasattr(context, 'config_files'):
| python | {
"resource": ""
} |
q19632 | bdd_common_before_scenario | train | def bdd_common_before_scenario(context_or_world, scenario, no_driver=False):
"""Common scenario initialization in behave or lettuce
:param context_or_world: behave context or lettuce world
:param scenario: running scenario
:param no_driver: True if this is an api test and driver should not be started
"""
# Initialize and connect driver wrapper
start_driver(context_or_world, no_driver)
| python | {
"resource": ""
} |
q19633 | create_and_configure_wrapper | train | def create_and_configure_wrapper(context_or_world):
"""Create and configure driver wrapper in behave or lettuce tests
:param context_or_world: behave context or lettuce world
"""
# Create default driver wrapper
context_or_world.driver_wrapper = DriverWrappersPool.get_default_wrapper()
context_or_world.utils = context_or_world.driver_wrapper.utils
# Get behave userdata properties to override config properties
try:
behave_properties = context_or_world.config.userdata
except AttributeError: | python | {
"resource": ""
} |
q19634 | connect_wrapper | train | def connect_wrapper(context_or_world):
"""Connect driver in behave or lettuce tests
:param context_or_world: behave context or lettuce world
"""
# Create driver if it is not already created
if context_or_world.driver_wrapper.driver:
context_or_world.driver = context_or_world.driver_wrapper.driver
| python | {
"resource": ""
} |
q19635 | add_assert_screenshot_methods | train | def add_assert_screenshot_methods(context_or_world, scenario):
"""Add assert screenshot methods to behave or lettuce object
:param context_or_world: behave context or lettuce world
:param scenario: running scenario
"""
file_suffix = scenario.name
def assert_screenshot(element_or_selector, filename, threshold=0, exclude_elements=[], driver_wrapper=None,
force=False):
VisualTest(driver_wrapper, force).assert_screenshot(element_or_selector, filename, file_suffix, threshold,
exclude_elements)
def assert_full_screenshot(filename, threshold=0, exclude_elements=[], driver_wrapper=None, force=False):
VisualTest(driver_wrapper, force).assert_screenshot(None, filename, file_suffix, threshold, exclude_elements)
# Monkey patching assert_screenshot method in PageElement to use the correct test name
def assert_screenshot_page_element(self, filename, | python | {
"resource": ""
} |
q19636 | bdd_common_after_scenario | train | def bdd_common_after_scenario(context_or_world, scenario, status):
"""Clean method that will be executed after each scenario in behave or lettuce
:param context_or_world: behave context or lettuce world
:param scenario: running scenario
:param status: scenario status (passed, failed or skipped)
"""
if status == 'skipped':
return
elif status == 'passed':
test_status = 'Pass'
test_comment = None
| python | {
"resource": ""
} |
q19637 | after_feature | train | def after_feature(context, feature):
"""Clean method that will be executed after each feature
:param context: behave context
:param feature: running feature
"""
# Behave dynamic environment
context.dyn_env.execute_after_feature_steps(context)
# Close drivers | python | {
"resource": ""
} |
q19638 | bdd_common_after_all | train | def bdd_common_after_all(context_or_world):
"""Common after all method in behave or lettuce
:param context_or_world: behave context or lettuce world
"""
# Close drivers
DriverWrappersPool.close_drivers(scope='session', test_name='multiple_tests',
| python | {
"resource": ""
} |
q19639 | DriverWrapper.configure_logger | train | def configure_logger(self, tc_config_log_filename=None, tc_output_log_filename=None):
"""Configure selenium instance logger
:param tc_config_log_filename: test case specific logging config file
:param tc_output_log_filename: test case specific output logger file
"""
# Get config logger filename
config_log_filename = DriverWrappersPool.get_configured_value('Config_log_filename', tc_config_log_filename,
'logging.conf')
config_log_filename = os.path.join(DriverWrappersPool.config_directory, config_log_filename)
# Configure logger only if logging filename has changed
if self.config_log_filename != config_log_filename:
# Get output logger filename
output_log_filename = DriverWrappersPool.get_configured_value('Output_log_filename', tc_output_log_filename,
'toolium.log')
output_log_filename = os.path.join(DriverWrappersPool.output_directory, output_log_filename)
| python | {
"resource": ""
} |
q19640 | DriverWrapper.configure_properties | train | def configure_properties(self, tc_config_prop_filenames=None, behave_properties=None):
"""Configure selenium instance properties
:param tc_config_prop_filenames: test case specific properties filenames
:param behave_properties: dict with behave user data properties
"""
prop_filenames = DriverWrappersPool.get_configured_value('Config_prop_filenames', tc_config_prop_filenames,
'properties.cfg;local-properties.cfg')
prop_filenames = [os.path.join(DriverWrappersPool.config_directory, filename) for filename in
prop_filenames.split(';')]
prop_filenames = ';'.join(prop_filenames)
# Configure config only if properties filename has changed
| python | {
"resource": ""
} |
q19641 | DriverWrapper.configure_visual_baseline | train | def configure_visual_baseline(self):
"""Configure baseline directory"""
# Get baseline name
baseline_name = self.config.get_optional('VisualTests', 'baseline_name', '{Driver_type}')
for section in self.config.sections():
for option in self.config.options(section):
option_value = self.config.get(section, option)
baseline_name = baseline_name.replace('{{{0}_{1}}}'.format(section, option), option_value)
# Configure baseline | python | {
"resource": ""
} |
q19642 | DriverWrapper.update_visual_baseline | train | def update_visual_baseline(self):
"""Configure baseline directory after driver is created"""
# Update baseline with real platformVersion value
if '{PlatformVersion}' in self.baseline_name:
try:
platform_version = self.driver.desired_capabilities['platformVersion']
except KeyError:
platform_version = None
self.baseline_name = self.baseline_name.replace('{PlatformVersion}', str(platform_version))
self.visual_baseline_directory = os.path.join(DriverWrappersPool.visual_baseline_directory,
self.baseline_name)
| python | {
"resource": ""
} |
q19643 | DriverWrapper.configure | train | def configure(self, tc_config_files, is_selenium_test=True, behave_properties=None):
"""Configure initial selenium instance using logging and properties files for Selenium or Appium tests
:param tc_config_files: test case specific config files
:param is_selenium_test: true if test is a selenium or appium test case
:param behave_properties: dict with behave user data properties
"""
| python | {
"resource": ""
} |
q19644 | DriverWrapper.connect | train | def connect(self, maximize=True):
"""Set up the selenium driver and connect to the server
:param maximize: True if the driver should be maximized
:returns: selenium driver
"""
if not self.config.get('Driver', 'type') or self.config.get('Driver', 'type') in ['api', 'no_driver']:
return None
self.driver = ConfigDriver(self.config, self.utils).create_driver()
# Save session id and remote node to download video after the test execution
self.session_id = self.driver.session_id
self.server_type, self.remote_node = self.utils.get_remote_node()
if self.server_type == 'grid':
self.remote_node_video_enabled = self.utils.is_remote_video_enabled(self.remote_node)
else:
self.remote_node_video_enabled = True if self.server_type in ['ggr', 'selenoid'] else False
# Save app_strings in mobile tests
if self.is_mobile_test() and not self.is_web_test() and self.config.getboolean_optional('Driver',
| python | {
"resource": ""
} |
q19645 | DriverWrapper.get_config_window_bounds | train | def get_config_window_bounds(self):
"""Reads bounds from config and, if monitor is specified, modify the values to match with the specified monitor
:return: coords X and Y where set the browser window.
"""
bounds_x = int(self.config.get_optional('Driver', 'bounds_x') or 0)
bounds_y = int(self.config.get_optional('Driver', 'bounds_y') or 0)
monitor_index = int(self.config.get_optional('Driver', 'monitor') or -1)
if monitor_index > -1:
| python | {
"resource": ""
} |
q19646 | DriverWrapper.should_reuse_driver | train | def should_reuse_driver(self, scope, test_passed, context=None):
"""Check if the driver should be reused
:param scope: execution scope (function, module, class or session)
:param test_passed: True if the test has passed
:param context: behave context
:returns: True if the driver should be reused
"""
reuse_driver = self.config.getboolean_optional('Driver', 'reuse_driver')
reuse_driver_session = self.config.getboolean_optional('Driver', 'reuse_driver_session')
restart_driver_after_failure = (self.config.getboolean_optional('Driver', 'restart_driver_after_failure') or
self.config.getboolean_optional('Driver', 'restart_driver_fail'))
if context and scope == 'function':
| python | {
"resource": ""
} |
q19647 | get_long_description | train | def get_long_description():
"""Get README content and update rst urls
:returns: long description
"""
# Get readme content
readme = read_file('README.rst')
# Change rst urls to ReadTheDocs html urls
docs_url = 'http://toolium.readthedocs.org/en/latest'
| python | {
"resource": ""
} |
q19648 | jira | train | def jira(test_key):
"""Decorator to update test status in Jira
:param test_key: test case key in Jira
:returns: jira test
"""
def decorator(test_item):
def modified_test(*args, **kwargs):
save_jira_conf()
try:
test_item(*args, **kwargs)
except Exception as e:
error_message = get_error_message_from_exception(e)
test_comment = "The test '{}' has failed: {}".format(args[0].get_method_name(), error_message)
| python | {
"resource": ""
} |
q19649 | save_jira_conf | train | def save_jira_conf():
"""Read Jira configuration from properties file and save it"""
global enabled, execution_url, summary_prefix, labels, comments, fix_version, build, only_if_changes, attachments
config = DriverWrappersPool.get_default_wrapper().config
enabled = config.getboolean_optional('Jira', 'enabled')
| python | {
"resource": ""
} |
q19650 | add_jira_status | train | def add_jira_status(test_key, test_status, test_comment):
"""Save test status and comments to update Jira later
:param test_key: test case key in Jira
:param test_status: test case status
:param test_comment: test case comments
"""
global attachments
if test_key and enabled:
if test_key in jira_tests_status:
# Merge data with previous test status
previous_status = jira_tests_status[test_key]
test_status = 'Pass' if previous_status[1] == 'Pass' and test_status == 'Pass' else 'Fail'
if previous_status[2] and test_comment:
| python | {
"resource": ""
} |
q19651 | change_jira_status | train | def change_jira_status(test_key, test_status, test_comment, test_attachments):
"""Update test status in Jira
:param test_key: test case key in Jira
:param test_status: test case status
:param test_comment: test case comments
:param test_attachments: test case attachments
"""
logger = logging.getLogger(__name__)
if not execution_url:
logger.warning("Test Case '%s' can not be updated: execution_url is not configured", test_key)
return
logger.info("Updating Test Case '%s' in Jira with status %s", test_key, test_status)
composed_comments = comments
if test_comment:
composed_comments = '{}\n{}'.format(comments, test_comment) if comments else test_comment
payload = {'jiraTestCaseId': test_key, 'jiraStatus': test_status, 'summaryPrefix': summary_prefix,
'labels': labels, 'comments': composed_comments, 'version': fix_version, 'build': build}
if only_if_changes:
payload['onlyIfStatusChanges'] = 'true'
try:
if test_attachments and len(test_attachments) > | python | {
"resource": ""
} |
q19652 | get_error_message | train | def get_error_message(response_content):
"""Extract error message from the HTTP response
:param response_content: HTTP response from test case execution API
:returns: error message
"""
apache_regex = re.compile('.*<u>(.*)</u></p><p>.*')
match = apache_regex.search(response_content)
if match:
error_message = match.group(1)
else:
| python | {
"resource": ""
} |
q19653 | Button.click | train | def click(self):
"""Click the element
:returns: page element instance
"""
try:
self.wait_until_clickable().web_element.click()
except | python | {
"resource": ""
} |
q19654 | PageObject._get_page_elements | train | def _get_page_elements(self):
"""Return page elements and page objects of this page object
:returns: list of page elements and page objects
"""
page_elements = []
for attribute, value in list(self.__dict__.items()) + list(self.__class__.__dict__.items()):
| python | {
"resource": ""
} |
q19655 | PageObject.wait_until_loaded | train | def wait_until_loaded(self, timeout=None):
"""Wait until page object is loaded
Search all page elements configured with wait=True
:param timeout: max time to wait
:returns: this page object instance
"""
for element in self._get_page_elements():
if hasattr(element, 'wait') and element.wait:
from toolium.pageelements.page_element import PageElement
if isinstance(element, PageElement):
# Pageelement and | python | {
"resource": ""
} |
q19656 | ExtendedConfigParser.get_optional | train | def get_optional(self, section, option, default=None):
""" Get an option value for a given section
If the section or the option are not found, the default value is returned
:param section: config section
:param option: config option
:param default: default value
:returns: | python | {
"resource": ""
} |
q19657 | ExtendedConfigParser.getboolean_optional | train | def getboolean_optional(self, section, option, default=False):
""" Get an option boolean value for a given section
If the section or the option are not found, the default value is returned
:param section: config section
:param option: config option
:param default: default value
:returns: | python | {
"resource": ""
} |
q19658 | ExtendedConfigParser.deepcopy | train | def deepcopy(self):
"""Returns a deep copy of config object
:returns: a copy of the config object
"""
# Save actual config to a string
config_string = StringIO()
self.write(config_string)
# We must reset the buffer ready for reading.
| python | {
"resource": ""
} |
q19659 | ExtendedConfigParser.update_properties | train | def update_properties(self, new_properties):
""" Update config properties values
Property name must be equal to 'Section_option' of config property
| python | {
"resource": ""
} |
q19660 | ExtendedConfigParser._update_property_from_dict | train | def _update_property_from_dict(self, section, option, new_properties):
""" Update a config property value with a new property value
Property name must be equal to 'Section_option' of config property
:param section: config section
:param option: config option
:param new_properties: dict with new properties values
| python | {
"resource": ""
} |
q19661 | ExtendedConfigParser.get_config_from_file | train | def get_config_from_file(conf_properties_files):
"""Reads properties files and saves them to a config object
:param conf_properties_files: comma-separated list of properties files
:returns: config object
"""
# Initialize the config object
config = ExtendedConfigParser()
logger = logging.getLogger(__name__)
# Configure properties (last files could override properties)
found = False
files_list = conf_properties_files.split(';')
for conf_properties_file in files_list:
| python | {
"resource": ""
} |
q19662 | PageElements.web_elements | train | def web_elements(self):
"""Find multiple WebElements using element locator
:returns: list of web element objects
:rtype: list of selenium.webdriver.remote.webelement.WebElement
or list of appium.webdriver.webelement.WebElement
"""
if not self._web_elements or not self.config.getboolean_optional('Driver', 'save_web_element'):
| python | {
"resource": ""
} |
q19663 | PageElements.page_elements | train | def page_elements(self):
"""Find multiple PageElement using element locator
:returns: list of page element objects
:rtype: list of toolium.pageelements.PageElement
"""
if not self._page_elements or not self.config.getboolean_optional('Driver', 'save_web_element'):
self._page_elements = []
| python | {
"resource": ""
} |
q19664 | PageElement.web_element | train | def web_element(self):
"""Find WebElement using element locator
:returns: web element object
:rtype: selenium.webdriver.remote.webelement.WebElement or appium.webdriver.webelement.WebElement
"""
try:
self._find_web_element()
except NoSuchElementException as exception:
parent_msg = " and parent locator '{}'".format(self.parent) if self.parent else ''
| python | {
"resource": ""
} |
q19665 | PageElement._find_web_element | train | def _find_web_element(self):
"""Find WebElement using element locator and save it in _web_element attribute"""
if not self._web_element or not self.config.getboolean_optional('Driver', 'save_web_element'):
# If the element is encapsulated we use the shadowroot tag in yaml (eg. Shadowroot: root_element_name)
if self.shadowroot:
if self.locator[0] != By.CSS_SELECTOR:
raise Exception('Locator type should be CSS_SELECTOR using shadowroot but found: '
'%s'.format(self.locator[0]))
# querySelector only support CSS SELECTOR locator
self._web_element = self.driver.execute_script('return document.querySelector("%s").shadowRoot.'
'querySelector("%s")' % (self.shadowroot,
| python | {
"resource": ""
} |
q19666 | PageElement.scroll_element_into_view | train | def scroll_element_into_view(self):
"""Scroll element into view
:returns: page element instance
"""
x = self.web_element.location['x']
| python | {
"resource": ""
} |
q19667 | PageElement.assert_screenshot | train | def assert_screenshot(self, filename, threshold=0, exclude_elements=[], force=False):
"""Assert that a screenshot of the element is the same as a screenshot on disk, within a given threshold.
:param filename: the filename for the screenshot, which will be appended with ``.png``
:param threshold: percentage threshold for triggering a test failure (value between 0 and 1)
:param exclude_elements: list of WebElements, PageElements or element locators as a tuple (locator_type,
locator_value) that must be excluded from the assertion
| python | {
"resource": ""
} |
q19668 | InputText.text | train | def text(self, value):
"""Set value on the element
:param value: value to be set
"""
if self.driver_wrapper.is_ios_test() and not self.driver_wrapper.is_web_test():
self.web_element.set_value(value)
| python | {
"resource": ""
} |
q19669 | install_documentation | train | def install_documentation(path="./Litho1pt0-Notebooks"):
"""Install the example notebooks for litho1pt0 in the given location
WARNING: If the path exists, the Notebook files will be written into the path
and will overwrite any existing files with which they collide. The default
path ("./Litho1pt0-Notebooks") is chosen to make collision less likely / problematic
The documentation for litho1pt0 is in the form of jupyter notebooks.
Some dependencies exist for the notebooks to be useful:
- matplotlib: for some diagrams
- cartopy: for plotting map examples
litho1pt0 dependencies are explicitly imported into the notebooks including:
- stripy (for interpolating on the sphere)
| python | {
"resource": ""
} |
q19670 | remove_duplicates | train | def remove_duplicates(vector_tuple):
"""
Remove duplicates rows from N equally-sized arrays
"""
array = np.column_stack(vector_tuple)
a = np.ascontiguousarray(array)
| python | {
"resource": ""
} |
q19671 | Triangulation._is_collinear | train | def _is_collinear(self, x, y):
"""
Checks if first three points are collinear
"""
| python | {
"resource": ""
} |
q19672 | Triangulation._deshuffle_field | train | def _deshuffle_field(self, *args):
"""
Return to original ordering
"""
ip = self._invpermutation
fields = []
for arg in args:
| python | {
"resource": ""
} |
q19673 | Triangulation.gradient | train | def gradient(self, f, nit=3, tol=1e-3, guarantee_convergence=False):
"""
Return the gradient of an n-dimensional array.
The method consists of minimizing a quadratic functional Q(G) over
gradient vectors (in x and y directions), where Q is an approximation
to the linearized curvature over the triangulation of a C-1 bivariate
function F(x,y) which interpolates the nodal values and gradients.
Parameters
----------
f : array of floats, shape (n,)
field over which to evaluate the gradient
nit: int (default: 3)
number of iterations to reach a convergence tolerance, tol
nit >= 1
tol: float (default: 1e-3)
maximum change in gradient between iterations.
convergence is reached when this condition is met.
Returns
-------
dfdx : array of floats, shape (n,)
derivative of f in the x direction
dfdy : array of floats, shape (n,)
derivative of f in the y direction
Notes
-----
For SIGMA = 0, optimal efficiency was achieved in testing with
tol = 0, and nit = 3 or 4.
The restriction of F to an arc of the triangulation is taken to be
the Hermite interpolatory tension spline defined by the data values
and tangential | python | {
"resource": ""
} |
q19674 | Triangulation.gradient_local | train | def gradient_local(self, f, index):
"""
Return the gradient at a specified node.
This routine employs a local method, in which values depend only on nearby
data points, to compute an estimated gradient at a node.
gradient_local() is more efficient than gradient() only if it is unnecessary
to compute gradients at all of the nodes. Both routines have similar accuracy.
Parameters
----------
"""
if f.size != self.npoints:
| python | {
"resource": ""
} |
q19675 | Triangulation.interpolate | train | def interpolate(self, xi, yi, zdata, order=1):
"""
Base class to handle nearest neighbour, linear, and cubic interpolation.
Given a triangulation of a set of nodes and values at the nodes,
this method interpolates the value at the given xi,yi coordinates.
Parameters
----------
xi : float / array of floats, shape (l,)
x Cartesian coordinate(s)
yi : float / array of floats, shape (l,)
y Cartesian coordinate(s)
zdata : array of floats, shape (n,)
value at each point in the triangulation
must be the same size of the mesh
order : int (default=1)
order of the interpolatory function used
0 = nearest-neighbour
1 = linear
3 = cubic
Returns
-------
| python | {
"resource": ""
} |
q19676 | Triangulation.interpolate_nearest | train | def interpolate_nearest(self, xi, yi, zdata):
"""
Nearest-neighbour interpolation.
Calls nearnd to find the index of the closest neighbours to xi,yi
Parameters
----------
xi : float / array of floats, shape (l,)
x coordinates on the Cartesian plane
yi : float / array of floats, shape (l,)
y coordinates on the Cartesian plane
Returns
-------
zi : float / array of floats, shape (l,)
nearest-neighbour interpolated value(s) of (xi,yi)
"""
| python | {
"resource": ""
} |
q19677 | Triangulation.containing_triangle | train | def containing_triangle(self, xi, yi):
"""
Returns indices of the triangles containing xi yi
Parameters
----------
xi : float / array of floats, shape (l,)
Cartesian coordinates in the x direction
yi : float / array of floats, shape (l,)
Cartesian coordinates in the y direction
Returns
-------
tri_indices: array of ints, shape (l,)
Notes
-----
The simplices are found as cartesian.Triangulation.simplices[tri_indices]
"""
p = self._permutation
pts = np.column_stack([xi, yi])
| python | {
"resource": ""
} |
q19678 | Triangulation.identify_vertex_neighbours | train | def identify_vertex_neighbours(self, vertex):
"""
Find the neighbour-vertices in the triangulation for the given vertex
Searches self.simplices for vertex entries and sorts neighbours
"""
simplices = self.simplices
ridx, cidx = np.where(simplices == | python | {
"resource": ""
} |
q19679 | Triangulation.identify_vertex_triangles | train | def identify_vertex_triangles(self, vertices):
"""
Find all triangles which own any of the vertices in the list provided
"""
triangles = []
for vertex in np.array(vertices).reshape(-1):
| python | {
"resource": ""
} |
q19680 | Triangulation.convex_hull | train | def convex_hull(self):
"""
Find the Convex Hull of the internal set of x,y points.
Returns
-------
bnodes : array of ints
indices corresponding to points on the convex hull
"""
| python | {
"resource": ""
} |
q19681 | Triangulation.areas | train | def areas(self):
"""
Compute the area of each triangle within the triangulation of points.
Returns
-------
area : array of floats, shape (nt,)
area of each triangle in self.simplices where nt
is the number of triangles.
"""
| python | {
"resource": ""
} |
q19682 | Triangulation.join | train | def join(self, t2, unique=False):
"""
Join this triangulation with another. If the points are known to have no duplicates, then
set unique=False to skip the testing and duplicate removal
"""
x_v1 = np.concatenate((self.x, t2.x), axis=0)
y_v1 = np.concatenate((self.y, t2.y), axis=0)
## remove any duplicates
if not unique:
| python | {
"resource": ""
} |
q19683 | write_processed_litho_data | train | def write_processed_litho_data(filename, litho_data, litho_points):
"""
Ensures that the data is stored in a format which is valid for initialising the class
"""
| python | {
"resource": ""
} |
q19684 | weighted_average_to_nodes | train | def weighted_average_to_nodes(x1, x2, data, interpolator ):
""" Weighted average of scattered data to the nodal points
of a triangulation using the barycentric coordinates as
weightings.
Parameters
----------
x1, x2 : 1D arrays arrays of x,y or lon, lat (radians)
data : 1D array of data to be lumped to the node locations
interpolator : a stripy.Triangulation or stripy.sTriangulation object
which defines the node locations and their triangulation
Returns
-------
grid : 1D array containing the results of the weighted average
norm : 1D array of the normalisation used to compute `grid`
count : 1D int array of number of points that contribute anything to a given node
"""
import numpy as np
gridded_data = np.zeros(interpolator.npoints)
norm = np.zeros(interpolator.npoints)
count | python | {
"resource": ""
} |
q19685 | great_circle_Npoints | train | def great_circle_Npoints(lonlat1r, lonlat2r, N):
"""
N points along the line joining lonlat1 and lonlat2
"""
ratio = np.linspace(0.0,1.0, N).reshape(-1,1)
xyz1 = lonlat2xyz(lonlat1r[0], lonlat1r[1])
xyz2 = lonlat2xyz(lonlat2r[0], lonlat2r[1])
mids = ratio * | python | {
"resource": ""
} |
q19686 | sTriangulation._generate_permutation | train | def _generate_permutation(self, npoints):
"""
Create shuffle and deshuffle vectors
"""
i = np.arange(0, npoints)
# permutation
| python | {
"resource": ""
} |
q19687 | sTriangulation._is_collinear | train | def _is_collinear(self, lons, lats):
"""
Checks if first three points are collinear - in the spherical
case this corresponds to all points lying on a great circle
and, hence, all coordinate vectors being in a single plane.
"""
| python | {
"resource": ""
} |
q19688 | sTriangulation.gradient_xyz | train | def gradient_xyz(self, f, nit=3, tol=1e-3, guarantee_convergence=False):
"""
Return the cartesian components of the gradient
of a scalar field on the surface of the sphere.
The method consists of minimizing a quadratic functional Q(G) over
gradient vectors, where Q is an approximation to the linearized
curvature over the triangulation of a C-1 bivariate function F(x,y)
which interpolates the nodal values and gradients.
Parameters
----------
f : array of floats, shape (n,)
field over which to evaluate the gradient
nit: int (default: 3)
number of iterations to reach a convergence tolerance, tol
nit >= 1
tol: float (default: 1e-3)
maximum change in gradient between iterations.
convergence is reached when this condition is met.
Returns
-------
dfdx : array of floats, shape (n,)
derivative of f in the x direction
dfdy : array of floats, shape (n,)
derivative of f in the y direction
dfdz : array of floats, shape (n,)
derivative of f in the z direction
Notes
-----
For SIGMA = 0, optimal efficiency was achieved in testing with
tol = 0, and nit = 3 or 4.
The restriction of F to an arc of the triangulation is taken to be
| python | {
"resource": ""
} |
q19689 | sTriangulation.tri_area | train | def tri_area(self, lons, lats):
"""
Calculate the area enclosed by 3 points on the unit sphere.
Parameters
----------
lons : array of floats, shape (3)
longitudinal coordinates in radians
lats : array of floats, shape (3)
latitudinal coordinates in radians
Returns
-------
area : float
area of triangle on the unit sphere
| python | {
"resource": ""
} |
q19690 | sTriangulation.areas | train | def areas(self):
"""
Compute the area each triangle within the triangulation of points
on the unit sphere.
Returns
-------
area : array of floats, shape (nt,)
| python | {
"resource": ""
} |
q19691 | sTriangulation.join | train | def join(self, t2, unique=False):
"""
Join this triangulation with another. If the points are known to have no duplicates, then
set unique=True to skip the testing and duplicate removal
"""
lonv1 = np.concatenate((self.lons, t2.lons), axis=0)
latv1 = np.concatenate((self.lats, t2.lats), | python | {
"resource": ""
} |
q19692 | SalesforceBulk.get_query_batch_request | train | def get_query_batch_request(self, batch_id, job_id=None):
""" Fetch the request sent for the batch. Note should only used for query batches """
if not job_id:
job_id = self.lookup_job_id(batch_id)
| python | {
"resource": ""
} |
q19693 | SalesforceBulk.abort_job | train | def abort_job(self, job_id):
"""Abort a given bulk job"""
doc = self.create_abort_job_doc()
url = self.endpoint + "/job/%s" % job_id
resp = requests.post(
url,
| python | {
"resource": ""
} |
q19694 | SalesforceBulk.get_all_results_for_query_batch | train | def get_all_results_for_query_batch(self, batch_id, job_id=None, chunk_size=2048):
"""
Gets result ids and generates each result set from the batch and returns it
as an generator fetching the next result set when needed
Args:
batch_id: id of batch
job_id: id of job, if not provided, it will be looked up
"""
result_ids = self.get_query_batch_result_ids(batch_id, job_id=job_id)
| python | {
"resource": ""
} |
q19695 | MatchApiV4.matchlist_by_account | train | def matchlist_by_account(
self,
region,
encrypted_account_id,
queue=None,
begin_time=None,
end_time=None,
begin_index=None,
end_index=None,
season=None,
champion=None,
):
"""
Get matchlist for ranked games played on given account ID and platform ID
and filtered using given filter parameters, if any
A number of optional parameters are provided for filtering. It is up to the caller to
ensure that the combination of filter parameters provided is valid for the requested
account, otherwise, no matches may be returned.
Note that if either beginIndex or endIndex are specified, then both must be specified and
endIndex must be greater than beginIndex.
If endTime is specified, but not beginTime, then beginTime is effectively the start of the
account's match history.
If beginTime is specified, but not endTime, then endTime is effectively the current time.
Note that endTime should be greater than beginTime if both are specified, although there is
no maximum limit on their range.
:param string region: The region to execute this request on
:param string encrypted_account_id: The account ID.
:param Set[int] queue: Set of queue IDs for which to filtering matchlist.
:param long begin_time: The begin time to use for filtering matchlist specified as
epoch milliseconds.
:param long end_time: The end time to use for filtering matchlist specified as epoch
milliseconds.
:param int begin_index: The begin | python | {
"resource": ""
} |
q19696 | MatchApiV4.timeline_by_match | train | def timeline_by_match(self, region, match_id):
"""
Get match timeline by match ID.
Not all matches have timeline data.
:param string region: The region to execute this request on
:param long match_id: The match ID.
:returns: MatchTimelineDto
| python | {
"resource": ""
} |
q19697 | RateLimitHandler.after_request | train | def after_request(self, region, endpoint_name, method_name, url, response):
"""
Called after a response is received and before it is returned to the user.
:param string region: the region of this request
:param string endpoint_name: the name of the endpoint that was requested
:param string method_name: the name of the method that was requested
:param url: The | python | {
"resource": ""
} |
q19698 | LolStatusApiV3.shard_data | train | def shard_data(self, region):
"""
Get League of Legends status for the given shard.
Requests to this API are not counted against the application Rate Limits.
:param string region: the region to execute this request on
:returns: ShardStatus
| python | {
"resource": ""
} |
q19699 | ChampionMasteryApiV4.by_summoner_by_champion | train | def by_summoner_by_champion(self, region, encrypted_summoner_id, champion_id):
"""
Get a champion mastery by player ID and champion ID.
:param string region: the region to execute this request on
:param string encrypted_summoner_id: Summoner ID associated with the player
:param long champion_id: Champion ID to retrieve Champion Mastery for
:returns: ChampionMasteryDTO: This object contains single Champion Mastery information for
| python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.