/
standard_pom_tests.py
170 lines (142 loc) · 6.79 KB
/
standard_pom_tests.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
import unittest
import pytest
from tests.pages.front import FrontPage
from tests.pages.admin import AdminPage
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.firefox.options import Options
import os
import pdb
import sys
import time
from datetime import date, datetime, timedelta
from faker import Faker
from configparser import ConfigParser
from faker.providers import BaseProvider
from tests.my_contact_provider import MyContactProvider
from tests.booker_api import BookerAPI
class ContactFormTestCase(unittest.TestCase):
def setUp(self):
options = Options()
self.driver = webdriver.Firefox(options=options)
self.driver.implicitly_wait(15)
self.driver.maximize_window()
self.booker_api = BookerAPI(base_url=BASE_URL,
username=BOOKER_API_USERNAME, password=BOOKER_API_PASSWORD)
def tearDown(self):
self.driver.quit()
@pytest.mark.ch1
def test_contact_form_successful(self):
page = FrontPage(self.driver, BASE_URL)
page.open()
page.contact_form.wait_for_region_to_load()
name = fake.valid_name()
email = fake.valid_email()
phone = fake.valid_phone()
subject = fake.valid_subject()
description = fake.valid_description()
page.contact_form.fill_contact_data(
name=name, email=email, phone=phone, subject=subject, description=description)
self.assertEqual(page.contact_form.contact_feedback_message,
f"Thanks for getting in touch {name}!\nWe'll get back to you about\n{subject}\nas soon as possible.")
@pytest.mark.ch1n
def test_contact_form_unsuccessfail_invalid_name(self):
page = FrontPage(self.driver, BASE_URL)
page.open()
page.contact_form.wait_for_region_to_load()
name = fake.invalid_name()
email = fake.valid_email()
phone = fake.valid_phone()
subject = fake.valid_subject()
description = fake.valid_description()
page.contact_form.fill_contact_data(
name=name, email=email, phone=phone, subject=subject, description=description)
self.assertTrue(page.contact_form.is_error_message_present,
"error message must be present")
@pytest.mark.ch2
def test_contact_message_received_in_backoffice(self):
page = FrontPage(self.driver, BASE_URL)
page.open()
page.contact_form.wait_for_region_to_load()
name = fake.valid_name()
email = fake.valid_email()
phone = fake.valid_phone()
subject = fake.valid_subject()
description = fake.valid_description()
page.contact_form.fill_contact_data(
name=name, email=email, phone=phone, subject=subject, description=description)
page.click_admin_panel()
page = AdminPage(self.driver)
page.authenticate_with_valid_credentials()
self.assertTrue(page.rooms.is_rooms_section_open,
"rooms section is not opened")
page.click_inbox()
self.assertTrue(page.inbox.is_message_section_open,
"message section is not opened")
page.inbox.find_and_open_unread_message(name=name, subject=subject)
self.assertEqual(page.inbox.message_detail_name,
f"From: {name}", "message's name doesnt match")
self.assertEqual(page.inbox.message_detail_email,
f"Email: {email}", "message's email doesnt match")
self.assertEqual(page.inbox.message_detail_phone,
f"Phone: {phone}", "message's phone doesnt match")
self.assertEqual(page.inbox.message_detail_subject, subject,
"message's subject doesnt match")
self.assertEqual(page.inbox.message_detail_description,
description, "message's description doesnt match")
@pytest.mark.ch3
def test_book_successful(self):
page = FrontPage(self.driver, BASE_URL)
page.open()
# click on first room
room = page.rooms.available_rooms()[0]
page.rooms.click_book_room(room)
# book some nights, starting today
today = date.today()
start_date = today
total_nights = 2
end_date = today+timedelta(days=total_nights)
page.rooms.select_calendar_dates(
start_day=start_date.day, end_day=end_date.day)
# check displayed information on the total nights and price, before submitting
price_per_night = self.booker_api.get_rooms()[0]['roomPrice']
total_price = price_per_night*total_nights
page.rooms.select_calendar_dates(
start_day=start_date.day, end_day=end_date.day)
for selection_block in page.rooms.get_date_selection_blocks():
self.assertEqual(selection_block.text,
f'{total_nights} night(s) - £{total_price}')
# submit booking request
start_date_str = start_date.isoformat()
end_date_str = end_date.isoformat()
first_name = fake.first_name()
last_name = fake.last_name()
email = fake.valid_email()
phone = fake.valid_phone()
page.rooms.fill_booking_contact_data(
first_name=first_name, last_name=last_name, email=email, phone=phone)
page.rooms.click_submit_booking()
# check confirmation message and stored booking on system
last_booking = self.booker_api.get_bookings()[-1]
self.assertEqual(page.rooms.booking_confirmed_message,
f"Booking Successful!\nCongratulations! Your booking has been confirmed for:\n{start_date_str} - {end_date_str}\nClose")
self.assertTrue(last_booking['firstname'] == first_name and last_booking['lastname'] == last_name and last_booking['bookingdates']['checkin']
== start_date_str and last_booking['bookingdates']['checkout'] == end_date_str, f"booking not found (last_booking={last_booking}")
################
HEADLESS = False
config = ConfigParser()
config.read('config.ini')
BASE_URL = os.environ.get("BASE_URL", config.get('app', 'base_url'))
BOOKER_API_USERNAME = config.get('app', 'booker_api_username')
BOOKER_API_PASSWORD = config.get('app', 'booker_api_password')
debugger = pdb.Pdb(stdout=sys.stdout)
fake = Faker()
fake.add_provider(MyContactProvider)
# Enforce a specific seed; there are currently some limitations in both AltWalker and GraphWalker though
# seed works in GW 4.3 but AltWaker doesn't have a way to enforce it or obtain it
seed = os.environ.get("SEED", config.getint('other', 'seed'))
print(f'seed: {seed}')
Faker.seed(int(seed))