Skip to content

Commit 5593095

Browse files
Merge pull request #8 from applitools/combined
Combined Classic runner, UFG, and XCloud into one branch in one repo
2 parents f9a0389 + 39fe74e commit 5593095

File tree

1 file changed

+47
-32
lines changed

1 file changed

+47
-32
lines changed

tests/conftest.py

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,19 @@
1212
import pytest
1313

1414
from 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+
# These could be set by environment variables or other input mechanisms.
22+
# They are hard-coded here to keep the example project simple.
23+
# --------------------------------------------------------------------------------
24+
25+
USE_ULTRAFAST_GRID = True
26+
USE_EXECUTION_CLOUD = False
27+
HEADLESS = False
1628

1729

1830
# --------------------------------------------------------------------------------
@@ -29,27 +41,21 @@ def api_key():
2941
return os.getenv('APPLITOOLS_API_KEY')
3042

3143

32-
@pytest.fixture(scope='session')
33-
def headless():
34-
"""
35-
Reads the headless mode setting from an environment variable.
36-
Uses headless mode for Continuous Integration (CI) execution.
37-
Uses headed mode for local development.
38-
"""
39-
h = os.getenv('HEADLESS', default='false')
40-
return h.lower() == 'true'
41-
42-
4344
@pytest.fixture(scope='session')
4445
def runner():
4546
"""
46-
Creates the runner for the Ultrafast Grid.
47-
Concurrency refers to the number of visual checkpoints Applitools will perform in parallel.
47+
Creates the runner for either the Ultrafast Grid or the Classic runner (local execution).
48+
For UFG, concurrency refers to the number of visual checkpoints Applitools will perform in parallel.
4849
Warning: If you have a free account, then concurrency will be limited to 1.
4950
After the test suite finishes execution, closes the batch and report visual differences to the console.
5051
Note that it forces pytest to wait synchronously for all visual checkpoints to complete.
5152
"""
52-
run = VisualGridRunner(RunnerOptions().test_concurrency(5))
53+
54+
if USE_ULTRAFAST_GRID:
55+
run = VisualGridRunner(RunnerOptions().test_concurrency(5))
56+
else:
57+
run = ClassicRunner()
58+
5359
yield run
5460
print(run.get_all_test_results())
5561

@@ -81,16 +87,19 @@ def configuration(api_key: str, batch_info: BatchInfo):
8187
# then the SDK will automatically read the `APPLITOOLS_API_KEY` environment variable to fetch it.
8288
config.set_api_key(api_key)
8389

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)
90+
# If running tests on the Ultrafast Grid, configure browsers.
91+
if USE_ULTRAFAST_GRID:
8992

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)
93+
# Add 3 desktop browsers with different viewports for cross-browser testing in the Ultrafast Grid.
94+
# Other browsers are also available, like Edge and IE.
95+
config.add_browser(800, 600, BrowserType.CHROME)
96+
config.add_browser(1600, 1200, BrowserType.FIREFOX)
97+
config.add_browser(1024, 768, BrowserType.SAFARI)
98+
99+
# Add 2 mobile browsers with different orientations for cross-browser testing in the Ultrafast Grid.
100+
# Other mobile devices are available.
101+
config.add_browser(IosDeviceInfo(IosDeviceName.iPhone_11, ScreenOrientation.PORTRAIT))
102+
config.add_browser(ChromeEmulationInfo(DeviceName.Nexus_10, ScreenOrientation.LANDSCAPE))
94103

95104
# Return the configuration object
96105
return config
@@ -103,28 +112,34 @@ def configuration(api_key: str, batch_info: BatchInfo):
103112
# --------------------------------------------------------------------------------
104113

105114
@pytest.fixture(scope='function')
106-
def webdriver(headless: bool):
115+
def webdriver():
107116
"""
108117
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.
111118
After the test function finishes execution, quits the browser.
112119
"""
120+
113121
options = ChromeOptions()
114-
options.headless = headless
115-
driver = Chrome(options=options)
122+
options.headless = HEADLESS
123+
124+
if USE_EXECUTION_CLOUD:
125+
driver = Remote(
126+
command_executor=Eyes.get_execution_cloud_url(),
127+
options=options)
128+
else:
129+
driver = Chrome(options=options)
130+
116131
yield driver
117132
driver.quit()
118133

119134

120135
@pytest.fixture(scope='function')
121136
def eyes(
122-
runner: VisualGridRunner,
137+
runner: EyesRunner,
123138
configuration: Configuration,
124-
webdriver: Chrome,
139+
webdriver: Remote,
125140
request: pytest.FixtureRequest):
126141
"""
127-
Creates the Applitools Eyes object connected to the VisualGridRunner and set its configuration.
142+
Creates the Applitools Eyes object connected to the runner and set its configuration.
128143
Then, opens Eyes to start visual testing before the test, and closes Eyes at the end of the test.
129144
130145
Opening Eyes requires 4 arguments:

0 commit comments

Comments
 (0)