This repository has been archived by the owner on Nov 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
conftest.py
280 lines (203 loc) · 7.36 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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
"""Test fixtures for selenium UAT for adventurer's codex."""
import logging
import sys
import time
from time import gmtime, strftime
import pytest
import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.remote_connection import LOGGER
from selenium.webdriver.support import expected_conditions as EC # noqa
from selenium.webdriver.support.ui import WebDriverWait
from components.core.character import wizard
from components.core.dm.encounter_add_edit_modal import EncounterAddEditModal
from components.core.dm.encounter_list import EncounterList
from components.core.dm.tabs import DMTabs
from components.core.dm.wizard import TellUsAStory
from components.core.general.api import LoginForm
from components.core.general.new_character_campaign import NewCharacterCampaign
from factories.core.dm.encounter import EncounterAddEditModalFactory
LOGGER.setLevel(logging.WARNING)
# This is a required setting
DEFAULT_WAIT_TIME = 15
def pytest_addoption(parser):
"""Command line parameters."""
parser.addoption('--web_driver', action='store', default='chrome')
parser.addoption('--usr', action='store', default=None)
parser.addoption('--pwd', action='store', default=None)
parser.addoption('--token', action='store', default=None)
parser.addoption('--opera_binary_path', action='store')
parser.addoption(
'--url',
action='store',
default='https://nightly.adventurerscodex.com'
)
@pytest.fixture
def web_driver(request):
"""Return command line argument."""
return request.config.getoption('--web_driver')
@pytest.fixture
def opera_binary_path(request):
"""Return command line argument."""
return request.config.getoption('--opera_binary_path')
@pytest.fixture
def url(request):
"""Return command line argument."""
return request.config.getoption('--url')
@pytest.fixture(scope='function')
def browser(request, web_driver, opera_binary_path, url):
"""Return selenium webdriver chrome instance."""
driver = None
if web_driver.lower() == 'chrome':
driver = webdriver.Chrome()
elif web_driver.lower() == 'firefox':
driver = webdriver.Firefox()
elif web_driver.lower() == 'safari':
driver = webdriver.Safari()
elif web_driver.lower() == 'opera':
if not opera_binary_path:
raise Exception('Opera binary path required: --opera_binary_path')
options = webdriver.ChromeOptions()
options.binary_location = opera_binary_path
driver = webdriver.Opera(options=options)
driver.get(url)
def close_browser():
driver.quit()
request.addfinalizer(close_browser)
return driver
def pytest_csv_register_columns(columns):
"""Add custom columns to csv reporting."""
browser = None
for arg in sys.argv:
if '--web_driver' in arg:
arg_string = arg.split('=')
try:
browser = arg_string[1]
except IndexError:
pass
columns['browser'] = browser
columns['created_at'] = strftime('%Y-%m-%d %H:%M:%S', gmtime())
@pytest.fixture
def usr(request):
"""Return command line argument."""
return request.config.getoption('--usr')
@pytest.fixture
def pwd(request):
"""Return command line argument."""
return request.config.getoption('--pwd')
@pytest.fixture(scope='function')
def login(browser, usr, pwd):
"""User logs in."""
print('As a User, I am able to login')
login = LoginForm(browser)
login.username = usr
login.password = pwd
login.submit.click()
@pytest.fixture
def token(request):
"""Return command line argument."""
return request.config.getoption('--token')
@pytest.fixture(scope='function')
def dm_wizard(delete, login, browser):
"""Navigate through the dm wizard."""
wizard_main = NewCharacterCampaign(browser)
tell_us_a_story = TellUsAStory(browser)
WebDriverWait(browser, DEFAULT_WAIT_TIME).until(
EC.element_to_be_clickable(
(By.ID, wizard_main.get_started_id)
)
)
wizard_main.get_started.click()
WebDriverWait(browser, DEFAULT_WAIT_TIME).until(
EC.element_to_be_clickable(
(By.ID, wizard_main.dm_id)
)
)
wizard_main.dm.click()
WebDriverWait(browser, DEFAULT_WAIT_TIME).until(
EC.element_to_be_clickable(
(By.ID, wizard_main.next_id)
)
)
wizard_main.next_.click()
tell_us_a_story.campaign_name = 'Test Campaign'
tell_us_a_story.player_name = 'Automated Testing Bot.'
wizard_main.finish.click()
@pytest.fixture(scope='function')
def encounter_all_sections(browser):
"""Will create an encounter with all sections."""
tabs = DMTabs(browser)
tabs.encounters.click()
encounter_list = EncounterList(browser)
encounter_list.add_plus_icon.click()
encounter_add_edit_modal = EncounterAddEditModal(browser)
stub = EncounterAddEditModalFactory.stub()
encounter_add_edit_modal.encounter_name = stub.encounter_name
encounter_add_edit_modal.location = stub.location
encounter_add_edit_modal.environment.click()
encounter_add_edit_modal.maps_and_images.click()
encounter_add_edit_modal.points_of_interest.click()
encounter_add_edit_modal.non_player_characters.click()
encounter_add_edit_modal.monsters.click()
encounter_add_edit_modal.treasure.click()
encounter_add_edit_modal.done.click()
@pytest.fixture(scope='function')
def delete(token):
"""Delete legacy characters and campaigns."""
headers = {
'Authorization': 'Bearer {}'.format(token),
}
response = requests.get(
'https://nightly.adventurerscodex.com/api/core/',
headers=headers
)
response.raise_for_status()
results = response.json()
characters_campaigns = results.get('results')
if characters_campaigns:
for asset in characters_campaigns:
url = asset.get('url')
if url:
response = requests.delete(url=url, headers=headers)
response.raise_for_status()
time.sleep(1)
@pytest.fixture(scope='function')
def player_wizard(delete, login, browser):
"""Navigate through the player wizard."""
wizard_main = NewCharacterCampaign(browser)
who_are_you = wizard.WhoAreYou(browser)
ability_scores = wizard.AbilityScoresManual(browser)
WebDriverWait(browser, DEFAULT_WAIT_TIME).until(
EC.element_to_be_clickable(
(By.ID, wizard_main.get_started_id)
)
)
wizard_main.get_started.click()
WebDriverWait(browser, DEFAULT_WAIT_TIME).until(
EC.element_to_be_clickable(
(By.ID, wizard_main.player_id)
)
)
wizard_main.player.click()
WebDriverWait(browser, DEFAULT_WAIT_TIME).until(
EC.element_to_be_clickable(
(By.ID, wizard_main.next_id)
)
)
wizard_main.next_.click()
who_are_you.character_name = 'Test Char'
who_are_you.player_name = 'Automated Testing Bot.'
WebDriverWait(browser, DEFAULT_WAIT_TIME).until(
EC.element_to_be_clickable(
(By.ID, wizard_main.next_id)
)
)
wizard_main.next_.click()
ability_scores.strength = '18'
ability_scores.dexterity = '18'
ability_scores.constitution = '18'
ability_scores.intelligence = '18'
ability_scores.wisdom = '18'
ability_scores.charisma = '18'
wizard_main.finish.click()