How to use save_all_webdriver_logs method in toolium

Best Python code snippet using toolium_python

driver_wrappers_pool.py

Source:driver_wrappers_pool.py Github

copy

Full Screen

...116 # Execute behave dynamic environment117 if context and hasattr(context, 'dyn_env'):118 context.dyn_env.execute_after_scenario_steps(context)119 # Save webdriver logs on error or if it is enabled120 cls.save_all_webdriver_logs(test_name, test_passed)121 elif scope == 'session':122 from toolium.visual_test import VisualTest123 VisualTest.update_latest_report()124 # Close browser and stop driver if it must not be reused125 reuse_driver = cls.get_default_wrapper().should_reuse_driver(scope, test_passed, context)126 cls.stop_drivers(reuse_driver)127 cls.download_videos(test_name, test_passed, reuse_driver)128 cls.save_all_ggr_logs(test_name, test_passed)129 cls.remove_drivers(reuse_driver)130 @classmethod131 def stop_drivers(cls, maintain_default=False):132 """Stop all drivers except default if it should be reused133 :param maintain_default: True if the default driver should not be closed134 """135 # Exclude first wrapper if the driver must be reused136 driver_wrappers = cls.driver_wrappers[1:] if maintain_default else cls.driver_wrappers137 for driver_wrapper in driver_wrappers:138 if not driver_wrapper.driver:139 continue140 try:141 driver_wrapper.driver.quit()142 except Exception as e:143 driver_wrapper.logger.warning(144 "Capture exceptions to avoid errors in teardown method due to session timeouts: \n %s" % e)145 @classmethod146 def download_videos(cls, name, test_passed=True, maintain_default=False):147 """Download saved videos if video is enabled or if test fails148 :param name: destination file name149 :param test_passed: True if the test has passed150 :param maintain_default: True if the default driver should not be closed151 """152 # Exclude first wrapper if the driver must be reused153 driver_wrappers = cls.driver_wrappers[1:] if maintain_default else cls.driver_wrappers154 video_name = '{}_driver{}' if len(driver_wrappers) > 1 else '{}'155 video_name = video_name if test_passed else 'error_{}'.format(video_name)156 driver_index = 1157 for driver_wrapper in driver_wrappers:158 if not driver_wrapper.driver:159 continue160 try:161 # Download video if necessary (error case or enabled video)162 if (not test_passed or driver_wrapper.config.getboolean_optional('Server', 'video_enabled', False)) \163 and driver_wrapper.remote_node_video_enabled:164 driver_wrapper.utils.download_remote_video(driver_wrapper.server_type,165 video_name.format(name, driver_index))166 except Exception as exc:167 # Capture exceptions to avoid errors in teardown method due to session timeouts168 driver_wrapper.logger.warning('Error downloading videos: %s' % exc)169 driver_index += 1170 @classmethod171 def remove_drivers(cls, maintain_default=False):172 """Clean drivers list except default if it should be reused. Drivers must be closed before.173 :param maintain_default: True if the default driver should not be removed174 """175 cls.driver_wrappers = cls.driver_wrappers[0:1] if maintain_default else []176 @classmethod177 def save_all_webdriver_logs(cls, test_name, test_passed):178 """Get all webdriver logs of each driver and write them to log files179 :param test_name: test that has generated these logs180 :param test_passed: True if the test has passed181 """182 cls.save_all_webdriver_or_ggr_logs(test_name, test_passed, ggr=False)183 @classmethod184 def save_all_ggr_logs(cls, test_name, test_passed):185 """Get all GGR logs of each driver and write them to log files186 :param test_name: test that has generated these logs187 :param test_passed: True if the test has passed188 """189 cls.save_all_webdriver_or_ggr_logs(test_name, test_passed, ggr=True)190 @classmethod191 def save_all_webdriver_or_ggr_logs(cls, test_name, test_passed, ggr=False):...

Full Screen

Full Screen

driver_manager.py

Source:driver_manager.py Github

copy

Full Screen

...55 if not test_passed:56 cls.capture_screenshots(test_name)57 if context and hasattr(context, 'dyn_env'):58 context.pytalos.dyn_env.execute_after_scenario_steps(context)59 cls.save_all_webdriver_logs(test_name, test_passed)60 reuse_driver = cls.get_default_wrapper().should_reuse_driver(scope, test_passed, context)61 cls.stop_drivers(reuse_driver)62 cls.download_videos(test_name, test_passed, reuse_driver)63 cls.save_all_ggr_logs(test_name, test_passed)64 cls.remove_drivers(reuse_driver)65 @classmethod66 def stop_drivers(cls, maintain_default=False):67 driver_wrappers = cls.driver_wrappers[1:] if maintain_default else cls.driver_wrappers68 close_driver = settings.settings.PYTALOS_RUN['close_webdriver']69 for driver_wrapper in driver_wrappers:70 if not driver_wrapper.driver:71 continue72 try:73 if close_driver:74 driver_wrapper.driver.quit()75 except Exception as e:76 driver_wrapper.logger.warn(77 f"Capture exceptions to avoid errors in teardown method due to session timeouts: \n {e}")78 @classmethod79 def download_videos(cls, name, test_passed=True, maintain_default=False):80 driver_wrappers = cls.driver_wrappers[1:] if maintain_default else cls.driver_wrappers81 video_name = '{}_driver{}' if len(driver_wrappers) > 1 else '{}'82 video_name = video_name if test_passed else 'error_{}'.format(video_name)83 driver_index = 184 for driver_wrapper in driver_wrappers:85 if not driver_wrapper.driver:86 continue87 try:88 if (not test_passed or driver_wrapper.config.getboolean_optional('Server', 'video_enabled', False)) \89 and driver_wrapper.remote_node_video_enabled:90 if driver_wrapper.server_type in ['ggr', 'selenoid']:91 from arc.contrib.utilities import get_valid_filename92 name = get_valid_filename(video_name.format(name, driver_index))93 Selenoid(driver_wrapper).download_session_video(name)94 elif driver_wrapper.server_type == 'grid':95 driver_wrapper.utils.download_remote_video(driver_wrapper.remote_node,96 driver_wrapper.session_id,97 video_name.format(name, driver_index))98 except Exception as exc:99 driver_wrapper.logger.warn(f"Error downloading videos: {exc}")100 driver_index += 1101 @classmethod102 def remove_drivers(cls, maintain_default=False):103 close_driver = settings.settings.PYTALOS_RUN['close_webdriver']104 if close_driver:105 cls.driver_wrappers = cls.driver_wrappers[0:1] if maintain_default else []106 @classmethod107 def save_all_webdriver_logs(cls, test_name, test_passed):108 log_name = '{} [driver {}]' if len(cls.driver_wrappers) > 1 else '{}'109 driver_index = 1110 for driver_wrapper in cls.driver_wrappers:111 if not driver_wrapper.driver or driver_wrapper.server_type in ['ggr', 'selenoid']:112 continue113 if driver_wrapper.config.getboolean_optional('Server', 'logs_enabled') or not test_passed:114 try:115 driver_wrapper.utils.save_webdriver_logs(log_name.format(test_name, driver_index))116 except Exception as exc:117 driver_wrapper.logger.warn(f"Error downloading webdriver logs: {exc}")118 driver_index += 1119 @classmethod120 def save_all_ggr_logs(cls, test_name, test_passed):121 log_name = '{} [driver {}]' if len(cls.driver_wrappers) > 1 else '{}'...

Full Screen

Full Screen

test_driver_wrappers_pool.py

Source:test_driver_wrappers_pool.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""3Copyright 2015 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.config_files import ConfigFiles19from toolium.driver_wrapper import DriverWrapper20from toolium.driver_wrappers_pool import DriverWrappersPool21from toolium.visual_test import VisualTest22@pytest.fixture23def driver_wrapper():24 # Reset wrappers pool values25 DriverWrappersPool._empty_pool()26 # Create default wrapper27 driver_wrapper = DriverWrappersPool.get_default_wrapper()28 # Configure properties29 config_files = ConfigFiles()30 root_path = os.path.dirname(os.path.realpath(__file__))31 config_files.set_config_directory(os.path.join(root_path, 'conf'))32 config_files.set_output_directory(os.path.join(root_path, 'output'))33 driver_wrapper.configure(config_files)34 return driver_wrapper35def test_singleton(driver_wrapper):36 # Request default wrapper37 new_wrapper = DriverWrappersPool.get_default_wrapper()38 # Modify new wrapper39 new_driver_type = 'opera'40 new_wrapper.config.set('Driver', 'type', new_driver_type)41 # Check that both wrappers are the same object42 assert new_driver_type == driver_wrapper.config.get('Driver', 'type')43 assert new_driver_type == new_wrapper.config.get('Driver', 'type')44 assert driver_wrapper == new_wrapper45 assert DriverWrappersPool.driver_wrappers[0] == driver_wrapper46def test_multiple(driver_wrapper):47 # Request a new additional wrapper48 new_wrapper = DriverWrapper()49 # Check that wrapper and new_wrapper are different50 assert driver_wrapper != new_wrapper51 assert DriverWrappersPool.driver_wrappers[0] == driver_wrapper52 assert DriverWrappersPool.driver_wrappers[1] == new_wrapper53def test_connect_default_driver_wrapper(driver_wrapper):54 driver_wrapper.connect = mock.MagicMock()55 # Connect default driver wrapper56 new_wrapper = DriverWrappersPool.connect_default_driver_wrapper()57 # Check that both wrappers are the same object and connect has been called58 assert new_wrapper == driver_wrapper59 driver_wrapper.connect.assert_called_once_with()60def test_connect_default_driver_wrapper_already_connected(driver_wrapper):61 driver_wrapper.connect = mock.MagicMock()62 driver_wrapper.driver = 'fake'63 # Connect default driver wrapper64 new_wrapper = DriverWrappersPool.connect_default_driver_wrapper()65 # Check that both wrappers are the same object and connect has not been called66 assert new_wrapper == driver_wrapper67 driver_wrapper.connect.assert_not_called()68close_drivers_scopes = (69 'function',70 'module',71 'session',72)73@pytest.mark.parametrize("scope", close_drivers_scopes)74def test_close_drivers_function(scope, driver_wrapper):75 DriverWrappersPool.save_all_webdriver_logs = mock.MagicMock()76 VisualTest.update_latest_report = mock.MagicMock()77 # Close drivers78 DriverWrappersPool.close_drivers(scope, 'test_name')79 # Check that save_all_webdriver_logs method has been called only in function scope80 # Check that update_latest_report method has been called only in session scope81 if scope == 'function':82 DriverWrappersPool.save_all_webdriver_logs.assert_called_once_with('test_name', True)83 VisualTest.update_latest_report.assert_not_called()84 elif scope == 'module':85 DriverWrappersPool.save_all_webdriver_logs.assert_not_called()86 VisualTest.update_latest_report.assert_not_called()87 elif scope == 'session':88 DriverWrappersPool.save_all_webdriver_logs.assert_not_called()89 VisualTest.update_latest_report.assert_called_once_with()90def test_find_parent_directory_relative():91 directory = 'conf'92 filename = 'properties.cfg'93 expected_config_directory = os.path.join(os.getcwd(), 'conf')94 assert expected_config_directory == DriverWrappersPool._find_parent_directory(directory, filename)95def test_find_parent_directory_file_not_found():96 directory = 'conf'97 filename = 'unknown'98 expected_config_directory = os.path.join(os.getcwd(), 'conf')99 assert expected_config_directory == DriverWrappersPool._find_parent_directory(directory, filename)100def test_find_parent_directory_absolute():101 directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'conf')102 filename = 'properties.cfg'103 expected_config_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'conf')104 assert expected_config_directory == DriverWrappersPool._find_parent_directory(directory, filename)105def test_find_parent_directory_absolute_recursively():106 directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'unknown', 'conf')107 filename = 'properties.cfg'108 expected_config_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'conf')109 assert expected_config_directory == DriverWrappersPool._find_parent_directory(directory, filename)110def test_initialize_config_files_new():111 config_files = None112 # Initialize config files113 init_config_files = DriverWrappersPool.initialize_config_files(config_files)114 # Check expected config files115 assert init_config_files.config_properties_filenames is None116 assert init_config_files.output_log_filename is None117def test_initialize_config_files_new_environment():118 config_files = None119 os.environ['TOOLIUM_CONFIG_ENVIRONMENT'] = 'android'120 # Initialize config files121 config_files = DriverWrappersPool.initialize_config_files(config_files)122 del os.environ['TOOLIUM_CONFIG_ENVIRONMENT']123 # Check expected config files124 expected_properties_filenames = 'properties.cfg;android-properties.cfg;local-android-properties.cfg'125 assert config_files.config_properties_filenames == expected_properties_filenames126 assert config_files.output_log_filename == 'toolium_android.log'127def test_initialize_config_files_configured():128 config_files = ConfigFiles()129 config_files.set_config_properties_filenames('test.conf', 'local-test.conf')130 config_files.set_output_log_filename('test.log')131 # Initialize config files132 config_files = DriverWrappersPool.initialize_config_files(config_files)133 # Check expected config files134 assert config_files.config_properties_filenames == 'test.conf;local-test.conf'135 assert config_files.output_log_filename == 'test.log'136def test_initialize_config_files_configured_environment():137 config_files = ConfigFiles()138 config_files.set_config_properties_filenames('test.conf', 'local-test.conf')139 config_files.set_output_log_filename('test.log')140 os.environ['TOOLIUM_CONFIG_ENVIRONMENT'] = 'android'141 # Initialize config files142 config_files = DriverWrappersPool.initialize_config_files(config_files)143 del os.environ['TOOLIUM_CONFIG_ENVIRONMENT']144 # Check expected config files145 expected_properties_filenames = 'test.conf;local-test.conf;android-test.conf;local-android-test.conf'146 assert config_files.config_properties_filenames == expected_properties_filenames147 assert config_files.output_log_filename == 'test_android.log'148def test_initialize_config_files_configured_environment_with_points():149 config_files = ConfigFiles()150 config_files.set_config_properties_filenames('test.new.conf', 'local-test.new.conf')151 config_files.set_output_log_filename('test.new.log')152 os.environ['TOOLIUM_CONFIG_ENVIRONMENT'] = 'ios'153 # Initialize config files154 config_files = DriverWrappersPool.initialize_config_files(config_files)155 del os.environ['TOOLIUM_CONFIG_ENVIRONMENT']156 # Check expected config files157 expected_properties_filenames = 'test.new.conf;local-test.new.conf;ios-test.new.conf;local-ios-test.new.conf'158 assert config_files.config_properties_filenames == expected_properties_filenames...

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