1212import pytest
1313
1414from applitools .selenium import *
15- from selenium .webdriver import Chrome , ChromeOptions
15+ from applitools .selenium .runner import EyesRunner
16+ from selenium .webdriver import Chrome , ChromeOptions , Remote
17+
18+
19+ # --------------------------------------------------------------------------------
20+ # Runner Settings
21+ # --------------------------------------------------------------------------------
22+
23+ USE_ULTRAFAST_GRID = True
24+ USE_EXECUTION_CLOUD = False
1625
1726
1827# --------------------------------------------------------------------------------
@@ -43,13 +52,18 @@ def headless():
4352@pytest .fixture (scope = 'session' )
4453def runner ():
4554 """
46- Creates the runner for the Ultrafast Grid.
47- Concurrency refers to the number of visual checkpoints Applitools will perform in parallel.
55+ Creates the runner for either the Ultrafast Grid or the Classic runner (local execution) .
56+ For UFG, concurrency refers to the number of visual checkpoints Applitools will perform in parallel.
4857 Warning: If you have a free account, then concurrency will be limited to 1.
4958 After the test suite finishes execution, closes the batch and report visual differences to the console.
5059 Note that it forces pytest to wait synchronously for all visual checkpoints to complete.
5160 """
52- run = VisualGridRunner (RunnerOptions ().test_concurrency (5 ))
61+
62+ if USE_ULTRAFAST_GRID :
63+ run = VisualGridRunner (RunnerOptions ().test_concurrency (5 ))
64+ else :
65+ run = ClassicRunner ()
66+
5367 yield run
5468 print (run .get_all_test_results ())
5569
@@ -81,16 +95,19 @@ def configuration(api_key: str, batch_info: BatchInfo):
8195 # then the SDK will automatically read the `APPLITOOLS_API_KEY` environment variable to fetch it.
8296 config .set_api_key (api_key )
8397
84- # Add 3 desktop browsers with different viewports for cross-browser testing in the Ultrafast Grid.
85- # Other browsers are also available, like Edge and IE.
86- config .add_browser (800 , 600 , BrowserType .CHROME )
87- config .add_browser (1600 , 1200 , BrowserType .FIREFOX )
88- config .add_browser (1024 , 768 , BrowserType .SAFARI )
98+ # If running tests on the Ultrafast Grid, configure browsers.
99+ if USE_ULTRAFAST_GRID :
100+
101+ # Add 3 desktop browsers with different viewports for cross-browser testing in the Ultrafast Grid.
102+ # Other browsers are also available, like Edge and IE.
103+ config .add_browser (800 , 600 , BrowserType .CHROME )
104+ config .add_browser (1600 , 1200 , BrowserType .FIREFOX )
105+ config .add_browser (1024 , 768 , BrowserType .SAFARI )
89106
90- # Add 2 mobile emulation devices with different orientations for cross-browser testing in the Ultrafast Grid.
91- # Other mobile devices are available, including iOS.
92- config .add_device_emulation (DeviceName .Pixel_2 , ScreenOrientation .PORTRAIT )
93- config .add_device_emulation (DeviceName .Nexus_10 , ScreenOrientation .LANDSCAPE )
107+ # Add 2 mobile emulation devices with different orientations for cross-browser testing in the Ultrafast Grid.
108+ # Other mobile devices are available, including iOS.
109+ config .add_device_emulation (DeviceName .Pixel_2 , ScreenOrientation .PORTRAIT )
110+ config .add_device_emulation (DeviceName .Nexus_10 , ScreenOrientation .LANDSCAPE )
94111
95112 # Return the configuration object
96113 return config
@@ -106,25 +123,31 @@ def configuration(api_key: str, batch_info: BatchInfo):
106123def webdriver (headless : bool ):
107124 """
108125 Creates a WebDriver object for Chrome.
109- Even though this test will run visual checkpoints on different browsers in the Ultrafast Grid,
110- it still needs to run the test one time locally to capture snapshots.
111126 After the test function finishes execution, quits the browser.
112127 """
128+
113129 options = ChromeOptions ()
114130 options .headless = headless
115- driver = Chrome (options = options )
131+
132+ if USE_EXECUTION_CLOUD :
133+ driver = Remote (
134+ command_executor = Eyes .get_execution_cloud_url (),
135+ options = options )
136+ else :
137+ driver = Chrome (options = options )
138+
116139 yield driver
117140 driver .quit ()
118141
119142
120143@pytest .fixture (scope = 'function' )
121144def eyes (
122- runner : VisualGridRunner ,
145+ runner : EyesRunner ,
123146 configuration : Configuration ,
124- webdriver : Chrome ,
147+ webdriver : Remote ,
125148 request : pytest .FixtureRequest ):
126149 """
127- Creates the Applitools Eyes object connected to the VisualGridRunner and set its configuration.
150+ Creates the Applitools Eyes object connected to the runner and set its configuration.
128151 Then, opens Eyes to start visual testing before the test, and closes Eyes at the end of the test.
129152
130153 Opening Eyes requires 4 arguments:
0 commit comments