/
test_pytest_example_functions.py
103 lines (78 loc) · 2.84 KB
/
test_pytest_example_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"""
Created on Aug 30, 2015
@author: Mikhail
"""
import pytest
from .home_page_functionality import HomePage
__author__ = 'Mikhail'
yandex_title = "Yandex"
yandex_url = "https://www.yandex.com/"
google_title = "Google"
google_url = "http://www.google.com"
page = HomePage()
url = None
# This method will be called before execution of all tests
@pytest.fixture(scope="module")
def setup_module(request):
print "Py.test set-up module method"
page.start_browser()
# This method will be called after execution of all tests
def fin():
global page
print "Py.test tear-down module method"
page.stop_browser()
request.addfinalizer(fin)
# This method will be called before execution of special tests
@pytest.fixture
def setup_yandex(request):
global url, page
print "Py.test set-up method for Yandex"
url = yandex_url
if page.number_of_opened_windows() == 0:
print "Start new browser instance"
page.start_browser()
# This method will be called after execution of the test
def fin():
global page
print "Py.test tear-down method"
page.close_browser_window()
request.addfinalizer(fin)
# This method will be called before execution of special tests
@pytest.fixture
def setup_google(request):
global url, page
print "Py.test set-up method for Google"
url = google_url
if page.number_of_opened_windows() == 0:
print "Start new browser instance"
page.start_browser()
# This method will be called after execution of the test
def fin():
global page
print "Py.test tear-down method"
page.close_browser_window()
request.addfinalizer(fin)
def test_CorrectCheckTitleYandex(setup_yandex):
global url, page
expected_title = yandex_title
actual_title = page.open_web_page(url)
assert expected_title == actual_title, "Title is incorrect. Expected '{}', Actual '{}'".format(expected_title,
actual_title)
def test_IncorrectCheckTitleYandex(setup_yandex):
global url, page
expected_title = google_title
actual_title = page.open_web_page(url)
assert expected_title == actual_title, "Title is incorrect. Expected '{}', Actual '{}'".format(expected_title,
actual_title)
def test_CorrectCheckTitleGoogle(setup_google):
global url, page
expected_title = google_title
actual_title = page.open_web_page(url)
assert expected_title, actual_title
def test_IncorrectCheckTitleGoogle(setup_google):
global url, page
expected_title = yandex_title
actual_title = page.open_web_page(url)
assert expected_title == actual_title
if __name__ == "__main__":
pytest.main(args=['-v', '-s'])