Skip to content

Commit 0a9517b

Browse files
author
Gaurav Singh
committed
Moved from unittest to pytest as a test framework
1 parent 4761eaf commit 0a9517b

File tree

5 files changed

+151
-76
lines changed

5 files changed

+151
-76
lines changed

Pipfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ verify_ssl = true
77

88
[packages]
99
eyes-selenium = "*"
10+
pytest = "*"
1011

1112
[requires]
12-
python_version = "3.7"
13+
python_version = "3.7.4"

Pipfile.lock

Lines changed: 102 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

automation/tests/base_test.py

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
from automation.tests.base_test import BaseTest
1+
from automation.tests.conftest import *
22

33

4-
class HelloWorldTest(BaseTest):
5-
6-
def test_hello_world(self):
7-
self.setup(test_name=self._testMethodName)
8-
9-
self.validate_window(tag='hello_world')
10-
self.driver.find_element_by_css_selector('button').click()
11-
self.validate_window('click_me')
12-
13-
self.teardown()
4+
def test_hello_world(driver, eyes):
5+
open_eyes(driver, eyes)
6+
validate_window(eyes, tag='hello_world')
7+
driver.find_element_by_css_selector('button').click()
8+
validate_window(eyes, 'click_me')

automation/tests/conftest.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import pytest
2+
from applitools.selenium import Eyes
3+
from selenium import webdriver
4+
5+
from automation.config.base import APPLITOOLS_API_KEY
6+
7+
APP_NAME = 'hello_world'
8+
9+
10+
@pytest.fixture(scope='function')
11+
def driver():
12+
driver = webdriver.Chrome()
13+
driver.get('https://applitools.com/helloworld')
14+
yield driver
15+
driver.quit()
16+
17+
18+
@pytest.fixture(scope='function')
19+
def eyes(driver):
20+
eyes = initialize_eyes()
21+
yield eyes
22+
eyes.close()
23+
24+
25+
def initialize_eyes():
26+
eyes = Eyes()
27+
eyes.api_key = APPLITOOLS_API_KEY
28+
return eyes
29+
30+
31+
def open_eyes(driver, eyes):
32+
eyes.open(driver, APP_NAME, test_name=get_test_name())
33+
34+
35+
def validate_window(eyes, tag):
36+
eyes.check_window(tag)
37+
38+
39+
def get_test_name():
40+
import inspect
41+
return inspect.stack()[2].function

0 commit comments

Comments
 (0)