How to use is_ios_test method in toolium

Best Python code snippet using toolium_python

test_page_element.py

Source:test_page_element.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 selenium.common.exceptions import NoSuchElementException, TimeoutException19from selenium.webdriver.common.by import By20from selenium.webdriver.remote.webelement import WebElement21from toolium.config_files import ConfigFiles22from toolium.driver_wrapper import DriverWrapper23from toolium.driver_wrappers_pool import DriverWrappersPool24from toolium.pageelements import PageElement, Group25from toolium.pageobjects.page_object import PageObject26child_element = 'child_element'27mock_element = None28class MenuGroup(Group):29 logo = PageElement(By.ID, 'image')30 logo_wait = PageElement(By.ID, 'image2', wait=True)31class RegisterPageObject(PageObject):32 username = PageElement(By.XPATH, '//input[0]')33 password = PageElement(By.ID, 'password', parent=username)34 menu_group = MenuGroup(By.ID, 'menu')35 def init_page_elements(self):36 self.language = PageElement(By.ID, 'language')37 self.email = PageElement(By.ID, 'email', parent=mock_element)38 self.address = PageElement(By.ID, 'address', parent=(By.ID, 'parent'))39 self.address_shadowroot = PageElement(By.CSS_SELECTOR, '#address', shadowroot='shadowroot_css')40 self.address_shadowroot_by_id = PageElement(By.ID, 'address', shadowroot='shadowroot_css')41 self.element_webview = PageElement(By.ID, 'webview', webview=True)42@pytest.fixture43def driver_wrapper():44 """Create a new mock element and a new driver before each test"""45 global mock_element46 mock_element = mock.MagicMock(spec=WebElement)47 mock_element.find_element.return_value = child_element48 # Reset wrappers pool values49 DriverWrappersPool._empty_pool()50 DriverWrapper.config_properties_filenames = None51 # Create a new wrapper52 driver_wrapper = DriverWrappersPool.get_default_wrapper()53 # Configure wrapper54 root_path = os.path.dirname(os.path.realpath(__file__))55 config_files = ConfigFiles()56 config_files.set_config_directory(os.path.join(root_path, 'conf'))57 config_files.set_output_directory(os.path.join(root_path, 'output'))58 config_files.set_config_log_filename('logging.conf')59 DriverWrappersPool.configure_common_directories(config_files)60 driver_wrapper.configure_properties()61 driver_wrapper.driver = mock.MagicMock()62 driver_wrapper.is_mobile_test = mock.MagicMock(return_value=False)63 return driver_wrapper64def test_locator(driver_wrapper):65 page_object = RegisterPageObject(driver_wrapper)66 assert page_object.username.locator == (By.XPATH, '//input[0]')67 assert page_object.password.locator == (By.ID, 'password')68def test_reset_object(driver_wrapper):69 login_page = RegisterPageObject(driver_wrapper)70 login_page.username.web_element71 login_page.language.web_element72 # Check that web elements are filled73 assert login_page.username._web_element is not None74 assert login_page.language._web_element is not None75 login_page.username.reset_object()76 # Check that only username is reset77 assert login_page.username._web_element is None78 assert login_page.language._web_element is not None79def test_reset_object_two_page_objects(driver_wrapper):80 login_page = RegisterPageObject(driver_wrapper)81 login_page.language.web_element82 second_login_page = RegisterPageObject(driver_wrapper)83 second_login_page.language.web_element84 # Check that web elements are filled85 assert login_page.language._web_element is not None86 assert second_login_page.language._web_element is not None87 login_page.language.reset_object()88 # Check that only first language is reset89 assert login_page.language._web_element is None90 assert second_login_page.language._web_element is not None91def test_get_web_element(driver_wrapper):92 RegisterPageObject(driver_wrapper).username.web_element93 driver_wrapper.driver.find_element.assert_called_once_with(By.XPATH, '//input[0]')94def test_get_web_element_init_page(driver_wrapper):95 RegisterPageObject(driver_wrapper).language.web_element96 driver_wrapper.driver.find_element.assert_called_once_with(By.ID, 'language')97def test_get_web_element_with_parent(driver_wrapper):98 driver_wrapper.driver.find_element.return_value = mock_element99 web_element = RegisterPageObject(driver_wrapper).password.web_element100 assert web_element == child_element101 driver_wrapper.driver.find_element.assert_called_once_with(By.XPATH, '//input[0]')102 mock_element.find_element.assert_called_once_with(By.ID, 'password')103def test_get_web_element_with_parent_locator(driver_wrapper):104 driver_wrapper.driver.find_element.return_value = mock_element105 web_element = RegisterPageObject(driver_wrapper).address.web_element106 assert web_element == child_element107 driver_wrapper.driver.find_element.assert_called_once_with(By.ID, 'parent')108 mock_element.find_element.assert_called_once_with(By.ID, 'address')109def test_get_web_element_with_parent_web_element(driver_wrapper):110 web_element = RegisterPageObject(driver_wrapper).email.web_element111 assert web_element == child_element112 driver_wrapper.driver.find_element.assert_not_called()113 mock_element.find_element.assert_called_once_with(By.ID, 'email')114def test_get_web_element_shadowroot(driver_wrapper):115 RegisterPageObject(driver_wrapper).address_shadowroot.web_element116 expected_script = 'return document.querySelector("shadowroot_css").shadowRoot.querySelector("#address")'117 mock_element.find_element.assert_not_called()118 driver_wrapper.driver.execute_script.assert_called_once_with(expected_script)119def test_get_web_element_shadowroot_wrong_locator(driver_wrapper):120 with pytest.raises(Exception) as excinfo:121 RegisterPageObject(driver_wrapper).address_shadowroot_by_id.web_element122 assert "Locator type should be CSS_SELECTOR using shadowroot but found: id" in str(excinfo.value)123 mock_element.find_element.assert_not_called()124def test_get_web_element_in_test(driver_wrapper):125 PageElement(By.XPATH, '//input[0]').web_element126 driver_wrapper.driver.find_element.assert_called_once_with(By.XPATH, '//input[0]')127def test_get_web_element_two_times_saving_enabled(driver_wrapper):128 driver_wrapper.config.set('Driver', 'save_web_element', 'true')129 login_page = RegisterPageObject(driver_wrapper)130 login_page.username.web_element131 login_page.username.web_element132 # Check that find_element is not called the second time133 driver_wrapper.driver.find_element.assert_called_once_with(By.XPATH, '//input[0]')134def test_get_web_element_two_times_saving_disabled(driver_wrapper):135 driver_wrapper.config.set('Driver', 'save_web_element', 'false')136 login_page = RegisterPageObject(driver_wrapper)137 login_page.username.web_element138 login_page.username.web_element139 # Check that find_element is called two times140 assert driver_wrapper.driver.find_element.call_count == 2141def test_get_web_element_two_elements(driver_wrapper):142 login_page = RegisterPageObject(driver_wrapper)143 login_page.username.web_element144 login_page.language.web_element145 # Check that find_element is called two times146 driver_wrapper.driver.find_element.assert_has_calls(147 [mock.call(By.XPATH, '//input[0]'), mock.call(By.ID, 'language')])148def test_get_web_element_two_objects(driver_wrapper):149 login_page = RegisterPageObject(driver_wrapper)150 login_page.language.web_element151 second_login_page = RegisterPageObject(driver_wrapper)152 second_login_page.language.web_element153 # Check that find_element is called two times154 driver_wrapper.driver.find_element.assert_has_calls(155 [mock.call(By.ID, 'language'), mock.call(By.ID, 'language')])156def test_get_web_element_exception(driver_wrapper):157 driver_wrapper.driver.find_element.side_effect = NoSuchElementException('Unknown')158 with pytest.raises(NoSuchElementException) as excinfo:159 RegisterPageObject(driver_wrapper).username.web_element160 assert "Page element of type 'PageElement' with locator ('xpath', '//input[0]') not found" in str(excinfo.value)161def test_is_present(driver_wrapper):162 driver_wrapper.driver.find_element.return_value = mock_element163 assert RegisterPageObject(driver_wrapper).username.is_present() is True164def test_is_present_not_found(driver_wrapper):165 driver_wrapper.driver.find_element.side_effect = NoSuchElementException('Unknown')166 assert RegisterPageObject(driver_wrapper).username.is_present() is False167def test_is_visible(driver_wrapper):168 mock_element.is_displayed.return_value = True169 driver_wrapper.driver.find_element.return_value = mock_element170 assert RegisterPageObject(driver_wrapper).username.is_visible() is True171def test_is_visible_not_visible(driver_wrapper):172 mock_element.is_displayed.return_value = False173 driver_wrapper.driver.find_element.return_value = mock_element174 assert RegisterPageObject(driver_wrapper).username.is_visible() is False175def test_is_visible_not_found(driver_wrapper):176 driver_wrapper.driver.find_element.side_effect = NoSuchElementException('Unknown')177 assert RegisterPageObject(driver_wrapper).username.is_visible() is False178def test_wait_until_visible(driver_wrapper):179 driver_wrapper.utils.wait_until_element_visible = mock.MagicMock(return_value=mock_element)180 page_element = RegisterPageObject(driver_wrapper).username181 element = page_element.wait_until_visible()182 assert element == page_element183def test_wait_until_visible_exception(driver_wrapper):184 driver_wrapper.utils.wait_until_element_visible = mock.MagicMock()185 driver_wrapper.utils.wait_until_element_visible.side_effect = TimeoutException('Unknown')186 page_element = RegisterPageObject(driver_wrapper).username187 with pytest.raises(TimeoutException) as excinfo:188 page_element.wait_until_visible()189 assert "Page element of type 'PageElement' with locator ('xpath', '//input[0]') not found or is not " \190 "visible after 10 seconds" in str(excinfo.value)191def test_wait_until_visible_exception_custom_timeout(driver_wrapper):192 driver_wrapper.utils.wait_until_element_visible = mock.MagicMock()193 driver_wrapper.utils.wait_until_element_visible.side_effect = TimeoutException('Unknown')194 page_element = RegisterPageObject(driver_wrapper).username195 with pytest.raises(TimeoutException) as excinfo:196 page_element.wait_until_visible(timeout=15)197 assert "Page element of type 'PageElement' with locator ('xpath', '//input[0]') not found or is not " \198 "visible after 15 seconds" in str(excinfo.value)199def test_wait_until_not_visible(driver_wrapper):200 driver_wrapper.utils.wait_until_element_not_visible = mock.MagicMock(return_value=False)201 page_element = RegisterPageObject(driver_wrapper).username202 element = page_element.wait_until_not_visible()203 assert element._web_element is None204 assert element == page_element205def test_wait_until_not_visible_exception(driver_wrapper):206 driver_wrapper.utils.wait_until_element_not_visible = mock.MagicMock()207 driver_wrapper.utils.wait_until_element_not_visible.side_effect = TimeoutException('Unknown')208 page_element = RegisterPageObject(driver_wrapper).username209 with pytest.raises(TimeoutException) as excinfo:210 page_element.wait_until_not_visible()211 assert "Page element of type 'PageElement' with locator ('xpath', '//input[0]') is still " \212 "visible after 10 seconds" in str(excinfo.value)213def test_wait_until_not_visible_exception_custom_timeout(driver_wrapper):214 driver_wrapper.utils.wait_until_element_not_visible = mock.MagicMock()215 driver_wrapper.utils.wait_until_element_not_visible.side_effect = TimeoutException('Unknown')216 page_element = RegisterPageObject(driver_wrapper).username217 with pytest.raises(TimeoutException) as excinfo:218 page_element.wait_until_not_visible(timeout=15)219 assert "Page element of type 'PageElement' with locator ('xpath', '//input[0]') is still " \220 "visible after 15 seconds" in str(excinfo.value)221def test_wait_until_clickable(driver_wrapper):222 driver_wrapper.utils.wait_until_element_clickable = mock.MagicMock(return_value=mock_element)223 page_element = RegisterPageObject(driver_wrapper).username224 element = page_element.wait_until_clickable()225 assert element == page_element226def test_wait_until_clickable_exception(driver_wrapper):227 driver_wrapper.utils.wait_until_element_clickable = mock.MagicMock()228 driver_wrapper.utils.wait_until_element_clickable.side_effect = TimeoutException('Unknown')229 page_element = RegisterPageObject(driver_wrapper).username230 with pytest.raises(TimeoutException) as excinfo:231 page_element.wait_until_clickable()232 assert "Page element of type 'PageElement' with locator ('xpath', '//input[0]') not found or is not " \233 "clickable after 10 seconds" in str(excinfo.value)234def test_wait_until_clickable_exception_custom_timeout(driver_wrapper):235 driver_wrapper.utils.wait_until_element_clickable = mock.MagicMock()236 driver_wrapper.utils.wait_until_element_clickable.side_effect = TimeoutException('Unknown')237 page_element = RegisterPageObject(driver_wrapper).username238 with pytest.raises(TimeoutException) as excinfo:239 page_element.wait_until_clickable(timeout=15)240 assert "Page element of type 'PageElement' with locator ('xpath', '//input[0]') not found or is not " \241 "clickable after 15 seconds" in str(excinfo.value)242@mock.patch('toolium.visual_test.VisualTest.__init__', return_value=None)243@mock.patch('toolium.visual_test.VisualTest.assert_screenshot')244def test_assert_screenshot(visual_assert_screenshot, visual_init, driver_wrapper):245 driver_wrapper.driver.find_element.return_value = mock_element246 RegisterPageObject(driver_wrapper).username.assert_screenshot('filename')247 visual_init.assert_called_once_with(driver_wrapper, False)248 visual_assert_screenshot.assert_called_once_with(mock_element, 'filename', 'PageElement', 0, [])249@mock.patch('toolium.visual_test.VisualTest.__init__', return_value=None)250@mock.patch('toolium.visual_test.VisualTest.assert_screenshot')251def test_assert_screenshot_options(visual_assert_screenshot, visual_init, driver_wrapper):252 driver_wrapper.driver.find_element.return_value = mock_element253 RegisterPageObject(driver_wrapper).username.assert_screenshot('filename', threshold=0.1,254 exclude_elements=[mock_element],255 force=True)256 visual_init.assert_called_once_with(driver_wrapper, True)257 visual_assert_screenshot.assert_called_once_with(mock_element, 'filename', 'PageElement', 0.1, [mock_element])258def test_get_attribute(driver_wrapper):259 driver_wrapper.driver.find_element.return_value = mock_element260 RegisterPageObject(driver_wrapper).username.get_attribute('attribute_name')261 mock_element.get_attribute.assert_called_once_with('attribute_name')262def test_automatic_context_selection_group(driver_wrapper):263 driver_wrapper.utils.wait_until_element_visible = mock.MagicMock(return_value=mock_element)264 driver_wrapper.is_android_test = mock.MagicMock(return_value=True)265 driver_wrapper.config.set('Driver', 'automatic_context_selection', 'true')266 driver_wrapper.driver.context = "NATIVE_APP"267 driver_wrapper.driver.contexts = ["NATIVE_APP", "WEBVIEW"]268 RegisterPageObject(driver_wrapper).menu_group.web_element269 driver_wrapper.driver.switch_to.context.assert_not_called()270 driver_wrapper.driver.find_element.assert_called_once_with(By.ID, 'menu')271def test_android_automatic_context_selection_app_package_cap_not_available(driver_wrapper):272 driver_wrapper.is_android_test = mock.MagicMock(return_value=True)273 driver_wrapper.config.set('Driver', 'automatic_context_selection', 'true')274 driver_wrapper.driver.context = "NATIVE_APP"275 driver_wrapper.driver.execute_script.return_value = [{'webviewName': 'WEBVIEW_test.package.fake',276 'pages': [{'id': '1234567890'}]}]277 driver_wrapper.driver.capabilities.__getitem__.side_effect = KeyError('no cap')278 driver_wrapper.driver.contexts = ["NATIVE_APP", "WEBVIEW_other.fake", "WEBVIEW_test.package.fake"]279 with pytest.raises(KeyError, match=r"no cap"):280 RegisterPageObject(driver_wrapper).element_webview.web_element281def test_ios_automatic_context_selection_bundle_id_cap_not_available(driver_wrapper):282 driver_wrapper.is_android_test = mock.MagicMock(return_value=False)283 driver_wrapper.is_ios_test = mock.MagicMock(return_value=True)284 driver_wrapper.config.set('Driver', 'automatic_context_selection', 'true')285 driver_wrapper.driver.context = "NATIVE_APP"286 driver_wrapper.driver.execute_script.return_value = [{'bundleId': 'test.package.fake',287 'id': 'WEBVIEW_12345.1'}]288 driver_wrapper.driver.capabilities.__getitem__.side_effect = KeyError('no cap')289 driver_wrapper.driver.contexts = ["NATIVE_APP", "WEBVIEW_other.fake", "WEBVIEW_test.package.fake"]290 with pytest.raises(KeyError, match=r"no cap"):291 RegisterPageObject(driver_wrapper).element_webview.web_element292def test_android_automatic_context_selection_no_webview_context_available(driver_wrapper):293 driver_wrapper.is_android_test = mock.MagicMock(return_value=True)294 driver_wrapper.is_ios_test = mock.MagicMock(return_value=False)295 driver_wrapper.config = mock.MagicMock()296 driver_wrapper.driver.execute_script.return_value = [{'webviewName': 'WEBVIEW_test.package.fake',297 'pages': [{'id': '1234567890'}]}]298 driver_wrapper.config.set('Driver', 'automatic_context_selection', 'true')299 driver_wrapper.driver.context = "NATIVE_APP"300 with pytest.raises(Exception) as excinfo:301 RegisterPageObject(driver_wrapper).element_webview.web_element302 assert "WEBVIEW context not found" in str(excinfo.value)303def test_ios_automatic_context_selection_no_webview_context_available(driver_wrapper):304 driver_wrapper.is_android_test = mock.MagicMock(return_value=False)305 driver_wrapper.is_ios_test = mock.MagicMock(return_value=True)306 driver_wrapper.config = mock.MagicMock()307 driver_wrapper.driver.execute_script.return_value = [{'bundleId': 'test.package.fake',308 'id': 'WEBVIEW_12345.1'}]309 driver_wrapper.config.set('Driver', 'automatic_context_selection', 'true')310 driver_wrapper.driver.context = "NATIVE_APP"311 with pytest.raises(Exception) as excinfo:312 RegisterPageObject(driver_wrapper).element_webview.web_element313 assert "WEBVIEW context not found" in str(excinfo.value)314def test_android_automatic_context_selection_already_in_desired_webview_context_and_window(driver_wrapper):315 driver_wrapper.is_android_test = mock.MagicMock(return_value=True)316 driver_wrapper.is_ios_test = mock.MagicMock(return_value=False)317 driver_wrapper.config = mock.MagicMock()318 driver_wrapper.config.set('Driver', 'automatic_context_selection', 'true')319 driver_wrapper.driver.capabilities = {'appPackage': 'test.package.fake'}320 driver_wrapper.driver.context = "WEBVIEW_test.package.fake"321 driver_wrapper.driver.current_window_handle = "CWindow-1234567890"322 driver_wrapper.driver.execute_script.return_value = [{'webviewName': 'WEBVIEW_test.package.fake',323 'pages': [{'id': '1234567890'},324 {'id': '0987654321'}]}]325 RegisterPageObject(driver_wrapper).element_webview.web_element326 driver_wrapper.driver.switch_to.context.assert_not_called327 driver_wrapper.driver.switch_to.window.assert_not_called328def test_android_automatic_context_selection_already_in_desired_webview_context_but_different_window(driver_wrapper):329 driver_wrapper.is_android_test = mock.MagicMock(return_value=True)330 driver_wrapper.is_ios_test = mock.MagicMock(return_value=False)331 driver_wrapper.config = mock.MagicMock()332 driver_wrapper.config.set('Driver', 'automatic_context_selection', 'true')333 driver_wrapper.driver.capabilities = {'appPackage': 'test.package.fake'}334 driver_wrapper.driver.context = "WEBVIEW_test.package.fake"335 driver_wrapper.driver.current_window_handle = "CDwindow-0987654321"336 driver_wrapper.driver.execute_script.return_value = [{'webviewName': 'WEBVIEW_test.package.fake',337 'pages': [{'id': '1234567890'},338 {'id': '0987654321'}]}]339 RegisterPageObject(driver_wrapper).element_webview.web_element340 driver_wrapper.driver.switch_to.context.assert_not_called341 driver_wrapper.driver.switch_to.window.assert_called_once_with('CDwindow-1234567890')342def test_ios_automatic_context_selection_already_in_desired_webview_context(driver_wrapper):343 driver_wrapper.is_android_test = mock.MagicMock(return_value=False)344 driver_wrapper.is_ios_test = mock.MagicMock(return_value=True)345 driver_wrapper.config = mock.MagicMock()346 driver_wrapper.config.set('Driver', 'automatic_context_selection', 'true')347 driver_wrapper.driver.capabilities = {'bundleId': 'test.package.fake'}348 driver_wrapper.driver.context = "WEBVIEW_12345.1"349 driver_wrapper.driver.execute_script.return_value = [{'bundleId': 'test.package.fake',350 'id': 'WEBVIEW_12345.1'},351 {'bundleId': 'test.package.fake',352 'id': 'WEBVIEW_12345.7'},353 {'bundleId': 'test.package.fake',354 'id': 'WEBVIEW_54321.1'}]355 RegisterPageObject(driver_wrapper).element_webview.web_element356 driver_wrapper.driver.switch_to.context.assert_not_called357def test_android_automatic_context_selection_switch_to_new_webview_context(driver_wrapper):358 driver_wrapper.is_android_test = mock.MagicMock(return_value=True)359 driver_wrapper.is_ios_test = mock.MagicMock(return_value=False)360 driver_wrapper.config = mock.MagicMock()361 driver_wrapper.config.set('Driver', 'automatic_context_selection', 'true')362 driver_wrapper.driver.capabilities = {'appPackage': 'test.package.fake'}363 driver_wrapper.driver.context = "WEBVIEW_other.fake.context"364 driver_wrapper.driver.current_window_handle = "CDwindow-0987654321"365 driver_wrapper.driver.execute_script.return_value = [{'webviewName': 'WEBVIEW_test.package.fake',366 'pages': [{'id': '1234567890'},367 {'id': '0987654321'}]}]368 RegisterPageObject(driver_wrapper).element_webview.web_element369 driver_wrapper.driver.switch_to.context.assert_called_once_with('WEBVIEW_test.package.fake')370 driver_wrapper.driver.switch_to.window.assert_called_once_with('CDwindow-1234567890')371def test_ios_automatic_context_selection_switch_to_new_webview_context(driver_wrapper):372 driver_wrapper.is_android_test = mock.MagicMock(return_value=False)373 driver_wrapper.is_ios_test = mock.MagicMock(return_value=True)374 driver_wrapper.config = mock.MagicMock()375 driver_wrapper.config.set('Driver', 'automatic_context_selection', 'true')376 driver_wrapper.driver.capabilities = {'bundleId': 'test.package.fake'}377 driver_wrapper.driver.context = "WEBVIEW_54321.1"378 driver_wrapper.driver.execute_script.return_value = [{'bundleId': 'test.package.fake',379 'id': 'WEBVIEW_12345.1'},380 {'bundleId': 'test.package.fake',381 'id': 'WEBVIEW_12345.7'},382 {'bundleId': 'other.package.fake',383 'id': 'WEBVIEW_54321.1'}]384 RegisterPageObject(driver_wrapper).element_webview.web_element385 driver_wrapper.driver.switch_to.context.assert_called_once_with('WEBVIEW_12345.7')386def test_android_automatic_context_selection_already_in_native_context(driver_wrapper):387 driver_wrapper.is_android_test = mock.MagicMock(return_value=True)388 driver_wrapper.is_ios_test = mock.MagicMock(return_value=False)389 driver_wrapper.config = mock.MagicMock()390 driver_wrapper.config.set('Driver', 'automatic_context_selection', 'true')391 driver_wrapper.driver.capabilities = {'appPackage': 'test.package.fake'}392 driver_wrapper.driver.context = "NATIVE_APP"393 RegisterPageObject(driver_wrapper).email394 driver_wrapper.driver.switch_to.context.assert_not_called395def test_ios_automatic_context_selection_already_in_native_context(driver_wrapper):396 driver_wrapper.is_android_test = mock.MagicMock(return_value=False)397 driver_wrapper.is_ios_test = mock.MagicMock(return_value=True)398 driver_wrapper.config = mock.MagicMock()399 driver_wrapper.config.set('Driver', 'automatic_context_selection', 'true')400 driver_wrapper.driver.capabilities = {'appPackage': 'test.package.fake'}401 driver_wrapper.driver.context = "NATIVE_APP"402 RegisterPageObject(driver_wrapper).email403 driver_wrapper.driver.switch_to.context.assert_not_called404def test_android_automatic_context_selection_switch_to_native_context(driver_wrapper):405 driver_wrapper.is_android_test = mock.MagicMock(return_value=True)406 driver_wrapper.is_ios_test = mock.MagicMock(return_value=False)407 driver_wrapper.config = mock.MagicMock()408 driver_wrapper.config.set('Driver', 'automatic_context_selection', 'true')409 driver_wrapper.driver.context = "WEBVIEW_test.package.fake"410 RegisterPageObject(driver_wrapper).language.web_element411 driver_wrapper.driver.switch_to.context.assert_called_once_with('NATIVE_APP')412def test_ios_automatic_context_selection_switch_to_native_context(driver_wrapper):413 driver_wrapper.is_android_test = mock.MagicMock(return_value=False)414 driver_wrapper.is_ios_test = mock.MagicMock(return_value=True)415 driver_wrapper.config = mock.MagicMock()416 driver_wrapper.config.set('Driver', 'automatic_context_selection', 'true')417 driver_wrapper.driver.context = "WEBVIEW_12345.1"418 RegisterPageObject(driver_wrapper).language.web_element419 driver_wrapper.driver.switch_to.context.assert_called_once_with('NATIVE_APP')420def test_android_automatic_context_selection_callback_provided(driver_wrapper):421 driver_wrapper.is_android_test = mock.MagicMock(return_value=True)422 driver_wrapper.is_ios_test = mock.MagicMock(return_value=False)423 driver_wrapper.config = mock.MagicMock()424 driver_wrapper.config.set('Driver', 'automatic_context_selection', 'true')425 driver_wrapper.driver.context = "WEBVIEW_fake.app.package"426 driver_wrapper.driver.current_window_handle = "CDwindow-0987654321"427 page_object = RegisterPageObject(driver_wrapper)428 page_object.element_webview.webview_context_selection_callback = lambda a, b: (a, b)429 page_object.element_webview.webview_csc_args = ['WEBVIEW_fake.other', "CDwindow-0123456789"]430 page_object.element_webview.web_element431 driver_wrapper.driver.switch_to.context.assert_called_once_with('WEBVIEW_fake.other')432 driver_wrapper.driver.switch_to.window.assert_called_once_with("CDwindow-0123456789")433def test_ios_automatic_context_selection_callback_provided(driver_wrapper):434 driver_wrapper.is_android_test = mock.MagicMock(return_value=False)435 driver_wrapper.is_ios_test = mock.MagicMock(return_value=True)436 driver_wrapper.config = mock.MagicMock()437 driver_wrapper.config.set('Driver', 'automatic_context_selection', 'true')438 driver_wrapper.driver.context = "WEBVIEW_12345.1"439 page_object = RegisterPageObject(driver_wrapper)440 page_object.element_webview.webview_context_selection_callback = lambda a: a441 page_object.element_webview.webview_csc_args = ['WEBVIEW_012345.67']442 page_object.element_webview.web_element443 driver_wrapper.driver.switch_to.context.assert_called_once_with('WEBVIEW_012345.67')444def test_automatic_context_selection_disabled(driver_wrapper):445 driver_wrapper.is_android_test = mock.MagicMock(return_value=True)446 driver_wrapper.is_ios_test = mock.MagicMock(return_value=False)447 driver_wrapper.config.set('Driver', 'automatic_context_selection', 'false')448 PageElement._automatic_context_selection = mock.MagicMock()449 RegisterPageObject(driver_wrapper).element_webview.web_element450 PageElement._automatic_context_selection.assert_not_called()...

Full Screen

Full Screen

utils.py

Source:utils.py Github

copy

Full Screen

1__author__ = 'mark'2# utils3from string import find4def utils_available(check=True):5 """6 Dummy function to test that utils.py is available7 """8 return check9def is_iOS(request):10 """11 Attempt to check for iOS as web browser12 """13 #print "META:"14 # print request.META15 print "User Agent:"16 print request.META['HTTP_USER_AGENT']17 ua = request.META['HTTP_USER_AGENT']18 # testing19 ## ua = 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3'20 browser_agent = ""21 is_iOS_test = False22 test_list= [{'char_check':"Safari",'eval_check':False},23 {'char_check':"Mobile",'eval_check':True},24 {'char_check':"iPhone",'eval_check':True},25 {'char_check':"iPod",'eval_check':True},26 {'char_check':"iPad",'eval_check':True}]27 for t in test_list:28 if (find(ua,t['char_check'])> -1):29 print t['char_check']+" "30 browser_agent = browser_agent + t['char_check'] + " "31 if is_iOS_test!=True:32 if t['eval_check']==True:33 is_iOS_test = True34 print "Browser discovery: "+browser_agent35 if is_iOS_test==True:36 browser_agent = "TRUE:"+browser_agent37 else:38 browser_agent = "FALSE:"+browser_agent39 print "Browser discovery: "+browser_agent40 return is_iOS_test41def is_iOS_browser(request):42 """43 Attempt to check for iOS as web browser44 """45 #print "META:"46 # print request.META47 print "User Agent:"48 print request.META['HTTP_USER_AGENT']49 ua = request.META['HTTP_USER_AGENT']50 # testing51 ## ua = 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3'52 print "testing with:"53 print ua54 browser_agent = ""55 is_iOS_test = False56 test_list= [{'char_check':"Safari",'eval_check':False},57 {'char_check':"Mobile",'eval_check':True},58 {'char_check':"iPhone",'eval_check':True},59 {'char_check':"iPod",'eval_check':True},60 {'char_check':"iPad",'eval_check':True}]61 print test_list62 for t in test_list:63 if (find(ua,t['char_check'])> -1):64 print t['char_check']+" "65 browser_agent = browser_agent + t['char_check'] + " "66 if is_iOS_test!=True:67 if t['eval_check']==True:68 is_iOS_test = True69 print "Browser discovery: "+browser_agent70 if is_iOS_test==True:71 browser_agent = "TRUE:"+browser_agent72 else:73 browser_agent = "FALSE:"+browser_agent74 print "Browser discovery: "+browser_agent...

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