-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_collabora_selenium.py
840 lines (716 loc) · 45 KB
/
test_collabora_selenium.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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
""" Selenium tests for Sunet Drive
Author: Richard Freitag <[email protected]>
Selenium tests to test Collabora on a local node
"""
from datetime import datetime
import xmlrunner
import unittest
import sunetnextcloud
import pyautogui
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver import FirefoxOptions
from webdav3.client import Client
import logging
import os
import time
import yaml
# 'prod' for production environment, 'test' for test environment
g_testtarget = os.environ.get('NextcloudTestTarget')
g_expectedResultsFile = 'expected.yaml'
g_filename=datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
g_isLoggedIn=False
g_webdav_timeout = 30
g_collaboraRetryCount = 5
g_loggedInNodes={}
g_logger={}
g_driver={}
g_drv={}
g_wait={}
def deleteCookies():
cookies = g_driver.get_cookies()
g_logger.info(f'Deleting all cookies: {cookies}')
g_driver.delete_all_cookies()
cookies = g_driver.get_cookies()
g_logger.info(f'Cookies deleted: {cookies}')
def nodelogin(collaboranode):
global g_wait
deleteCookies()
g_logger.info(f'Logging in to {collaboranode}')
loginurl = g_drv.get_node_login_url(collaboranode)
g_logger.info(f'Login url: {loginurl}')
nodeuser = g_drv.get_seleniumuser(collaboranode)
nodepwd = g_drv.get_seleniumuserpassword(collaboranode)
g_isLoggedIn = True
g_loggedInNodes[collaboranode] = True
g_driver.maximize_window()
actions = ActionChains(g_driver)
# driver2 = webdriver.Firefox()
g_driver.get(loginurl)
g_wait.until(EC.presence_of_element_located((By.ID, 'user'))).send_keys(nodeuser)
g_wait.until(EC.presence_of_element_located((By.ID, 'password'))).send_keys(nodepwd + Keys.ENTER)
return
def checkFile(node, foldername, filename):
fullPath = foldername + '/' + filename
g_logger.info(f'Check if file {fullPath} exists on {node}')
nodeuser = g_drv.get_seleniumuser(node)
nodepwd = g_drv.get_seleniumuserpassword(node)
url = g_drv.get_webdav_url(node, nodeuser)
options = {
'webdav_hostname': url,
'webdav_login' : nodeuser,
'webdav_password' : nodepwd,
'webdav_timeout': g_webdav_timeout
}
client = Client(options)
# We check a few times if the file has been created
tryCount = 0
while tryCount < 5:
tryCount += 1
g_logger.info(f'Folder contains {len(client.list(foldername))} elements')
exists = client.check(fullPath)
if exists == True:
g_logger.info(f'File {fullPath} was found on try {tryCount}')
return exists
g_logger.info(f'File {fullPath} not found on try {tryCount}')
time.sleep(3)
g_logger.info(f'File {fullPath} on {node} not found after {tryCount} tries: {exists}')
return exists
class TestCollaboraSelenium(unittest.TestCase):
global g_loggedInNodes, g_logger, g_drv, g_wait, g_driver
drv = sunetnextcloud.TestTarget(g_testtarget)
g_drv=drv
logger = logging.getLogger(__name__)
g_logger = logger
logging.basicConfig(format = '%(asctime)s - %(module)s.%(funcName)s - %(levelname)s: %(message)s',
datefmt = '%Y-%m-%d %H:%M:%S', level = logging.INFO)
with open(g_expectedResultsFile, "r") as stream:
expectedResults=yaml.safe_load(stream)
testfolders = ['SeleniumCollaboraTest', 'selenium-system', 'selenium-personal']
# Some class names of icons changed from Nextcloud 27 to 28
version = expectedResults[drv.target]['status']['version']
homeIcon = 'home-icon'
addIcon = 'plus-icon'
if len(drv.browsers) > 1:
logger.warning(f'Please test only one browser by setting NextcloudTestBrowsers to the one you want to test: {drv.browsers}')
logger.info(f'Testing browser: {drv.browsers[0]}')
if drv.browsers[0] == 'chrome':
try:
options = ChromeOptions()
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--disable-gpu")
options.add_argument("--disable-extensions")
driver = webdriver.Chrome(options=options)
g_driver=driver
except Exception as error:
logger.error(f'Error initializing Chrome driver: {error}')
elif drv.browsers[0] == 'firefox':
try:
options = FirefoxOptions()
driver = webdriver.Firefox(options=options)
g_driver=driver
except Exception as error:
logger.error(f'Error initializing Firefox driver: {error}')
else:
logger.error(f'Unknown browser: {drv.browsers[0]}')
def test_logger(self):
self.logger.info(f'TestID: {self._testMethodName}')
pass
for collaboranode in drv.fullnodes:
g_loggedInNodes[collaboranode] = False
# text file
def test_markup_text(self):
delay = 30 # seconds
global g_isLoggedIn, g_loggedInNodes, g_wait
wait = WebDriverWait(self.driver, delay)
g_wait = wait
for collaboranode in self.drv.fullnodes:
with self.subTest(mynode=collaboranode):
self.logger.info(f'TestID: {collaboranode}')
# if g_isLoggedIn == False:
if g_loggedInNodes.get(collaboranode) == False:
nodelogin(collaboranode)
self.assertTrue(g_loggedInNodes.get(collaboranode))
success = True
self.logger.info('Waiting for app menu')
try:
wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'app-menu')))
self.logger.info(f'App menu is ready!')
except TimeoutException:
self.logger.warning(f'Loading of app menu took too much time!')
success = False
if success == False:
self.logger.warning(f'Manually open home folder in case loading of all files takes too much time')
self.driver.get(self.drv.get_folder_url(collaboranode,''))
success = True
self.assertTrue(success)
# Check URLs after login
dashboardUrl = self.drv.get_dashboard_url(collaboranode)
currentUrl = self.driver.current_url
# self.assertEqual(dashboardUrl, currentUrl)
try:
self.logger.info(f'Wait for {self.drv.indexsuffix}/apps/files/')
wait.until(EC.element_to_be_clickable((By.XPATH,'//a[@href="'+ self.drv.indexsuffix + '/apps/files/' +'"]'))).click()
except Exception as error:
self.logger.warning(f'Wait for {self.drv.indexsuffix}/apps/files/ took too long: {error}')
success = False
self.assertTrue(success)
try:
wait.until(EC.presence_of_element_located((By.LINK_TEXT, 'All files')))
self.logger.info(f'All files visible!')
except TimeoutException:
self.logger.warning(f'Loading of all files took too much time!')
success = False
if success == False:
self.logger.warning(f'Manually open home folder in case loading of all files takes too much time')
self.driver.get(self.drv.get_folder_url(collaboranode,''))
success = True
self.assertTrue(success)
self.driver.implicitly_wait(10) # seconds before quitting
self.logger.info(self.driver.current_url)
self.logger.info(f'Looking for all files text in {self.version}')
# //*[@id="app-content-vue"]/div[1]/div/nav/ul/li/a/span/span[2] "//h4/a[contains(text(),'SAP M')]"
self.driver.find_element(By.XPATH, "//*[contains(text(), 'All files')]")
self.logger.info(f'All files found!')
self.logger.info(f'Looking for SeleniumCollaboraTest folder')
try:
self.driver.find_element(By.XPATH, "//*[contains(text(), 'SeleniumCollaboraTest')]")
self.logger.info(f'SeleniumCollaboraTest folder found')
except Exception as error:
self.logger.info(f'SeleniumCollaboraTest folder not found, creating; {error}')
wait.until(EC.element_to_be_clickable((By.CLASS_NAME, self.addIcon))).click()
time.sleep(1)
wait.until(EC.element_to_be_clickable((By.XPATH, "//*[contains(@class, 'action-button__text') and text()='New folder']"))).click()
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'input[id^=\'input\']')))
ActionChains(self.driver).key_down(Keys.CONTROL).send_keys('a').key_up(Keys.CONTROL).perform()
ActionChains(self.driver).send_keys(f'SeleniumCollaboraTest{Keys.ENTER}').perform()
time.sleep(1)
folderurl = self.drv.get_folder_url(collaboranode, "SeleniumCollaboraTest")
self.driver.get(folderurl)
fileCreated = False
retryCount = 0
while fileCreated == False:
retryCount += 1
if retryCount >= g_collaboraRetryCount:
self.logger.error(f'File {g_filename}.md has not been created after {retryCount} tries, saving screenshot')
screenshot = pyautogui.screenshot()
screenshot.save("screenshots/" + collaboranode + g_filename + ".png")
self.assertTrue(False)
break
# Check if the folder is empty
try:
wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'files-list__table')))
isEmpty = False
self.logger.info(f'Folder is not empty, adding new content')
except Exception as error:
self.logger.info(f'Folder seems empty, creating new files')
isEmpty = True
# Sort file list so that new files are created at the beginning of the list
if isEmpty == False:
try:
wait.until(EC.element_to_be_clickable((By.CLASS_NAME, 'files-list__column-sort-button'))).click()
self.logger.info(f'Changed sort order to descending')
except Exception as error:
self.logger.warning(f'Unable to change sort order to descending: {error}')
time.sleep(3)
try:
wait.until(EC.element_to_be_clickable((By.CLASS_NAME, self.addIcon))).click()
# wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'icon-filetype-text'))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//*[contains(text(), 'New text file')]"))).click()
# Starting with Nextcloud 28, we have to rename the file
wait.until(EC.presence_of_element_located((By.XPATH, "//*[contains(text(), 'New document')]")))
self.logger.info(f'Renaming the file we just created to {g_filename}.md')
ActionChains(self.driver).key_down(Keys.CONTROL).send_keys('a').key_up(Keys.CONTROL).perform()
time.sleep(0.5)
ActionChains(self.driver).send_keys(f'{g_filename}.md').perform()
time.sleep(0.5)
ActionChains(self.driver).send_keys(Keys.ENTER).perform()
except Exception as error:
self.logger.warning(f'Unable to create new file: {g_filename}, saving screenshot: {error}')
screenshot = pyautogui.screenshot()
screenshot.save("screenshots/" + collaboranode + g_filename + ".png")
self.assertTrue(False)
# Verify the file has been created
fileCreated = checkFile(collaboranode, "SeleniumCollaboraTest", g_filename + '.md')
if fileCreated == False:
self.logger.warning(f'File {g_filename}.md has not been created in try {retryCount}, refresh page and retry')
self.driver.refresh()
time.sleep(3)
# If it is the first entry in the list, we have to reload the page to get it to load
try:
if isEmpty:
self.logger.info(f'Reload page to open new document')
self.driver.refresh()
except Exception as e:
self.logger.error(f'Error: {e}')
self.logger.info(f'Sleep for 3 seconds...')
time.sleep(3)
self.logger.info(f'Can we type in the markup area?')
ActionChains(self.driver).send_keys(f'Lorem Ipsum! {Keys.ENTER} {g_filename}').perform()
time.sleep(3) # We give nextcloud a literal second to register the keystrokes before closing the document
self.logger.info(f'Closing document...')
try:
wait.until(EC.element_to_be_clickable((By.CLASS_NAME, 'header-close'))).click()
except Exception as error:
self.logger.warning(f"Closing markup document failed: {error}")
self.logger.info(f'Manually open home folder in case closing of document fails')
self.driver.get(self.drv.get_folder_url(collaboranode,''))
self.logger.info(f'And done...')
time.sleep(1)
def test_collabora_document(self):
delay = 30 # seconds
global g_isLoggedIn, g_loggedInNodes, g_wait
wait = WebDriverWait(self.driver, delay)
g_wait = wait
for collaboranode in self.drv.fullnodes:
with self.subTest(mynode=collaboranode):
self.logger.info(f'TestID: {collaboranode}')
# if g_isLoggedIn == False:
if g_loggedInNodes.get(collaboranode) == False:
nodelogin(collaboranode)
self.assertTrue(g_loggedInNodes.get(collaboranode))
success = True
self.logger.info('Waiting for app menu')
try:
wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'app-menu')))
self.logger.info(f'App menu is ready!')
except TimeoutException:
self.logger.warning(f'Loading of app menu took too much time!')
success = False
if success == False:
self.logger.warning(f'Manually open home folder in case loading of all files takes too much time')
self.driver.get(self.drv.get_folder_url(collaboranode,''))
success = True
self.assertTrue(success)
# Check URLs after login
dashboardUrl = self.drv.get_dashboard_url(collaboranode)
currentUrl = self.driver.current_url
# self.assertEqual(dashboardUrl, currentUrl)
for testfolder in self.testfolders:
with self.subTest(myFolder=testfolder):
self.logger.info(f'TestID: {collaboranode} for folder {testfolder}')
try:
self.logger.info(f'Wait for {self.drv.indexsuffix}/apps/files/ and click')
wait.until(EC.element_to_be_clickable((By.XPATH,'//a[@href="'+ self.drv.indexsuffix + '/apps/files/' +'"]'))).click()
# self.logger.info(f'Get link for files app')
# files = self.driver.find_element(by=By.XPATH, value='//a[@href="'+ self.drv.indexsuffix + '/apps/files/' +'"]')
# self.logger.info(f'Click on files app')
# files.click()
except Exception as error:
self.logger.warning(f'Wait for {self.drv.indexsuffix}/apps/files/ took too long: {error}')
success = False
self.logger.info(f'Success: {success}')
self.assertTrue(success)
try:
wait.until(EC.presence_of_element_located((By.LINK_TEXT, 'All files')))
self.logger.info(f'All files visible!')
except TimeoutException:
self.logger.warning(f'Loading of all files took too much time!')
success = False
if success == False:
self.logger.warning(f'Manually open home folder in case loading of all files takes too much time')
self.driver.get(self.drv.get_folder_url(collaboranode,''))
success = True
self.assertTrue(success)
self.driver.implicitly_wait(10) # seconds before quitting
self.logger.info(self.driver.current_url)
self.logger.info(f'Looking for all files text in {self.version}')
# //*[@id="app-content-vue"]/div[1]/div/nav/ul/li/a/span/span[2] "//h4/a[contains(text(),'SAP M')]"
self.driver.find_element(By.XPATH, "//*[contains(text(), 'All files')]")
self.logger.info(f'All files found!')
self.logger.info(f'Looking for {testfolder} folder')
try:
self.driver.find_element(By.XPATH, f"//*[contains(text(), '{testfolder}')]")
self.logger.info(f'{testfolder} folder found')
except Exception as error:
self.logger.info(f'{testfolder} folder not found, creating; Exception was: {error}')
wait.until(EC.element_to_be_clickable((By.CLASS_NAME, self.addIcon))).click()
time.sleep(1)
self.logger.info(f'Creating {testfolder} on {self.version}')
wait.until(EC.element_to_be_clickable((By.XPATH, "//*[contains(@class, 'action-button__text') and text()='New folder']"))).click()
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'input[id^=\'input\']')))
ActionChains(self.driver).key_down(Keys.CONTROL).send_keys('a').key_up(Keys.CONTROL).perform()
ActionChains(self.driver).send_keys(f'{testfolder}{Keys.ENTER}').perform()
time.sleep(1)
folderurl = self.drv.get_folder_url(collaboranode, testfolder)
self.driver.get(folderurl)
fileCreated = False
retryCount = 0
while fileCreated == False:
retryCount += 1
if retryCount >= g_collaboraRetryCount:
self.logger.error(f'File {g_filename} has not been created after {retryCount} tries, saving screenshot')
screenshot = pyautogui.screenshot()
screenshot.save("screenshots/" + collaboranode + g_filename + ".png")
self.assertTrue(False)
break
# Check if the folder is empty
try:
wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'files-list__table')))
isEmpty = False
self.logger.info(f'Folder is not empty, adding new content')
except Exception as error:
self.logger.info(f'Folder seems empty, creating new files;')
isEmpty = True
# Sort file list so that new files are created at the beginning of the list
# if isEmpty == False:
# try:
# wait.until(EC.element_to_be_clickable((By.CLASS_NAME, 'files-list__column-sort-button'))).click()
# self.logger.info(f'Changed sort order to descending')
# except Exception as error:
# self.logger.warning(f'Unable to change sort order to descending; Exception was {error}')
time.sleep(3)
try:
self.logger.info(f'Click on add icon')
wait.until(EC.element_to_be_clickable((By.CLASS_NAME, self.addIcon))).click()
self.logger.info(f'Click on add document')
# wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'icon-filetype-document'))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//*[contains(text(), 'New document')]"))).click()
# Starting with Nextcloud 28, we have to rename the file
wait.until(EC.presence_of_element_located((By.XPATH, "//*[contains(text(), 'New document')]")))
self.logger.info(f'Renaming the file we just created to {g_filename}.odt')
ActionChains(self.driver).key_down(Keys.CONTROL).send_keys('a').key_up(Keys.CONTROL).perform()
time.sleep(.5)
ActionChains(self.driver).send_keys(f'{g_filename}.odt').perform()
time.sleep(.5)
ActionChains(self.driver).send_keys(Keys.ENTER).perform()
except Exception as error:
self.logger.warning(f'Unable to create new file: {g_filename}, saving screenshot: {error}')
screenshot = pyautogui.screenshot()
screenshot.save("screenshots/" + collaboranode + g_filename + ".png")
self.assertTrue(False)
# Verify the file has been created
fileCreated = checkFile(collaboranode, testfolder, g_filename + '.odt')
if fileCreated == False:
self.logger.warning(f'File {g_filename}.odt has not been created in try {retryCount}, refresh page and retry')
self.driver.refresh()
time.sleep(3)
# If it is the first entry in the list, we have to reload the page to get it to load
try:
if isEmpty:
self.logger.info(f'Reload page to open new document')
self.driver.refresh()
except Exception as e:
self.logger.error(f'Error: {e}')
self.logger.info(f'Sleep for 3 seconds...')
self.logger.info(f'Proceeding...')
try:
self.logger.info(f'Waiting for collabora frame')
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[id^='collaboraframe']")))
self.logger.info(f'Collabora loaded... Let\'s type some text')
time.sleep(3)
ActionChains(self.driver).send_keys(f'Lorem Ipsum! {Keys.ENTER} {g_filename}').perform()
time.sleep(3)
except Exception as error:
self.logger.error(f'Error writing to the document, saving screenshot: {error}')
screenshot = pyautogui.screenshot()
screenshot.save("screenshots/" + collaboranode + g_filename + ".png")
success = False
self.logger.info(f'Open the folder URL instead of closing the document')
self.driver.get(self.drv.get_folder_url(collaboranode,''))
self.assertTrue(success)
self.logger.info('End of test!')
self.assertTrue(g_loggedInNodes.get(collaboranode))
# spreadsheet
def test_collabora_spreadsheet(self):
delay = 30 # seconds
global g_isLoggedIn, g_loggedInNodes, g_wait
wait = WebDriverWait(self.driver, delay)
g_wait = wait
for collaboranode in self.drv.fullnodes:
with self.subTest(mynode=collaboranode):
self.logger.info(f'TestID: {collaboranode}')
# if g_isLoggedIn == False:
if g_loggedInNodes.get(collaboranode) == False:
nodelogin(collaboranode)
self.assertTrue(g_loggedInNodes.get(collaboranode))
success = True
self.logger.info('Waiting for app menu')
try:
wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'app-menu')))
self.logger.info(f'App menu is ready!')
except TimeoutException:
self.logger.warning(f'Loading of app menu took too much time!')
success = False
if success == False:
self.logger.warning(f'Manually open home folder in case loading of all files takes too much time')
self.driver.get(self.drv.get_folder_url(collaboranode,''))
success = True
self.assertTrue(success)
# Check URLs after login
dashboardUrl = self.drv.get_dashboard_url(collaboranode)
currentUrl = self.driver.current_url
# self.assertEqual(dashboardUrl, currentUrl)
try:
self.logger.info(f'Wait for {self.drv.indexsuffix}/apps/files/')
wait.until(EC.element_to_be_clickable((By.XPATH,'//a[@href="'+ self.drv.indexsuffix + '/apps/files/' +'"]'))).click()
# files = self.driver.find_element(by=By.XPATH, value='//a[@href="'+ self.drv.indexsuffix + '/apps/files/' +'"]')
# files.click()
except Exception as error:
self.logger.warning(f'Wait for {self.drv.indexsuffix}/apps/files/ took too long: {error}')
success = False
self.assertTrue(success)
try:
wait.until(EC.presence_of_element_located((By.LINK_TEXT, 'All files')))
self.logger.info(f'All files visible!')
except TimeoutException:
self.logger.warning(f'Loading of all files took too much time!')
success = False
if success == False:
self.logger.warning(f'Manually open home folder in case loading of all files takes too much time')
self.driver.get(self.drv.get_folder_url(collaboranode,''))
success = True
self.assertTrue(success)
self.driver.implicitly_wait(10) # seconds before quitting
self.logger.info(self.driver.current_url)
self.logger.info(f'Looking for all files text in {self.version}')
# //*[@id="app-content-vue"]/div[1]/div/nav/ul/li/a/span/span[2] "//h4/a[contains(text(),'SAP M')]"
self.driver.find_element(By.XPATH, "//*[contains(text(), 'All files')]")
self.logger.info(f'All files found!')
self.logger.info(f'Looking for SeleniumCollaboraTest folder')
try:
self.driver.find_element(By.XPATH, "//*[contains(text(), 'SeleniumCollaboraTest')]")
self.logger.info(f'SeleniumCollaboraTest folder found')
except Exception as error:
self.logger.info(f'SeleniumCollaboraTest folder not found, creating; {error}')
wait.until(EC.element_to_be_clickable((By.CLASS_NAME, self.addIcon))).click()
time.sleep(1)
wait.until(EC.element_to_be_clickable((By.XPATH, "//*[contains(@class, 'action-button__text') and text()='New folder']"))).click()
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'input[id^=\'input\']')))
ActionChains(self.driver).key_down(Keys.CONTROL).send_keys('a').key_up(Keys.CONTROL).perform()
ActionChains(self.driver).send_keys(f'SeleniumCollaboraTest{Keys.ENTER}').perform()
time.sleep(1)
folderurl = self.drv.get_folder_url(collaboranode, "SeleniumCollaboraTest")
self.driver.get(folderurl)
fileCreated = False
retryCount = 0
while fileCreated == False:
retryCount += 1
if retryCount >= g_collaboraRetryCount:
self.logger.error(f'File {g_filename} has not been created after {retryCount} tries, saving screenshot')
screenshot = pyautogui.screenshot()
screenshot.save("screenshots/" + collaboranode + g_filename + ".png")
self.assertTrue(False)
break
# Check if the folder is empty
try:
wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'files-list__table')))
isEmpty = False
self.logger.info(f'Folder is not empty, adding new content')
except Exception as error:
self.logger.info(f'Folder seems empty, creating new files.')
isEmpty = True
# Sort file list so that new files are created at the beginning of the list
if isEmpty == False:
try:
wait.until(EC.element_to_be_clickable((By.CLASS_NAME, 'files-list__column-sort-button'))).click()
self.logger.info(f'Changed sort order to descending')
except Exception as error:
self.logger.warning(f'Unable to change sort order to descending: {error}')
time.sleep(3)
try:
wait.until(EC.element_to_be_clickable((By.CLASS_NAME, self.addIcon))).click()
# wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'icon-filetype-spreadsheet'))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//*[contains(text(), 'New spreadsheet')]"))).click()
# Starting with Nextcloud 28, we have to rename the file
wait.until(EC.presence_of_element_located((By.XPATH, "//*[contains(text(), 'New document')]")))
self.logger.info(f'Renaming the file we just created to {g_filename}.ods')
ActionChains(self.driver).key_down(Keys.CONTROL).send_keys('a').key_up(Keys.CONTROL).perform()
time.sleep(0.5)
ActionChains(self.driver).send_keys(f'{g_filename}.ods').perform()
time.sleep(0.5)
ActionChains(self.driver).send_keys(Keys.ENTER).perform()
except Exception as error:
self.logger.error(f'Unable to create new file: {g_filename}, saving screenshot: {error}')
screenshot = pyautogui.screenshot()
screenshot.save("screenshots/" + collaboranode + g_filename + ".png")
self.assertTrue(False)
# Verify the file has been created
fileCreated = checkFile(collaboranode, "SeleniumCollaboraTest", g_filename + '.ods')
if fileCreated == False:
self.logger.warning(f'File {g_filename}.ods has not been created in try {retryCount}, refresh page and retry')
self.driver.refresh()
time.sleep(3)
# If it is the first entry in the list, we have to reload the page to get it to load
try:
if isEmpty:
self.logger.info(f'Reload page to open new document')
self.driver.refresh()
except Exception as e:
self.logger.error(f'Error: {e}')
self.logger.info(f'Sleep for 3 seconds...')
time.sleep(3)
self.logger.info(f'Proceeding...')
try:
self.logger.info(f'Waiting for collabora frame')
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[id^='collaboraframe']")))
self.logger.info(f'Collabora loaded... Let\'s type some text')
time.sleep(1)
ActionChains(self.driver).key_down(Keys.CONTROL).send_keys(Keys.UP).key_up(Keys.CONTROL).perform()
ActionChains(self.driver).key_down(Keys.CONTROL).send_keys(Keys.LEFT).key_up(Keys.CONTROL).perform()
ActionChains(self.driver).send_keys(f'{g_filename}{Keys.ENTER}{Keys.SPACE}1{Keys.ENTER}{Keys.SPACE}2{Keys.ENTER}{Keys.SPACE}3{Keys.ENTER}{Keys.SPACE}4{Keys.ENTER}{Keys.SPACE}').perform()
time.sleep(1)
except Exception as error:
self.logger.error(f'Error writing to the document, saving screenshot: {error}')
screenshot = pyautogui.screenshot()
screenshot.save("screenshots/" + collaboranode + g_filename + ".png")
success = False
self.logger.info(f'Open the folder URL instead of closing the document')
self.driver.get(self.drv.get_folder_url(collaboranode,''))
self.assertTrue(success)
self.logger.info('End of test!')
# presentation
def test_collabora_presentation(self):
delay = 30 # seconds
global g_isLoggedIn, g_loggedInNodes, g_wait
wait = WebDriverWait(self.driver, delay)
g_wait = wait
for collaboranode in self.drv.fullnodes:
with self.subTest(mynode=collaboranode):
self.logger.info(f'TestID: {collaboranode}')
# if g_isLoggedIn == False:
if g_loggedInNodes.get(collaboranode) == False:
nodelogin(collaboranode)
self.assertTrue(g_loggedInNodes.get(collaboranode))
success = True
self.logger.info('Waiting for app menu')
try:
wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'app-menu')))
self.logger.info(f'App menu is ready!')
except TimeoutException:
self.logger.warning(f'Loading of app menu took too much time!')
success = False
if success == False:
self.logger.warning(f'Manually open home folder in case loading of all files takes too much time')
self.driver.get(self.drv.get_folder_url(collaboranode,''))
success = True
self.assertTrue(success)
# Check URLs after login
dashboardUrl = self.drv.get_dashboard_url(collaboranode)
currentUrl = self.driver.current_url
# self.assertEqual(dashboardUrl, currentUrl)
try:
self.logger.info(f'Wait for {self.drv.indexsuffix}/apps/files/')
wait.until(EC.element_to_be_clickable((By.XPATH,'//a[@href="'+ self.drv.indexsuffix + '/apps/files/' +'"]'))).click()
# files = self.driver.find_element(by=By.XPATH, value='//a[@href="'+ self.drv.indexsuffix + '/apps/files/' +'"]')
# files.click()
except Exception as error:
self.logger.warning(f'Wait for {self.drv.indexsuffix}/apps/files/ took too long: {error}')
success = False
self.assertTrue(success)
try:
wait.until(EC.presence_of_element_located((By.LINK_TEXT, 'All files')))
self.logger.info(f'All files visible!')
except Exception as error:
self.logger.warning(f'Loading of all files took too much time: {error}')
success = False
if success == False:
self.logger.warning(f'Manually open home folder in case loading of all files takes too much time')
self.driver.get(self.drv.get_folder_url(collaboranode,''))
success = True
self.assertTrue(success)
self.driver.implicitly_wait(10) # seconds before quitting
self.logger.info(self.driver.current_url)
self.logger.info(f'Looking for all files text in {self.version}')
# //*[@id="app-content-vue"]/div[1]/div/nav/ul/li/a/span/span[2] "//h4/a[contains(text(),'SAP M')]"
self.driver.find_element(By.XPATH, "//*[contains(text(), 'All files')]")
self.logger.info(f'All files found!')
self.logger.info(f'Looking for SeleniumCollaboraTest folder')
try:
self.driver.find_element(By.XPATH, "//*[contains(text(), 'SeleniumCollaboraTest')]")
self.logger.info(f'SeleniumCollaboraTest folder found')
except Exception as error:
self.logger.info(f'SeleniumCollaboraTest folder not found, creating; {error}')
wait.until(EC.element_to_be_clickable((By.CLASS_NAME, self.addIcon))).click()
time.sleep(1)
wait.until(EC.element_to_be_clickable((By.XPATH, "//*[contains(@class, 'action-button__text') and text()='New folder']"))).click()
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'input[id^=\'input\']')))
ActionChains(self.driver).key_down(Keys.CONTROL).send_keys('a').key_up(Keys.CONTROL).perform()
ActionChains(self.driver).send_keys(f'SeleniumCollaboraTest{Keys.ENTER}').perform()
time.sleep(1)
folderurl = self.drv.get_folder_url(collaboranode, "SeleniumCollaboraTest")
self.driver.get(folderurl)
fileCreated = False
retryCount = 0
while fileCreated == False:
retryCount += 1
if retryCount >= g_collaboraRetryCount:
self.logger.error(f'File {g_filename} has not been created after {retryCount} tries, saving screenshot')
screenshot = pyautogui.screenshot()
screenshot.save("screenshots/" + collaboranode + g_filename + ".png")
self.assertTrue(False)
break
# Check if the folder is empty
try:
wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'files-list__table')))
isEmpty = False
self.logger.info(f'Folder is not empty, adding new content')
except Exception as error:
self.logger.info(f'Folder seems empty, creating new files.')
isEmpty = True
# Sort file list so that new files are created at the beginning of the list
if isEmpty == False:
try:
wait.until(EC.element_to_be_clickable((By.CLASS_NAME, 'files-list__column-sort-button'))).click()
self.logger.info(f'Changed sort order to descending')
except Exception as error:
self.logger.warning(f'Unable to change sort order to descending: {error}')
time.sleep(3)
try:
wait.until(EC.element_to_be_clickable((By.CLASS_NAME, self.addIcon))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//*[contains(text(), 'New presentation')]"))).click()
# Starting with Nextcloud 28, we have to rename the file
wait.until(EC.presence_of_element_located((By.XPATH, "//*[contains(text(), 'New document')]")))
self.logger.info(f'Renaming the file we just created to {g_filename}.odp')
ActionChains(self.driver).key_down(Keys.CONTROL).send_keys('a').key_up(Keys.CONTROL).perform()
time.sleep(0.5)
ActionChains(self.driver).send_keys(f'{g_filename}.odp').perform()
time.sleep(0.5)
ActionChains(self.driver).send_keys(Keys.ENTER).perform()
except Exception as error:
self.logger.error(f'Unable to create new file: {g_filename}, saving screenshot: {error}')
screenshot = pyautogui.screenshot()
screenshot.save("screenshots/" + collaboranode + g_filename + ".png")
self.assertTrue(False)
# Verify the file has been created
fileCreated = checkFile(collaboranode, "SeleniumCollaboraTest", g_filename + '.odp')
if fileCreated == False:
self.logger.warning(f'File {g_filename}.odp has not been created in try {retryCount}, refresh page and retry')
self.driver.refresh()
time.sleep(3)
# If it is the first entry in the list, we have to reload the page to get it to load
try:
if isEmpty:
self.logger.info(f'Reload page to open new document')
self.driver.refresh()
except Exception as e:
self.logger.error(f'Error: {e}')
self.logger.info(f'Sleep for 3 seconds...')
time.sleep(3)
self.logger.info(f'Proceeding...')
try:
self.logger.info(f'Waiting for collabora frame')
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[id^='collaboraframe']")))
self.logger.info(f'Collabora loaded... Let\'s type some text')
time.sleep(3)
ActionChains(self.driver).send_keys(f'Lorem ipsum! {Keys.ENTER}{g_filename}').perform()
time.sleep(1)
except Exception as error:
self.logger.error(f'Error writing to the document, saving screenshot: {error}')
screenshot = pyautogui.screenshot()
screenshot.save("screenshots/" + collaboranode + g_filename + ".png")
success = False
self.logger.info(f'Open the folder URL instead of closing the document')
self.driver.get(self.drv.get_folder_url(collaboranode,''))
self.assertTrue(success)
self.logger.info('End of test!')
if __name__ == '__main__':
# unittest.main()
unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))