Best Python code snippet using toolium_python
visual_test.py
Source:visual_test.py
...386 if diff_message is None:387 diff_message = message388 return diff_message389 @staticmethod390 def update_latest_report():391 """392 Duplicate current visual testing report into latest folder393 """394 if os.path.exists(DriverWrappersPool.visual_output_directory):395 latest_directory = os.path.join(os.path.dirname(DriverWrappersPool.visual_output_directory), 'latest')396 if os.path.exists(latest_directory):397 shutil.rmtree(latest_directory)...
driver_wrappers_pool.py
Source:driver_wrappers_pool.py
...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:...
test_driver_wrappers_pool.py
Source:test_driver_wrappers_pool.py
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...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!