Skip to content

Commit dae8df2

Browse files
author
Gaurav Singh
committed
Chapter 10: Analyzing test results via applitools eyes test manager
Change log: 1. Added an apps.py file to hold app and urls for different sections 2. Updated validate_window to accept MatchLevel from the caller 3. Added a TestInfo class to hold details required to setup the tests 4. Added a function scope fixture setup_test which accepts TestInfo method from the tests and does manager and app setup 5. Dummy pdf file from pdf test added.
1 parent 00c5fe2 commit dae8df2

File tree

6 files changed

+52
-5
lines changed

6 files changed

+52
-5
lines changed

automation/config/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
APP_URLS = {
2+
'the-internet': {
3+
'dynamic_content_for_a_section': 'https://the-internet.herokuapp.com/dynamic_content?with_content=static',
4+
'tables': 'https://the-internet.herokuapp.com/tables'
5+
}
6+
}

automation/core/eyes_manager.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22

3-
from applitools.common import BatchInfo
3+
from applitools.common import BatchInfo, MatchLevel
44
from applitools.selenium import Eyes
55

66
from automation.config.base import APPLITOOLS_API_KEY
@@ -31,10 +31,12 @@ def set_batch(self, batch_name):
3131
batch_info = BatchInfo(batch_name)
3232
self.eyes.batch = batch_info
3333

34-
def validate_window(self, tag=None, full_page=False):
34+
def validate_window(self, tag=None, full_page=False,
35+
match_level=MatchLevel.STRICT):
3536
if full_page:
3637
self.eyes.force_full_page_screenshot = True
3738

39+
self.eyes.match_level = match_level
3840
self.eyes.check_window(tag=tag)
3941

4042
def validate_element(self, element, tag=None):

automation/core/test_helper.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class TestInfo:
2+
def __init__(self, app_name, app_under_test, batch_name=None):
3+
self.app_name = app_name
4+
self.app_under_test = app_under_test
5+
self.batch_name = batch_name

automation/resources/INV0001.pdf

13.6 KB
Binary file not shown.
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
from automation.tests.conftest import validate_window
1+
import pytest
22

3+
from automation.config.apps import APP_URLS
4+
from automation.core.test_helper import TestInfo
35

4-
def test_match_level_layout(driver, eyes):
5-
validate_window(driver, eyes)
6+
APP = 'the-internet'
7+
test_info = TestInfo(APP, APP_URLS[APP]['dynamic_content_for_a_section'])
68

9+
10+
@pytest.mark.parametrize('setup_test', [test_info], indirect=True)
11+
def test_dynamic_content(setup_test, manager):
12+
manager.validate_window()

automation/tests/conftest.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,31 @@ def driver():
1515
driver = webdriver.Chrome()
1616
yield driver
1717
driver.quit()
18+
19+
20+
@pytest.fixture(scope='function')
21+
def setup_test(request, manager):
22+
test_info = request.param
23+
24+
_set_batch_and_app_in_manager(manager, test_info)
25+
_launch_app_and_open_eyes(manager, request, test_info)
26+
27+
yield manager
28+
manager.close_eyes()
29+
30+
31+
def _launch_app_and_open_eyes(manager, request, test_info):
32+
driver = manager.driver
33+
driver.get(test_info.app_under_test)
34+
driver.maximize_window()
35+
36+
test_name = request.function.__name__
37+
manager.open_eyes(test_name)
38+
39+
40+
def _set_batch_and_app_in_manager(manager, test_info):
41+
batch_name = test_info.batch_name
42+
43+
if batch_name:
44+
manager.set_batch(batch_name)
45+
manager.set_app_name(test_info.app_name)

0 commit comments

Comments
 (0)