How to use add_assert_screenshot_methods method in toolium

Best Python code snippet using toolium_python

env_utils.py

Source:env_utils.py Github

copy

Full Screen

...207def utils_before_scenario(context, scenario):208 configure_properties_from_tags(context, scenario)209 no_driver = 'no_driver' in scenario.tags or 'no_driver' in scenario.feature.tags210 start_driver(context, no_driver)211 add_assert_screenshot_methods(context, scenario)212 context.logger.info(f"Running new scenario: {scenario.name}")213 context.pytalos.dyn_env.execute_before_scenario_steps(context)214def utils_after_scenario(context, scenario, status):215 if status == 'skipped':216 return217 elif status == 'passed':218 context.logger.info(f"The scenario {scenario.name} has passed")219 else:220 context.logger.error(f"The scenario {scenario.name} has failed")221 context.pytalos.global_status['test_passed'] = False222 DriverManager.close_drivers(223 scope='function',224 test_name=scenario.name,225 test_passed=status == 'passed',226 context=context227 )228def utils_after_feature(context, feature):229 context.pytalos.dyn_env.execute_after_feature_steps(context)230 DriverManager.close_drivers(231 scope='module',232 test_name=feature.name,233 test_passed=context.pytalos.global_status['test_passed']234 )235def utils_after_all(context):236 DriverManager.close_drivers(237 scope='session',238 test_name='multiple_tests',239 test_passed=context.pytalos.global_status['test_passed']240 )241def create_wrapper(context):242 context.pytalos.driver_wrapper = DriverManager.get_default_wrapper()243 context.utils = context.pytalos.driver_wrapper.utils244 try:245 behave_properties = context.config.userdata246 except AttributeError:247 behave_properties = None248 context.pytalos.driver_wrapper.configure(context.pytalos.config_files, behave_properties=behave_properties)249 context.pytalos_config = context.pytalos.driver_wrapper.config250 context.logger = logging.getLogger(__name__)251def connect_wrapper(context):252 if context.pytalos.driver_wrapper.driver:253 context.driver = context.pytalos.driver_wrapper.driver254 else:255 context.driver = context.pytalos.driver_wrapper.connect()256 context.pytalos.app_strings = context.pytalos.driver_wrapper.app_strings257def start_driver(context, no_driver):258 create_wrapper(context)259 if not no_driver:260 connect_wrapper(context)261def add_assert_screenshot_methods(context, scenario):262 file_suffix = scenario.name263 def assert_screenshot(element_or_selector, filename, threshold=0, exclude_elements=None, driver_wrapper=None,264 force=False):265 if exclude_elements is None:266 exclude_elements = []267 VisualTest(driver_wrapper, force).assert_screenshot(element_or_selector,268 filename,269 file_suffix,270 threshold,271 exclude_elements)272 def assert_full_screenshot(filename, threshold=0, exclude_elements=None, driver_wrapper=None, force=False):273 if exclude_elements is None:274 exclude_elements = []275 VisualTest(driver_wrapper, force).assert_screenshot(None,...

Full Screen

Full Screen

environment.py

Source:environment.py Github

copy

Full Screen

...110 """111 # Initialize and connect driver wrapper112 start_driver(context_or_world, no_driver)113 # Add assert screenshot methods with scenario configuration114 add_assert_screenshot_methods(context_or_world, scenario)115 # Configure Jira properties116 save_jira_conf()117 context_or_world.logger.info("Running new scenario: %s", scenario.name)118def create_and_configure_wrapper(context_or_world):119 """Create and configure driver wrapper in behave or lettuce tests120 :param context_or_world: behave context or lettuce world121 """122 # Create default driver wrapper123 context_or_world.driver_wrapper = DriverWrappersPool.get_default_wrapper()124 context_or_world.utils = context_or_world.driver_wrapper.utils125 # Get behave userdata properties to override config properties126 try:127 behave_properties = context_or_world.config.userdata128 except AttributeError:129 behave_properties = None130 # Configure wrapper131 context_or_world.driver_wrapper.configure(context_or_world.config_files, behave_properties=behave_properties)132 # Copy config object133 context_or_world.toolium_config = context_or_world.driver_wrapper.config134 # Configure logger135 context_or_world.logger = logging.getLogger(__name__)136def connect_wrapper(context_or_world):137 """Connect driver in behave or lettuce tests138 :param context_or_world: behave context or lettuce world139 """140 # Create driver if it is not already created141 if context_or_world.driver_wrapper.driver:142 context_or_world.driver = context_or_world.driver_wrapper.driver143 else:144 context_or_world.driver = context_or_world.driver_wrapper.connect()145 # Copy app_strings object146 context_or_world.app_strings = context_or_world.driver_wrapper.app_strings147def add_assert_screenshot_methods(context_or_world, scenario):148 """Add assert screenshot methods to behave or lettuce object149 :param context_or_world: behave context or lettuce world150 :param scenario: running scenario151 """152 file_suffix = scenario.name153 def assert_screenshot(element_or_selector, filename, threshold=0, exclude_elements=[], driver_wrapper=None,154 force=False):155 VisualTest(driver_wrapper, force).assert_screenshot(element_or_selector, filename, file_suffix, threshold,156 exclude_elements)157 def assert_full_screenshot(filename, threshold=0, exclude_elements=[], driver_wrapper=None, force=False):158 VisualTest(driver_wrapper, force).assert_screenshot(None, filename, file_suffix, threshold, exclude_elements)159 # Monkey patching assert_screenshot method in PageElement to use the correct test name160 def assert_screenshot_page_element(self, filename, threshold=0, exclude_elements=[], force=False):161 VisualTest(self.driver_wrapper, force).assert_screenshot(self.web_element, filename, file_suffix, threshold,...

Full Screen

Full Screen

test_environment.py

Source:test_environment.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""3Copyright 2016 Telefónica Investigación y Desarrollo, S.A.U.4This file is part of Toolium.5Licensed under the Apache License, Version 2.0 (the "License");6you may not use this file except in compliance with the License.7You may obtain a copy of the License at8 http://www.apache.org/licenses/LICENSE-2.09Unless required by applicable law or agreed to in writing, software10distributed under the License is distributed on an "AS IS" BASIS,11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12See the License for the specific language governing permissions and13limitations under the License.14"""15import os16import mock17import pytest18from toolium.behave.environment import (get_jira_key_from_scenario, before_all, before_feature, before_scenario,19 after_scenario, after_feature, after_all)20from toolium.config_files import ConfigFiles21from toolium.config_parser import ExtendedConfigParser22tags = (23 (["jira('PROJECT-32')"], 'PROJECT-32'),24 (["jira=PROJECT-32"], 'PROJECT-32'),25 (["jira(PROJECT-32)"], 'PROJECT-32'),26 (["jira='PROJECT-32'"], 'PROJECT-32'),27 (["jiraPROJECT-32"], 'PROJECT-32'),28 (["jira"], None),29 (["PROJECT-32"], None),30 (['slow', "jira('PROJECT-32')", 'critical'], 'PROJECT-32'),31 (['slow', "PROJECT-32", 'critical'], None),32 (['slow', "jira('PROJECT-32')", "jira('PROJECT-33')"], 'PROJECT-32'),33)34@pytest.mark.parametrize("tag_list, jira_key", tags)35def test_get_jira_key_from_scenario(tag_list, jira_key):36 scenario = mock.Mock()37 scenario.tags = tag_list38 # Extract Jira key and compare with expected key39 assert jira_key == get_jira_key_from_scenario(scenario)40@mock.patch('toolium.behave.environment.create_and_configure_wrapper')41def test_before_all(create_and_configure_wrapper):42 # Create context mock43 context = mock.MagicMock()44 context.config.userdata.get.return_value = None45 context.config_files = ConfigFiles()46 before_all(context)47 # Check that configuration folder is the same as environment folder48 expected_config_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'conf')49 assert context.config_files.config_directory == expected_config_directory50 assert context.config_files.config_properties_filenames is None51 assert context.config_files.config_log_filename is None52properties = (53 'TOOLIUM_CONFIG_ENVIRONMENT',54 'Config_environment',55 'env'56)57@pytest.mark.parametrize("property_name", properties)58@mock.patch('toolium.behave.environment.create_and_configure_wrapper')59def test_before_all_config_environment(create_and_configure_wrapper, property_name):60 # Create context mock61 context = mock.MagicMock()62 context.config.userdata.get.side_effect = lambda x: 'os' if x == property_name else None63 context.config_files = ConfigFiles()64 before_all(context)65 # Check that configuration folder is the same as environment folder and property 'TOOLIUM_CONFIG_ENVIRONMENT' is66 # configured67 expected_config_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'conf')68 assert context.config_files.config_directory == expected_config_directory69 assert context.config_files.config_properties_filenames == 'properties.cfg;os-properties.cfg;local-os-properties.cfg'70 assert context.config_files.config_log_filename is None71 assert os.environ['TOOLIUM_CONFIG_ENVIRONMENT'] == 'os'72 del os.environ['TOOLIUM_CONFIG_ENVIRONMENT']73@mock.patch('toolium.behave.environment.start_driver')74def test_before_feature(start_driver):75 # Create context mock76 context = mock.MagicMock()77 context.toolium_config = ExtendedConfigParser()78 feature = mock.MagicMock()79 feature.tags = ['a', 'b']80 before_feature(context, feature)81 # Check that start_driver is not called82 start_driver.assert_not_called()83@mock.patch('toolium.behave.environment.start_driver')84def test_before_feature_reuse_driver(start_driver):85 # Create context mock86 context = mock.MagicMock()87 context.toolium_config = ExtendedConfigParser()88 feature = mock.MagicMock()89 feature.tags = ['a', 'reuse_driver', 'b']90 before_feature(context, feature)91 # Check that start_driver is called when reuse_driver tag92 start_driver.assert_called_once_with(context, False)93 assert context.reuse_driver_from_tags is True94@mock.patch('toolium.behave.environment.start_driver')95def test_before_feature_reuse_driver_no_driver(start_driver):96 # Create context mock97 context = mock.MagicMock()98 context.toolium_config = ExtendedConfigParser()99 feature = mock.MagicMock()100 feature.tags = ['a', 'reuse_driver', 'b', 'no_driver']101 before_feature(context, feature)102 # Check that start_driver is called when reuse_driver tag, with True no_driver param103 start_driver.assert_called_once_with(context, True)104 assert context.reuse_driver_from_tags is True105@mock.patch('toolium.behave.environment.add_assert_screenshot_methods')106@mock.patch('toolium.behave.environment.DriverWrappersPool')107@mock.patch('toolium.behave.environment.start_driver')108def test_before_scenario(start_driver, DriverWrappersPool, add_assert_screenshot_methods):109 # Create context mock110 context = mock.MagicMock()111 context.toolium_config = ExtendedConfigParser()112 scenario = mock.MagicMock()113 scenario.tags = ['a', 'b']114 before_scenario(context, scenario)115 # Check that start_driver is called116 start_driver.assert_called_once_with(context, False)117 DriverWrappersPool.stop_drivers.assert_not_called()118@mock.patch('toolium.behave.environment.add_assert_screenshot_methods')119@mock.patch('toolium.behave.environment.DriverWrappersPool')120@mock.patch('toolium.behave.environment.start_driver')121def test_before_scenario_reset_driver(start_driver, DriverWrappersPool, add_assert_screenshot_methods):122 # Create context mock123 context = mock.MagicMock()124 context.toolium_config = ExtendedConfigParser()125 scenario = mock.MagicMock()126 scenario.tags = ['a', 'reset_driver', 'b']127 before_scenario(context, scenario)128 # Check that start_driver and stop drivers are called129 start_driver.assert_called_once_with(context, False)130 DriverWrappersPool.stop_drivers.assert_called_once_with()131@mock.patch('toolium.behave.environment.add_assert_screenshot_methods')132@mock.patch('toolium.behave.environment.start_driver')133def test_before_scenario_no_driver(start_driver, add_assert_screenshot_methods):134 # Create context mock135 context = mock.MagicMock()136 context.toolium_config = ExtendedConfigParser()137 scenario = mock.MagicMock()138 scenario.tags = ['a', 'no_driver', 'b']139 before_scenario(context, scenario)140 # Check that start_driver is called141 start_driver.assert_called_once_with(context, True)142@mock.patch('toolium.behave.environment.add_assert_screenshot_methods')143@mock.patch('toolium.behave.environment.start_driver')144def test_before_scenario_no_driver_feature(start_driver, add_assert_screenshot_methods):145 # Create context mock146 context = mock.MagicMock()147 context.toolium_config = ExtendedConfigParser()148 scenario = mock.MagicMock()149 scenario.tags = ['a', 'b']150 scenario.feature.tags = ['no_driver']151 before_scenario(context, scenario)152 # Check that start_driver is called153 start_driver.assert_called_once_with(context, True)154@mock.patch('toolium.behave.environment.DriverWrappersPool')155def test_after_scenario_passed(DriverWrappersPool):156 # Create context mock157 context = mock.MagicMock()158 context.global_status = {'test_passed': True}159 scenario = mock.MagicMock()160 scenario.name = 'name'161 scenario.status = 'passed'162 after_scenario(context, scenario)163 # Check that close_drivers is called164 assert context.global_status['test_passed'] is True165 DriverWrappersPool.close_drivers.assert_called_once_with(context=context, scope='function', test_name='name',166 test_passed=True)167@mock.patch('toolium.behave.environment.DriverWrappersPool')168def test_after_scenario_failed(DriverWrappersPool):169 # Create context mock170 context = mock.MagicMock()171 context.global_status = {'test_passed': True}172 scenario = mock.MagicMock()173 scenario.name = 'name'174 scenario.status = 'failed'175 after_scenario(context, scenario)176 # Check that close_drivers is called177 assert context.global_status['test_passed'] is False178 DriverWrappersPool.close_drivers.assert_called_once_with(context=context, scope='function', test_name='name',179 test_passed=False)180@mock.patch('toolium.behave.environment.DriverWrappersPool')181def test_after_scenario_skipped(DriverWrappersPool):182 # Create context mock183 context = mock.MagicMock()184 context.global_status = {'test_passed': True}185 scenario = mock.MagicMock()186 scenario.name = 'name'187 scenario.status = 'skipped'188 after_scenario(context, scenario)189 # Check that close_drivers is not called190 assert context.global_status['test_passed'] is True191 DriverWrappersPool.close_drivers.assert_not_called()192@mock.patch('toolium.behave.environment.DriverWrappersPool')193def test_after_feature(DriverWrappersPool):194 # Create context mock195 context = mock.MagicMock()196 context.global_status = {'test_passed': True}197 feature = mock.MagicMock()198 feature.name = 'name'199 after_feature(context, feature)200 # Check that close_drivers is called201 DriverWrappersPool.close_drivers.assert_called_once_with(scope='module', test_name='name', test_passed=True)202@mock.patch('toolium.behave.environment.DriverWrappersPool')203def test_after_all(DriverWrappersPool):204 # Create context mock205 context = mock.MagicMock()206 context.global_status = {'test_passed': True}207 after_all(context)208 # Check that close_drivers is called209 DriverWrappersPool.close_drivers.assert_called_once_with(scope='session', test_name='multiple_tests',...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run toolium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful