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
|
#
# Copyright (c) 2014 ThoughtWorks, Inc.
#
# Pixelated is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pixelated is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
from page_objects import SignUpPage, LeapLoginPage
from selenium import webdriver
from selenium.webdriver.common.by import By
from steps.common import get_invite_code, RandomUser
from steps import behave_testuser, behave_password, delete_soledad_server_db, delete_soledad_client_db, signup_url
def before_all(context):
set_browser(context)
create_behave_user(context)
context.random_user = RandomUser
def after_step(context, step):
screenshot_filename = '{step_name}.png'
if step.status == 'failed':
take_screenshot(context,
screenshot_filename.format(step_name=step.name))
log_browser_console(context, step)
save_page_source(context, step)
def after_scenario(context, scenario):
context.browser.delete_all_cookies()
def after_all(context):
_delete_user(context, behave_testuser(), behave_password())
_delete_user(context, context.random_user.username, context.random_user.password)
if hasattr(context, 'browser'):
context.browser.quit()
def _delete_user(context, username, password):
user_id = LeapLoginPage(context).destroy_account(username, password)
delete_soledad_server_db(user_id, username)
delete_soledad_client_db(user_id)
def save_page_source(context, step):
page_source_filename = '{step_name}.html'.format(step_name=step.name)
with open(page_source_filename, 'w') as page_source:
page_source.write(context.browser.page_source)
def log_browser_console(context, step):
console_log_filename = '{step_name}.log'.format(step_name=step.name)
with open(console_log_filename, 'w') as console_log_file:
line = '{time} {level}: {message}\n'
log_lines = []
for log in context.browser.get_log('browser'):
log_lines.append(line.format(time=log['timestamp'],
level=log['level'],
message=log['message']))
console_log_file.writelines(log_lines)
def take_screenshot(context, filename):
context.browser.save_screenshot(filename)
def set_browser(context):
# context.browser = webdriver.Firefox()
#context.browser = webdriver.Chrome()
context.browser = webdriver.PhantomJS(service_args=['--ignore-ssl-errors=yes'])
context.browser.set_window_size(1280, 1024)
context.browser.implicitly_wait(10)
context.browser.set_page_load_timeout(60)
def create_behave_user(context):
username = behave_testuser()
password = behave_password()
context.browser.get(signup_url())
signup_page = SignUpPage(context)
signup_page.wait_until_element_is_visible_by_locator((By.CSS_SELECTOR, 'input#srp_username'))
signup_page.enter_username(username)
signup_page.enter_password(password)
signup_page.enter_password_confirmation(password)
signup_page.enter_invite_code(get_invite_code())
signup_page.click_signup_button()
# context.browser.quit()
|