-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage_objects.py
More file actions
162 lines (130 loc) · 5.21 KB
/
Copy pathpage_objects.py
File metadata and controls
162 lines (130 loc) · 5.21 KB
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
from appium.webdriver.common.mobileby import MobileBy
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException, TimeoutException
from testdata import TestData
class BaseTest:
"""
Helping functions
"""
def __init__(self, driver):
self.driver = driver
def do_wait_and_click(self, loc, sec=5):
WebDriverWait(self.driver.instance, sec).until(EC.visibility_of_element_located(loc)).click()
def get_element_text(self, loc, sec=5):
elem_txt = WebDriverWait(self.driver.instance, sec).until(EC.visibility_of_element_located(loc)).text
return elem_txt
def do_send_keys(self, loc, text, sec=5):
WebDriverWait(self.driver.instance, sec).until(EC.visibility_of_element_located(loc)).send_keys(text)
def do_clear(self, loc, sec=5):
WebDriverWait(self.driver.instance, sec).until(EC.visibility_of_element_located(loc)).clear()
def is_visible(self, loc, sec=5):
el = False
try:
el = WebDriverWait(self.driver.instance, sec).until(EC.visibility_of_element_located(loc)).is_displayed()
except (TimeoutException, NoSuchElementException):
return bool(el)
return bool(el)
class MainScreen(BaseTest, TestData):
new_note_btn = (MobileBy.ACCESSIBILITY_ID, "New list")
whole_note = (MobileBy.ID, "com.google.android.keep:id/browse_note_interior_content")
empty_view = (MobileBy.XPATH,
"//*[@resource-id='com.google.android.keep:id/empty_view_text']")
added_note_title = (MobileBy.ID, "com.google.android.keep:id/index_note_title")
search_bar = (MobileBy.ID, "com.google.android.keep:id/toolbar")
search_query = (MobileBy.ID, "com.google.android.keep:id/search_actionbar_query_text")
get_started = (MobileBy.ID, "com.google.android.keep:id/skip_welcome")
no_thanks = (MobileBy.XPATH, "//android.widget.Button[@text='No, thanks']")
def __init__(self, driver):
self.driver = driver
def get_started_btn(self):
"""
Clicks on Get started button if visible
"""
if self.is_visible(self.get_started) is True:
self.do_wait_and_click(self.get_started)
else:
pass
def google_offer_skip(self):
"""
Skips Google offer bar if visible
"""
if self.is_visible(self.no_thanks) is True:
self.do_wait_and_click(self.no_thanks)
else:
pass
def is_empty(self):
"""
Verifies if main screen is empty - without any notes
"""
assert self.is_visible(self.empty_view) is True
def add_a_note(self):
"""
Adds new note
"""
self.do_wait_and_click(self.new_note_btn)
def search_a_note(self):
"""
Searches for a note with chosen title
"""
self.do_wait_and_click(self.search_bar)
self.do_send_keys(self.search_query, TestData.title)
assert self.is_visible(self.added_note_title) is True
def search_a_note_no_result(self):
"""
Searches for a note with incorrect title
"""
self.do_wait_and_click(self.search_bar)
self.do_send_keys(self.search_query, TestData.incorrect_title)
assert self.is_visible(self.empty_view) is True
def open_a_note(self):
"""
Opens a note
"""
self.do_wait_and_click(self.added_note_title)
def verify_if_note_exist(self, title):
"""
Verifies if note with chosen title exists on the main scene
"""
title_text = self.get_element_text(self.added_note_title)
assert title_text == title
class NoteScreen(MainScreen):
note_title = (MobileBy.ID, "com.google.android.keep:id/editable_title")
note_content = (MobileBy.ID, "com.google.android.keep:id/description")
note_edit_text = (MobileBy.ID, "com.google.android.keep:id/edit_note_text")
note_checklist_item = (MobileBy.ACCESSIBILITY_ID, "New list")
arrow_back = (MobileBy.ACCESSIBILITY_ID, "Navigate up")
three_dots = (MobileBy.ACCESSIBILITY_ID, "Action")
delete = (MobileBy.XPATH, "//android.widget.LinearLayout[1]/android.widget.ImageView")
def __init__(self, driver):
self.driver = driver
def add_title(self):
"""
Adds title to a note
"""
self.do_wait_and_click(self.note_title)
self.do_send_keys(self.note_title, TestData.title)
def add_note_content(self):
"""
Adds content to a note
"""
self.do_wait_and_click(self.note_edit_text)
self.do_send_keys(self.note_edit_text, TestData.content)
def edit_note_title(self):
"""
Edits a note's title
"""
self.do_clear(self.note_title)
self.do_send_keys(self.note_title, TestData.edited_title)
def delete_a_note(self):
"""
Deletes a note
"""
self.do_wait_and_click(self.three_dots)
self.do_wait_and_click(self.delete)
def go_back_to_main(self):
"""
Goes back to the main screen
"""
self.do_wait_and_click(self.arrow_back)
assert self.is_visible(self.new_note_btn) is True