Repository navigation
Expand file tree
/
Copy pathBookCollectionByJulioTesting.py
More file actions
245 lines (217 loc) · 11 KB
/
Copy pathBookCollectionByJulioTesting.py
File metadata and controls
245 lines (217 loc) · 11 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
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
from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import InvalidSessionIdException
import unittest
import time
capabilities = dict(
platformName='Android',
automationName='uiautomator2',
deviceName='emulator-5554',
appPackage='com.salugan.todolist',
appActivity='com.salugan.todolist.ui.activity.splash.SplashActivity',
appWaitForLaunch = "false"
)
appium_server_url = 'http://localhost:4723'
class TestAppium(unittest.TestCase):
def setUp(self) -> None:
self.driver = webdriver.Remote(appium_server_url, capabilities)
self.bookData1 = ["https://kognisia.co/wp-content/uploads/2017/04/1795191_35b54ca3-b77f-46dc-aeba-5a64d6c5bf7c.jpg",
"Harry Potter : The Chamber of Secrets",
"J.K. Rowling",
"2003",
"Fiksi"]
self.editedBookData1 = ["https://www.bookstation.ie/wp-content/uploads/2019/06/Harry-Potter-25-Year.jpg",
"Harry Potter : Prisoner of Azkaban",
"J.K. Rowling",
"2010",
"Fiksi"]
self.bookData2 = ["https://kognisia.co/wp-content/uploads/2017/04/1795191_35b54ca3-b77f-46dc-aeba-5a64d6c5bf7c.jpg",
"Pulang",
"Tere Liye",
"2015",
"Fiksi"]
self.bookData3 = ["https://kognisia.co/wp-content/uploads/2017/04/1795191_35b54ca3-b77f-46dc-aeba-5a64d6c5bf7c.jpg",
"Testing Crash Book",
"Usman",
"2147483649",
"Nonfiksi"]
def tearDown(self) -> None:
if self.driver:
self.driver.quit()
def test_Case1(self) -> None:
self.driver.implicitly_wait(10)
print("Test Case tambah satu buku")
try :
nodata = self.driver.find_element(MobileBy.ID, "com.salugan.todolist:id/textView")
if (nodata.is_displayed()):
print("Berhasil masuk ke menu")
except:
self.driver.implicitly_wait(10)
print("Buku telah ada sebelumnya dan berhasil masuk ke menu")
addBookButton = self.driver.find_element(MobileBy.ID, 'com.salugan.todolist:id/fab')
addBookButton.click()
time.sleep(1)
okButton = self.driver.find_element(MobileBy.ID, "android:id/button1")
bookElements = [(MobileBy.ID, "com.salugan.todolist:id/edtCover"),
(MobileBy.ID, "com.salugan.todolist:id/edtJudul"),
(MobileBy.ID, "com.salugan.todolist:id/edtNamaPenulis"),
(MobileBy.ID, "com.salugan.todolist:id/edtTahun"),
(MobileBy.ID, "com.salugan.todolist:id/edtKategori")]
# memasukkan data ke dalam form
for i, data in enumerate(self.bookData1):
input_element = self.driver.find_element(*bookElements[i])
input_element.send_keys(data)
time.sleep(0.1)
# mengeklik ok /save button
okButton = self.driver.find_element(MobileBy.ID, "android:id/button1")
okButton.click()
time.sleep(2)
# mengecek apabila text no data masih ada, jika tidak maka buku berhasil ditambahkan
try:
if nodata.is_displayed():
print("Buku gagal ditambahkan")
print(30*"=")
except:
print("Buku berhasil ditambahkan")
print(30*"=")
def test_Case2(self) -> None:
self.driver.implicitly_wait(10)
print("\nTest Case Edit Buku")
# validate if book in collections
try:
bookChecker = None
bookChecker = self.driver.find_element(MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.salugan.todolist:id/rvTodoList")')
if bookChecker is not None:
print("Buku telah divalidasi dan telah ditambahkan sebelumnya")
time.sleep(0.5)
except NoSuchElementException:
print("Tidak ada buku yang ditambahkan sebelumnya")
book1 = bookChecker.find_elements(MobileBy.CLASS_NAME, "android.widget.FrameLayout")[0]
book1.click()
time.sleep(1)
# menampung current value dari text view detail book
oldValue = []
oldValue.append(self.driver.find_element(MobileBy.ID, "com.salugan.todolist:id/tvJudul").text)
oldValue.append(self.driver.find_element(MobileBy.ID, "com.salugan.todolist:id/tvNamaPenulisDt").text)
oldValue.append(self.driver.find_element(MobileBy.ID, "com.salugan.todolist:id/tvTahun").text)
oldValue.append(self.driver.find_element(MobileBy.ID, "com.salugan.todolist:id/tvKategori").text)
bookEditButton = self.driver.find_element(MobileBy.ID, "com.salugan.todolist:id/btnUpdate")
bookEditButton.click()
time.sleep(0.5)
# validation variable declare
bookCover = self.driver.find_element(MobileBy.ID, "com.salugan.todolist:id/edtCover")
bookAuthor = self.driver.find_element(MobileBy.ID, "com.salugan.todolist:id/edtNamaPenulis")
bookElements = [(MobileBy.ID, "com.salugan.todolist:id/edtCover"),
(MobileBy.ID, "com.salugan.todolist:id/edtJudul"),
(MobileBy.ID, "com.salugan.todolist:id/edtNamaPenulis"),
(MobileBy.ID, "com.salugan.todolist:id/edtTahun"),
(MobileBy.ID, "com.salugan.todolist:id/edtKategori")]
try:
if(bookCover and bookAuthor is not None):
print("Value sebelumnya berhasil di deteksi")
for i, data in enumerate(self.editedBookData1):
input_element = self.driver.find_element(*bookElements[i])
input_element.clear()
input_element.send_keys(data)
time.sleep(0.1)
okButton = self.driver.find_element(MobileBy.ID, "android:id/button1")
okButton.click()
time.sleep(2)
except :
print("Credential book salah/tidak sesuai")
try:
currentEdited = []
counter = 0
currentEdited.append(self.driver.find_element(MobileBy.ID, "com.salugan.todolist:id/tvJudul").text)
currentEdited.append(self.driver.find_element(MobileBy.ID, "com.salugan.todolist:id/tvNamaPenulisDt").text)
currentEdited.append(self.driver.find_element(MobileBy.ID, "com.salugan.todolist:id/tvTahun").text)
currentEdited.append(self.driver.find_element(MobileBy.ID, "com.salugan.todolist:id/tvKategori").text)
for i,j,k in zip(currentEdited,oldValue,range(len(oldValue))) :
if i != j:
print(f"value indeks list ke-{k} tidak sama")
counter += 1
else:
print(f"value indeks ke-{k} sama")
except:
print("Buku gagal diedit")
finally:
if counter > 0 :
print("Buku berhasil diedit\n")
print(30*"=")
else:
print("Buku tidak diedit / tetap")
print(30*"=")
def test_Case3(self) -> None:
self.driver.implicitly_wait(10)
print("\nTest Case Delete Satu Buku")
try:
bookChecker = None
bookChecker = self.driver.find_element(MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.salugan.todolist:id/rvTodoList")')
if bookChecker is not None:
print("Buku telah divalidasi dan telah ditambahkan sebelumnya")
time.sleep(0.5)
except NoSuchElementException:
print("Tidak ada buku yang ditambahkan sebelumnya")
print(30*"=")
book1 = bookChecker.find_elements(MobileBy.CLASS_NAME, "android.widget.FrameLayout")[0]
book1.click()
time.sleep(1)
try:
currentBookDetails = []
currentBookDetails.append(self.driver.find_element(MobileBy.ID, "com.salugan.todolist:id/tvJudul").text)
currentBookDetails.append(self.driver.find_element(MobileBy.ID, "com.salugan.todolist:id/tvNamaPenulisDt").text)
currentBookDetails.append(self.driver.find_element(MobileBy.ID, "com.salugan.todolist:id/tvTahun").text)
currentBookDetails.append(self.driver.find_element(MobileBy.ID, "com.salugan.todolist:id/tvKategori").text)
if currentBookDetails != 0:
deleteButton = self.driver.find_element(MobileBy.ID,"com.salugan.todolist:id/btnDelete")
deleteButton.click()
time.sleep(0.3)
confirmDeleteButton = self.driver.find_element(MobileBy.ID, "android:id/button1")
confirmDeleteButton.click()
time.sleep(1)
except:
print("Buku tidak tersedia")
print(30*"=")
finally:
nodata = self.driver.find_element(MobileBy.ID, "com.salugan.todolist:id/textView").is_displayed
if nodata != True:
print("Buku berhasil dihapus")
print(30*"=")
def test_case4(self)-> None:
self.driver.implicitly_wait(10)
print("Test Case tambah satu buku invalid tahun terbit")
try :
nodata = self.driver.find_element(MobileBy.ID, "com.salugan.todolist:id/textView")
if (nodata.is_displayed()):
print("Berhasil masuk ke menu")
except:
self.driver.implicitly_wait(10)
print("Buku telah ada sebelumnya dan berhasil masuk ke menu")
addBookButton = self.driver.find_element(MobileBy.ID, 'com.salugan.todolist:id/fab')
addBookButton.click()
time.sleep(1)
okButton = self.driver.find_element(MobileBy.ID, "android:id/button1")
bookElements = [(MobileBy.ID, "com.salugan.todolist:id/edtCover"),
(MobileBy.ID, "com.salugan.todolist:id/edtJudul"),
(MobileBy.ID, "com.salugan.todolist:id/edtNamaPenulis"),
(MobileBy.ID, "com.salugan.todolist:id/edtTahun"),
(MobileBy.ID, "com.salugan.todolist:id/edtKategori")]
# memasukkan data ke dalam form
for i, data in enumerate(self.bookData3):
input_element = self.driver.find_element(*bookElements[i])
input_element.send_keys(data)
time.sleep(0.1)
# mengeklik ok /save button
# mengecek terjadinya crash
try:
okButton = self.driver.find_element(MobileBy.ID, "android:id/button1")
okButton.click()
time.sleep(0.5)
if InvalidSessionIdException :
print("Aplikasi telah berhenti/crash")
pass
except InvalidSessionIdException as e:
print(f"Aplikasi telah berhenti/crash dikarekanakan\n{e}")
if __name__ == '__main__':
unittest.main()