From 0f754e83028db6751a76b9d5a447b555c9c408a3 Mon Sep 17 00:00:00 2001 From: Pandy Knight Date: Wed, 10 May 2023 14:16:16 -0400 Subject: [PATCH 1/3] Combined fixtures for UFG, Classic, and XCloud all in one --- tests/conftest.py | 61 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 0bf1813..926471f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -12,7 +12,16 @@ import pytest from applitools.selenium import * -from selenium.webdriver import Chrome, ChromeOptions +from applitools.selenium.runner import EyesRunner +from selenium.webdriver import Chrome, ChromeOptions, Remote + + +# -------------------------------------------------------------------------------- +# Runner Settings +# -------------------------------------------------------------------------------- + +USE_ULTRAFAST_GRID = True +USE_EXECUTION_CLOUD = False # -------------------------------------------------------------------------------- @@ -43,13 +52,18 @@ def headless(): @pytest.fixture(scope='session') def runner(): """ - Creates the runner for the Ultrafast Grid. - Concurrency refers to the number of visual checkpoints Applitools will perform in parallel. + Creates the runner for either the Ultrafast Grid or the Classic runner (local execution). + For UFG, concurrency refers to the number of visual checkpoints Applitools will perform in parallel. Warning: If you have a free account, then concurrency will be limited to 1. After the test suite finishes execution, closes the batch and report visual differences to the console. Note that it forces pytest to wait synchronously for all visual checkpoints to complete. """ - run = VisualGridRunner(RunnerOptions().test_concurrency(5)) + + if USE_ULTRAFAST_GRID: + run = VisualGridRunner(RunnerOptions().test_concurrency(5)) + else: + run = ClassicRunner() + yield run print(run.get_all_test_results()) @@ -81,16 +95,19 @@ def configuration(api_key: str, batch_info: BatchInfo): # then the SDK will automatically read the `APPLITOOLS_API_KEY` environment variable to fetch it. config.set_api_key(api_key) - # Add 3 desktop browsers with different viewports for cross-browser testing in the Ultrafast Grid. - # Other browsers are also available, like Edge and IE. - config.add_browser(800, 600, BrowserType.CHROME) - config.add_browser(1600, 1200, BrowserType.FIREFOX) - config.add_browser(1024, 768, BrowserType.SAFARI) + # If running tests on the Ultrafast Grid, configure browsers. + if USE_ULTRAFAST_GRID: + + # Add 3 desktop browsers with different viewports for cross-browser testing in the Ultrafast Grid. + # Other browsers are also available, like Edge and IE. + config.add_browser(800, 600, BrowserType.CHROME) + config.add_browser(1600, 1200, BrowserType.FIREFOX) + config.add_browser(1024, 768, BrowserType.SAFARI) - # Add 2 mobile emulation devices with different orientations for cross-browser testing in the Ultrafast Grid. - # Other mobile devices are available, including iOS. - config.add_device_emulation(DeviceName.Pixel_2, ScreenOrientation.PORTRAIT) - config.add_device_emulation(DeviceName.Nexus_10, ScreenOrientation.LANDSCAPE) + # Add 2 mobile emulation devices with different orientations for cross-browser testing in the Ultrafast Grid. + # Other mobile devices are available, including iOS. + config.add_device_emulation(DeviceName.Pixel_2, ScreenOrientation.PORTRAIT) + config.add_device_emulation(DeviceName.Nexus_10, ScreenOrientation.LANDSCAPE) # Return the configuration object return config @@ -106,25 +123,31 @@ def configuration(api_key: str, batch_info: BatchInfo): def webdriver(headless: bool): """ Creates a WebDriver object for Chrome. - Even though this test will run visual checkpoints on different browsers in the Ultrafast Grid, - it still needs to run the test one time locally to capture snapshots. After the test function finishes execution, quits the browser. """ + options = ChromeOptions() options.headless = headless - driver = Chrome(options=options) + + if USE_EXECUTION_CLOUD: + driver = Remote( + command_executor=Eyes.get_execution_cloud_url(), + options=options) + else: + driver = Chrome(options=options) + yield driver driver.quit() @pytest.fixture(scope='function') def eyes( - runner: VisualGridRunner, + runner: EyesRunner, configuration: Configuration, - webdriver: Chrome, + webdriver: Remote, request: pytest.FixtureRequest): """ - Creates the Applitools Eyes object connected to the VisualGridRunner and set its configuration. + Creates the Applitools Eyes object connected to the runner and set its configuration. Then, opens Eyes to start visual testing before the test, and closes Eyes at the end of the test. Opening Eyes requires 4 arguments: From e418521105e721f19e51b1c24a1874856c13cef9 Mon Sep 17 00:00:00 2001 From: Pandy Knight Date: Wed, 10 May 2023 14:54:56 -0400 Subject: [PATCH 2/3] Changed mobile browser config --- tests/conftest.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 926471f..22473a0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -104,10 +104,10 @@ def configuration(api_key: str, batch_info: BatchInfo): config.add_browser(1600, 1200, BrowserType.FIREFOX) config.add_browser(1024, 768, BrowserType.SAFARI) - # Add 2 mobile emulation devices with different orientations for cross-browser testing in the Ultrafast Grid. - # Other mobile devices are available, including iOS. - config.add_device_emulation(DeviceName.Pixel_2, ScreenOrientation.PORTRAIT) - config.add_device_emulation(DeviceName.Nexus_10, ScreenOrientation.LANDSCAPE) + # Add 2 mobile browsers with different orientations for cross-browser testing in the Ultrafast Grid. + # Other mobile devices are available. + config.add_browser(IosDeviceInfo(IosDeviceName.iPhone_11, ScreenOrientation.PORTRAIT)) + config.add_browser(ChromeEmulationInfo(DeviceName.Nexus_10, ScreenOrientation.LANDSCAPE)) # Return the configuration object return config From 39fe74ebd38da9bc46163ef504e59321f7608589 Mon Sep 17 00:00:00 2001 From: Pandy Knight Date: Wed, 10 May 2023 16:45:21 -0400 Subject: [PATCH 3/3] Made headless setting a hard-coded variable --- tests/conftest.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 22473a0..8dfa76f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -18,10 +18,13 @@ # -------------------------------------------------------------------------------- # Runner Settings +# These could be set by environment variables or other input mechanisms. +# They are hard-coded here to keep the example project simple. # -------------------------------------------------------------------------------- USE_ULTRAFAST_GRID = True USE_EXECUTION_CLOUD = False +HEADLESS = False # -------------------------------------------------------------------------------- @@ -38,17 +41,6 @@ def api_key(): return os.getenv('APPLITOOLS_API_KEY') -@pytest.fixture(scope='session') -def headless(): - """ - Reads the headless mode setting from an environment variable. - Uses headless mode for Continuous Integration (CI) execution. - Uses headed mode for local development. - """ - h = os.getenv('HEADLESS', default='false') - return h.lower() == 'true' - - @pytest.fixture(scope='session') def runner(): """ @@ -120,14 +112,14 @@ def configuration(api_key: str, batch_info: BatchInfo): # -------------------------------------------------------------------------------- @pytest.fixture(scope='function') -def webdriver(headless: bool): +def webdriver(): """ Creates a WebDriver object for Chrome. After the test function finishes execution, quits the browser. """ options = ChromeOptions() - options.headless = headless + options.headless = HEADLESS if USE_EXECUTION_CLOUD: driver = Remote(