Skip to content

Commit 0c4b823

Browse files
Redeveloped the code
1 parent 2cb0ec6 commit 0c4b823

File tree

4 files changed

+99
-95
lines changed

4 files changed

+99
-95
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ to your [account's API key](https://applitools.com/tutorials/getting-started/set
3737
and then run:
3838

3939
```
40-
python3 -m pytest tests
40+
python3 -m pytest -s -v tests
4141
```
4242

4343
**For full instructions on running this project, take our

tests/conftest.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import os
2+
import pytest
3+
4+
from applitools.selenium import *
5+
from selenium.webdriver import Chrome, ChromeOptions
6+
from webdriver_manager.chrome import ChromeDriverManager
7+
from selenium.webdriver.chrome.service import Service
8+
9+
10+
@pytest.fixture(scope='session')
11+
def api_key():
12+
return os.getenv('APPLITOOLS_API_KEY')
13+
14+
15+
@pytest.fixture(scope='session')
16+
def headless():
17+
h = os.getenv('HEADLESS', default='false')
18+
return h.lower() == 'true'
19+
20+
21+
@pytest.fixture(scope='session')
22+
def runner():
23+
run = VisualGridRunner(RunnerOptions().test_concurrency(5))
24+
yield run
25+
print(run.get_all_test_results())
26+
27+
28+
@pytest.fixture(scope='session')
29+
def batch_info():
30+
return BatchInfo("Example: Selenium Python pytest with the Ultrafast Grid")
31+
32+
33+
@pytest.fixture(scope='session')
34+
def configuration(api_key: str, batch_info: BatchInfo):
35+
config = Configuration()
36+
config.set_batch(batch_info)
37+
config.set_api_key(api_key)
38+
config.add_browser(800, 600, BrowserType.CHROME)
39+
config.add_browser(1600, 1200, BrowserType.FIREFOX)
40+
config.add_browser(1024, 768, BrowserType.SAFARI)
41+
config.add_device_emulation(DeviceName.Pixel_2, ScreenOrientation.PORTRAIT)
42+
config.add_device_emulation(DeviceName.Nexus_10, ScreenOrientation.LANDSCAPE)
43+
return config
44+
45+
46+
@pytest.fixture(scope='session')
47+
def chromedriver_service():
48+
path = ChromeDriverManager().install()
49+
return Service(path)
50+
51+
52+
@pytest.fixture(scope='function')
53+
def webdriver(headless: bool, chromedriver_service: Service):
54+
options = ChromeOptions()
55+
options.headless = headless
56+
driver = Chrome(service=chromedriver_service, options=options)
57+
yield driver
58+
driver.quit()
59+
60+
61+
@pytest.fixture(scope='function')
62+
def eyes(
63+
runner: VisualGridRunner,
64+
configuration: Configuration,
65+
webdriver: Chrome,
66+
request: pytest.FixtureRequest):
67+
68+
eyes = Eyes(runner)
69+
eyes.set_configuration(configuration)
70+
eyes.open(
71+
driver=webdriver,
72+
app_name='ACME Bank Web App',
73+
test_name=request.node.name,
74+
viewport_size=RectangleSize(1024, 768))
75+
76+
yield eyes
77+
eyes.close_async()

tests/test_acme_bank.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from applitools.selenium import Eyes, Target
2+
from selenium.webdriver import Chrome
3+
from selenium.webdriver.common.by import By
4+
5+
6+
def test_log_into_bank_account(webdriver: Chrome, eyes: Eyes) -> None:
7+
8+
# Load the login page.
9+
webdriver.get("https://demo.applitools.com")
10+
11+
# Verify the full login page loaded correctly.
12+
eyes.check(Target.window().fully().with_name("Login page"))
13+
14+
# Perform login.
15+
webdriver.find_element(By.ID, "username").send_keys("applibot")
16+
webdriver.find_element(By.ID, "password").send_keys("I<3VisualTests")
17+
webdriver.find_element(By.ID, "log-in").click()
18+
19+
# Verify the full main page loaded correctly.
20+
# This snapshot uses LAYOUT match level to avoid differences in closing time text.
21+
eyes.check(Target.window().fully().with_name("Main page").layout())

tests/ultrafastgrid_tutorial.py

Lines changed: 0 additions & 94 deletions
This file was deleted.

0 commit comments

Comments
 (0)