forked from qxf2/qxf2-page-object-model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
231 lines (187 loc) · 7.91 KB
/
conftest.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
import pytest
import os
from conf import browser_os_name_conf
from utils import post_test_reports_to_slack
from utils.email_pytest_report import Email_Pytest_Report
from utils import Tesults
@pytest.fixture
def browser():
"pytest fixture for browser"
return pytest.config.getoption("-B")
@pytest.fixture
def base_url():
"pytest fixture for base url"
return pytest.config.getoption("-U")
@pytest.fixture
def api_url():
"pytest fixture for base url"
return pytest.config.getoption("-A")
@pytest.fixture
def test_run_id():
"pytest fixture for test run id"
return pytest.config.getoption("-R")
@pytest.fixture
def testrail_flag():
"pytest fixture for test rail flag"
return pytest.config.getoption("-X")
@pytest.fixture
def remote_flag():
"pytest fixture for browserstack/sauce flag"
return pytest.config.getoption("-M")
@pytest.fixture
def browser_version():
"pytest fixture for browser version"
return pytest.config.getoption("-V")
@pytest.fixture
def os_name():
"pytest fixture for os_name"
return pytest.config.getoption("-P")
@pytest.fixture
def os_version():
"pytest fixture for os version"
return pytest.config.getoption("-O")
@pytest.fixture
def slack_flag():
"pytest fixture for sending reports on slack"
return pytest.config.getoption("-S")
@pytest.fixture
def tesults_flag():
"pytest fixture for sending results to tesults"
return pytest.config.getoption("--tesults")
@pytest.fixture
def mobile_os_name():
"pytest fixture for mobile os name"
return pytest.config.getoption("-G")
@pytest.fixture
def mobile_os_version():
"pytest fixture for mobile os version"
return pytest.config.getoption("-H")
@pytest.fixture
def device_name():
"pytest fixture for device name"
return pytest.config.getoption("-I")
@pytest.fixture
def app_package():
"pytest fixture for app package"
return pytest.config.getoption("-J")
@pytest.fixture
def app_activity():
"pytest fixture for app activity"
return pytest.config.getoption("-K")
@pytest.fixture
def device_flag():
"pytest fixture for device flag"
return pytest.config.getoption("-Q")
@pytest.fixture
def email_pytest_report():
"pytest fixture for device flag"
return pytest.config.getoption("--email_pytest_report")
@pytest.fixture
def app_name():
"pytest fixture for app name"
return pytest.config.getoption("-D")
def pytest_terminal_summary(terminalreporter, exitstatus):
"add additional section in terminal summary reporting."
if pytest.config.getoption("-S").lower() == 'y':
post_test_reports_to_slack.post_reports_to_slack()
elif pytest.config.getoption("--email_pytest_report").lower() == 'y':
#Initialize the Email_Pytest_Report object
email_obj = Email_Pytest_Report()
# Send html formatted email body message with pytest report as an attachment
email_obj.send_test_report_email(html_body_flag=True,attachment_flag=True,report_file_path= 'default')
if pytest.config.getoption("--tesults").lower() == 'y':
Tesults.post_results_to_tesults()
def pytest_generate_tests(metafunc):
"test generator function to run tests across different parameters"
if metafunc.config.getoption("-B") == []:
metafunc.config.option.browser = browser_os_name_conf.default_browser
if 'browser' in metafunc.fixturenames:
if metafunc.config.getoption("-M").lower() == 'y':
if metafunc.config.getoption("-B") == ["all"]:
metafunc.parametrize("browser,browser_version,os_name,os_version",
browser_os_name_conf.cross_browser_cross_platform_config)
else:
metafunc.parametrize("browser,browser_version,os_name,os_version",
browser_os_name_conf.default_config_list)
if metafunc.config.getoption("-M").lower() !='y':
if metafunc.config.getoption("-B") == ["all"]:
metafunc.config.option.browser = browser_os_name_conf.local_browsers
metafunc.parametrize("browser",
metafunc.config.option.browser)
def pytest_addoption(parser):
parser.addoption("-B","--browser",
dest="browser",
action="append",
default=[],
help="Browser. Valid options are firefox, ie and chrome")
parser.addoption("-U","--app_url",
dest="url",
default="https://qxf2.com",
help="The url of the application")
parser.addoption("-X","--testrail_flag",
dest="testrail_flag",
default='N',
help="Y or N. 'Y' if you want to report to TestRail")
parser.addoption("-R","--test_run_id",
dest="test_run_id",
default=None,
help="The test run id in TestRail")
parser.addoption("-M","--remote_flag",
dest="remote_flag",
default="N",
help="Run the test in Browserstack/Sauce Lab: Y or N")
parser.addoption("-O","--os_version",
dest="os_version",
action="append",
help="The operating system: xp, 7",
default=[])
parser.addoption("-V","--ver",
dest="browser_version",
action="append",
help="The version of the browser: a whole number",
default=[])
parser.addoption("-P","--os_name",
dest="os_name",
action="append",
help="The operating system: Windows 7, Linux",
default=[])
parser.addoption("-S","--slack_flag",
dest="slack_flag",
default="N",
help="Post the test report on slack channel: Y or N")
parser.addoption("-G","--mobile_os_name",
dest="mobile_os_name",
help="Enter operating system of mobile. Ex: Android, iOS",
default="Android")
parser.addoption("-H","--mobile_os_version",
dest="mobile_os_version",
help="Enter version of operating system of mobile: 8.1.0",
default="6.0")
parser.addoption("-I","--device_name",
dest="device_name",
help="Enter device name. Ex: Emulator, physical device name",
default="Google Nexus 6")
parser.addoption("-J","--app_package",
dest="app_package",
help="Enter name of app package. Ex: bitcoininfo",
default="com.dudam.rohan.bitcoininfo")
parser.addoption("-K","--app_activity",
dest="app_activity",
help="Enter name of app activity. Ex: .MainActivity",
default=".MainActivity")
parser.addoption("-Q","--device_flag",
dest="device_flag",
help="Enter Y or N. 'Y' if you want to run the test on device. 'N' if you want to run the test on emulator.",
default="N")
parser.addoption("--email_pytest_report",
dest="email_pytest_report",
help="Email pytest report: Y or N",
default="N")
parser.addoption("--tesults",
dest="tesults_flag",
default='N',
help="Y or N. 'Y' if you want to report results with Tesults")
parser.addoption("-D","--app_name",
dest="app_name",
help="Enter application name to be uploaded.Ex:Bitcoin Info_com.dudam.rohan.bitcoininfo.apk.",
default="Bitcoin Info_com.dudam.rohan.bitcoininfo.apk")