Repository navigation
Expand file tree
/
Copy pathspacesdriver.py
More file actions
executable file
·2562 lines (2227 loc) · 149 KB
/
Copy pathspacesdriver.py
File metadata and controls
executable file
·2562 lines (2227 loc) · 149 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
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
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
import os
import pdb
import string
import time
import random
import logging
import sys
from selenium.common.exceptions import TimeoutException, StaleElementReferenceException
from selenium.webdriver.common.action_chains import ActionChains
from spaces_webdriver import SpacesWebDriver
from test_config_loader import TestConfigLoader
from platform_lib import PlatformLib
from xpath import XPathBuilder
from accessibility import Accessibility
try:
from castro import Castro
except ImportError:
import datetime
print("[%s] %s" % (datetime.datetime.now(), "Video recording library not installed."))
class NotSupportedPlatformException(Exception):
pass
class SkypeSpaces(object):
UNINSTALL_APP_BEFORE_SETUP = True
ENABLE_SLIMCORE = True
ENABLE_CALLING_IN_BROWSER = True
CSS = "css"
XPATH = "xpath"
ID = "id"
LOADING_TIMEOUT = 90
CALLING_TIMEOUT = 300
LEAVE_TIMEOUT = 900
CQF_SEARCH_LIMIT = 15
CQF_DEFAULT_STARS = 3
CQF_MAX_STARS = 5
FORCE_WEB_URL_LOAD = False
CONTAINER_ARG = "container"
RING_ARG = "ring"
################
# Element data #
################
ELECTRON_APP_HANDLER_XPATH = "//body"
CHANNEL_LOADING_SPINNER_DISPAYED = "//message-list//div[contains(@class,'vr-loadmore')][not(contains(@class,'hide-spinner'))]//busy-animation"
CHANNEL_LOADING_SPINNER_NOT_DISPAYED = "//message-list//div[contains(@class,'vr-loadmore hide-spinner')]//busy-animation"
WELCOME_TO_MICROSOFT_TEAMS_LETS_GO_BUTTON = "//button[@data-tid='routingSettingsInformational-letsGoBtn']"
TEAMS_LOGIN_REDIRECTING_IS_VISIBLE = "//div[@id='redirect_cta_text'][contains(@style,'display: block')]"
CHANNEL_MESSAGE_LIST_XPATH = "//virtual-repeat[contains(@class, 'ts-message-list')]"
LOGIN_AREA = "//div[@id='loginArea']"
MSFT_LOGIN_PAGE = "login.microsoftonline.com"
SPACES_LOGIN_USE_ANOTHER_ACCOUNT_ID = "use_another_account"
SPACES_LOGIN_USE_ANOTHER_ACCOUNT_LINK_ID = "use_another_account_link"
USE_ANOTHER_ACCOUNT_ELEMENTS_LIST = "//*[@id='" + SPACES_LOGIN_USE_ANOTHER_ACCOUNT_ID + "' or @id='" + SPACES_LOGIN_USE_ANOTHER_ACCOUNT_LINK_ID + "']"
SPACES_LOGIN_USERNAME_ID = "cred_userid_inputtext"
SPACES_LOGIN_USERNAME_INPUT = "//input[@id='" + SPACES_LOGIN_USERNAME_ID + "']"
SPACES_LOGIN_PASSWORD_ID = "cred_password_inputtext"
SPACES_LOGIN_PASSWORD_INPUT = "//input[@id='" + SPACES_LOGIN_PASSWORD_ID + "']"
SPACES_LOGIN_SUBMIT_ID = "cred_sign_in_button"
SPACES_LOGIN_SUBMIT_BUTTON_XPATH = "//button[@id='" + SPACES_LOGIN_SUBMIT_ID + "']"
SPACES_USER_INFO_ELEM_XPATH = "//div[@data-tid = 'userInformation']"
SPACES_OPTIONS_DROPDOWN_BUTTON_ID = "personDropdown"
SPACES_OPTIONS_DROPDOWN_BUTTON_XPATH = "//footer/button[@id='personDropdown']"
SPACES_LOGOUT_BUTTON_ID = "logout-button"
CALLING_NOT_SUPPORTED_MESG = "//div[contains(text(),'This feature is coming and will be available real soon')]"
PLEASE_REFRESH_MSG = "Please refresh to try again"
REFRESH_BTN_XPATH = "//button[.= 'Refresh']"
MSFT_LOG_IN_WITH_USERNAME_AND_PASSWORD_LINK_XPATH = "//p[.='Sign in with a username and password instead']"
MSFT_LOGIN_PASSWORD_ID = "passwordInput"
MSFT_LOGIN_BUTTON_ID = "submitButton"
SHOW_MORE_TEAMS_BUTTON_XPATH = "//a[@data-tid='team-overflow-moreBtn']"
CALL_NOTIFICATION_WINDOW_XPATH = "//div[contains(@class,'notification')]"
CALL_NOTIFICATION_WINDOW_IS_CALLING_MESG_XPATH = "//div[contains(@class, 'subtitle') and contains(., 'is calling you')]"
CALL_NOTIFICATION_WINDOW_IS_NUDGING_MESG_XPATH = "//div[contains(@class, 'subtitle') and contains(., 'wants you to join a meeting')]"
CALL_NOTIFICATION_ACCEPT_CALL_VIDEO_BUTTON_XPATH = "//button[contains(@class, 'call-video')]"
CALL_NOTIFICATION_ACCEPT_CALL_AUDIO_BUTTON_XPATH = "//button[contains(@class, 'call-audio')]"
CALL_NOTIFICATION_REJECT_CALL_BUTTON_XPATH = "//button[contains(@class, 'call-reject')]"
CALL_NOTIFICATION_JUMP_IN_CALL_BUTTON_XPATH = "//button[contains(@class, 'jumpin')]"
CALL_NOTIFICATION_CHAT_CALL_BUTTON_XPATH = "//button[contains(@class, 'chat')]"
CHAT_SEARCH_INPUT_XPATH = "//div[@data-tid = 'left-rail-2']//input[@id = 'searchInput']"
CHAT_SEARCH_BUTTON_XPATH = "//div[@data-tid = 'left-rail-2']//button[@data-tid = 'searchBtn']"
CHAT_COMMON_COMMON_BTN_XPATH = "//button[(@data-tid = 'lr-create-chat-2') or (@data-tid = 'lr-create-chat-4') or (@data-tid = 'lr-create-chat') or contains(@data-tid , 'lr-create-chat')]"
CHAT_COMMON_CREATE_CHAT_BTN_XPATH = CHAT_COMMON_COMMON_BTN_XPATH
CHAT_CREATE_CHAT_BTN_XPATH = CHAT_COMMON_COMMON_BTN_XPATH
TEAMS_CREATE_CHAT_BTN_XPATH = CHAT_COMMON_COMMON_BTN_XPATH
CHAT_SEARCH_PEOPLE_TAB_XPATH = "//search//span[. = 'People']"
CHAT_LINK_XPATH_TEMPLATE = "//individual-search-category-people//div/div[. = '%s']/.."
CHAT_USERNAME_HEADER_XPATH_TEMPLATE = "//chat-header//img[@pl-upn = '%s']"
CHAT_VIDEO_CALL_START_BUTTON_XPATH = "//calling-start-button[@with-video = 'true']/button"
CHAT_AUDIO_CALL_START_BUTTON_XPATH = "//calling-start-button[not(@with-video) or @with-video = 'false']/button"
CHAT_VIDEO_CALL_JOIN_BUTTON_XPATH = "//calling-join-button[not(@audio-only) or @audio-only = 'false']/button"
CHAT_AUDIO_CALL_JOIN_BUTTON_XPATH = "//calling-join-button[@audio-only = 'true']/button"
CHAT_VIDEO_CALL_REJECT_BUTTON_XPATH = "//calling-reject-button/button"
CALL_1_1_PARTICIPANT_ANIMATION_XPATH_TEMPLATE = "//calling-animation-outgoing//img[@pl-upn = '%s']"
CALL_1_1_JOIN_ERROR_STATE_XPATH = "//div[contains(@class, 'state-description-title')]"
CHAT_ADD_PARTICIPANT_BUTTON_XPATH = "//chat-header//button[@data-tid = 'lr-create-group-chat']"
CHAT_PEOPLE_PICKER_INPUT_XPATH = "//div[@data-tid = 'createNewChat']//chat-people-picker//input"
CHAT_CREATE_NEW_INPUT_XPATH = "//chat-people-picker[@data-tid = 'mp-to-line']//input"
CHAT_USER_CHOOSER_XPATH = "//div[@data-tid = 'peoplepicker-dropdown']//div[contains(@class, 'result-image')]"
CHAT_ADD_USER_BUTTON_XPATH = "//div[@data-tid = 'createNewChat']//button[@data-tid = 'createChat-AddMembers']"
CHAT_GROUP_HEADER_XPATH_TEMPLATE = "//chat-header//span[@pl-upn = '%s']"
CHAT_RECENTS_ACTIVE_CALL_XPATH = "//div[@data-tid = 'left-rail-2']//active-calls-counter/span"
CHAT_MESSAGE_TEMPLATE_XPATH = "//div[@data-tid='messageThreadBody']//div[@data-tid='messageBodyContent']/div[text()='%s']"
CHANNEL_CONVERSATION_URL_TEMPLATE = "channel/%(team_name)s/%(channel_name)s/%(channel_thread_id)s/conversations?ctx=channel"
CHANNEL_CONVERSATION_TITLE_TEMPLATE = "//h2[@data-tid = 'messagesHeader-Title' and . = '%s']"
CHANNEL_CONVERSATION_CALL_START_BUTTON_XPATH = "//div[@id = 'add-new-message']//button[contains(@class, 'icons-call')][.//ng-include[contains(@src,'icons-call-meetup-line')]]"
CHANNEL_CONVERSATION_CALL_TITLE_INPUT_XPATH = "//div[contains(@class, 'title-container')]/input[contains(@class, 'title')]"
CHANNEL_CONVERSATION_NEW_CALL_START_BUTTON_XPATH = "//calling-start-button-rectangular/button"
CHANNEL_CONVERSATION_JUMP_IN_BUTTON_MOST_RECENT_XPATH = "//calling-thread-header//calling-join-button[last()]/button"
CHANNEL_CONVERSATION_JUMP_IN_BUTTON_FOR_INITIATOR_SPECIFIED_XPATH_TEMPLATE = "//div[contains(@class,'ts-calling-thread-header')][img[@pl-upn='%s']]//calling-join-button/button"
CHANNEL_CONVERSATION_JOIN_BUTTON_BY_CALL_ID_TEMPLATE = "//button[@data-tid = 'join-btn-%s']"
CHANNEL_CONVERSATION_CALL_STARTED_IN_PROGRESS_MESSAGE_TEMPLATE = "//div[@data-tid = 'in-progress-%s']"
CHANNEL_CONVERSATION_MEETUP_TITLE_FOR_INITIATOR_SPECIFIED_XPATH_TEMPLATE = "//calling-thread-header[.//img[@pl-upn ='%s']]//div[contains(@class, 'title')]"
CHANNEL_CONVERSATION_MEETUP_TITLE_FOR_CALL_ID_XPATH_TEMPLATE = "//calling-thread-header[.//button[contains(@data-tid , 'join-btn-%s')]]//div[contains(@class, 'title')]"
CHANNEL_CONVERSATION_MEETUP_TITLE_FOR_ONGOING_MEETUP_TEMPLATE = "//calling-thread-header[.//button[contains(@data-tid,'join-btn-')]]"
CHANNEL_CONVERSATION_MEETUP_TITLE_GETS_CHANGED_FOR_CALL_ID_XPATH_TEMPLATE = "//calling-thread-header[.//button[contains(@data-tid , 'join-btn-')]]//div[@title = '%s']"
CHANNEL_PERSISTENT_INDICATOR_JUMP_IN_BUTTON_XPATH = "//calling-persistent-indicator//div[@title = '%s']/../..//calling-join-button/button"
CHANNEL_CONVERSATION_AVATAR_IN_CALLING_HEADER_ROSTER_XPATH_TEMPLATE = "//calling-thread-header//calling-live-roster//img[@pl-upn = '%s']/../../img[@pl-upn]"
CHANNEL_CALLING_LIVE_ROSTER_FOR_MEETUP_XPATH_TEMPLATE = "//calling-live-roster"
CHANNEL_CONVERSATION_CALL_MONITOR_XPATH = "//calling-monitor/div[contains(@class, 'ts-show-cursor')]"
CHANNEL_CONVERSATION_MEETUP_ENDED_XPATH_TEMPLATE = "(//div[contains(@class, 'ts-message-list-item')]//img[@pl-upn = '%s'])[last()]/../../../div[contains(., '%s')]"
CHANNEL_CONVERSATION_MEETUP_ENDED_XPATH_DTID_TEMPLATE = "//div[@data-tid = 'call-ended-%s']"
CHANNEL_CONVERSATION_MEETUP_IN_PROGRESS_XPATH_DTID_TEMPLATE = "//div[@data-tid = 'in-progress-%s']"
CHANNEL_CONVERSATION_MEETUP_ENDED_MESG = "ended:"
CHANNEL_PERSISTENT_INDICATOR_MORE_BUTTON_XPATH = "//calling-persistent-indicator//a[contains(@class, 'toggle-button')]"
CQF_RATING_ELEM_XPATH_TEMPLATE = "//calling-thread-body[." + CHANNEL_CONVERSATION_MEETUP_ENDED_XPATH_DTID_TEMPLATE + "]//star-rating"
CQF_NTH_STAR_XPATH_TEMPLATE = CQF_RATING_ELEM_XPATH_TEMPLATE + "//div[contains(@class, 'stars')]/a[%d]"
CQF_THANKS_FOR_FEEDBACK_XPATH_TEMPLATE = "//calling-thread-body[." + CHANNEL_CONVERSATION_MEETUP_ENDED_XPATH_DTID_TEMPLATE + "]//thanks-for-feedback"
CQF_THANKS_FOR_FEEDBACK_IN_PROGRESS_XPATH_TEMPLATE = "//calling-thread-body[." + CHANNEL_CONVERSATION_MEETUP_IN_PROGRESS_XPATH_DTID_TEMPLATE + "]//thanks-for-feedback"
CQF_QUESTIONNAIRE_ITEMS_XPATH_TEMPLATE = "//calling-thread-body[." + CHANNEL_CONVERSATION_MEETUP_ENDED_XPATH_DTID_TEMPLATE + "]//calling-quality-feedback//div[contains(@class, 'questionnaire-items')]"
CQF_QUESTIONNAIRE_BUTTONS_XPATH_TEMPLATE = "//calling-thread-body[." + CHANNEL_CONVERSATION_MEETUP_ENDED_XPATH_DTID_TEMPLATE + "]//calling-quality-feedback//div[contains(@class, 'questionnaire-buttons')]"
CQF_QUESTIONNAIRE_ITEM_CALLING_XPATH_TEMPLATE = CQF_QUESTIONNAIRE_ITEMS_XPATH_TEMPLATE + "//div[contains(@class, 'type') and not(contains(@class, 'types'))][1]"
CQF_QUESTIONNAIRE_ITEM_VIDEO_XPATH_TEMPLATE = CQF_QUESTIONNAIRE_ITEMS_XPATH_TEMPLATE + "//div[contains(@class, 'type') and not(contains(@class, 'types'))][2]"
CQF_QUESTIONNAIRE_ITEM_PRESENTING_XPATH_TEMPLATE = CQF_QUESTIONNAIRE_ITEMS_XPATH_TEMPLATE + "//div[contains(@class, 'type') and not(contains(@class, 'types'))][3]"
CQF_QUESTIONNAIRE_SUBMIT_BUTTON_XPATH_TEMPLATE = CQF_QUESTIONNAIRE_BUTTONS_XPATH_TEMPLATE + "//button[1]"
CQF_QUESTIONNAIRE_CANCEL_BUTTON_XPATH_TEMPLATE = CQF_QUESTIONNAIRE_BUTTONS_XPATH_TEMPLATE + "//button[2]"
CALLING_SCREEN_XPATH = "//calling-screen"
CALL_COUNTER_XPATH = "//calling-duration"
CALLING_SCREEN_PARTICIPANT_AVATAR_XPATH_TEMPLATE = "//calling-participant-stream//img[@pl-upn = '%s']"
CALLING_SCREEN_SPECIFIC_PARTICIPANT_VISIBLE_STREAM_XPATH = "//calling-participant-stream/div[contains(@class,'ts-calling-participant-stream')][.//img[@pl-upn = '%s']]"
CALLING_SCREEN_NONSPECIFIC_PARTICIPANT_VISIBLE_STREAM_XPATH = "//calling-participant-stream/div[contains(@class,'ts-calling-participant-stream')][.//img[contains(@pl-upn , '%s')]]"
CALLING_SCREEN_GROUP_CALL_PARTICIPANT_AVATAR_XPATH_TEMPLATE = "//calling-stage//calling-participant-stream//img[@pl-upn = '%s']"
CALLING_SCREEN_PARTICIPANT_AVATAR_XPATH_ENTRY = "//calling-participant-stream//img[@pl-upn]"
CALLING_SCREEN_GROUP_CALL_PARTICIPANT_AVATAR_XPATH_ENTRY = "//calling-stage//calling-participant-stream//img[@pl-upn]"
CALLING_SCREEN_PARTICIPANT_SHARING_SCREEN_AVATAR_XPATH_TEMPLATE = "//div[contains(@class, 'PRESENTATION')]//calling-stage//calling-participant-stream//img[@pl-upn = '%s']"
CALLING_SCREEN_SHARE_DESKTOP_PANEL_XPATH = "//div[contains(@class, 'ts-calling-screensharing-panel')]"
CALLING_SCREEN_SHARE_DESKTOP_PANEL_SCREEN_XPATH = "//div[contains(@class, 'ts-calling-screensharing-panel')]//div[contains(@class, 'screen')]"
CALLING_SCREEN_HANGUP_BUTTON_XPATH = "//button[contains(@class, 'ts-hangup')]"
CALLING_SCREEN_SHARE_DESKTOP_BUTTON_XPATH = "//button[contains(@class, 'share-desktop')]"
CALLING_SCREEN_TOGGLE_MIC_BUTTON_XPATH = "//button[contains(@ng-click, 'toggleMuteAudio')]"
CALLING_SCREEN_PARTICIPANT_STREAM_XPATH = "//calling-participant-stream"
#CALLING_SCREEN_TOGGLE_VIDEO_BUTTON_XPATH = "//button[contains(@title, 'video')]"
CALLING_SCREEN_TOGGLE_VIDEO_BUTTON_XPATH = "//button[@calling-screen-focus='toggle-video-button']"
CALLING_SCREEN_TURN_OFF_VIDEO_BUTTON_XPATH = CALLING_SCREEN_TOGGLE_VIDEO_BUTTON_XPATH + "[@common-tooltip='Stop my video' or @title = 'Stop my video']"
CALLING_SCREEN_TURN_ON_VIDEO_BUTTON_XPATH = CALLING_SCREEN_TOGGLE_VIDEO_BUTTON_XPATH + "[@common-tooltip='Start my video' or @title = 'Start my video']"
CALLING_SCREEN_MEETUP_TITLE_XPATH = "//editable-text//div[contains(@class, 'inputContainer')]/input[@readonly='readonly']"
CALLING_SCREEN_MEETUP_TITLE_INPUT_XPATH = "//editable-text//input[not(@readonly='readonly')]"
CALLING_SCREEN_MEETUP_TITLE_INPUT_SAVED_XPATH = "//editable-text[@title-text='%s']//input[@readonly='readonly']"
CALLING_SCREEN_MEETUP_TITLE_SAVE_XPATH = "//span[@title = 'Save title']"
CALLING_SCREEN_DURATION_TIMER = "//calling-duration/span[contains(@class,'calling-duration')][contains(@class,'timer')]"
CALLING_MYSELF_VIDEO_XPATH_EXPANDED = "//calling-myself-video/div[contains(@class,'calling-myself-video')][contains(@class,'expanded')]/canvas"
CALLING_MYSELF_VIDEO_XPATH_COLLAPSED = "//calling-myself-video/div[contains(@class,'calling-myself-video')][not(contains(@class,'expanded'))]/canvas"
VIDEO_TOGGLE_XPATH = "//button[@calling-screen-focus='toggle-video-button']"
VIDEO_TURN_ON_XPATH = "//button[@calling-screen-focus='toggle-video-button'][@aria-label='Your video is off. Start video']"
VIDEO_TURN_OFF_XPATH = "//button[@calling-screen-focus='toggle-video-button'][@aria-label='Your video is on. Stop video']"
# When experimental setting use pepper renderer is enabled then on calling screen is not present canvas elemnt containing video stream but embed is there instead so this will works in both cases in the same way as previously without need to change anything else
CALLING_MYSELF_VIDEO_XPATH = "//calling-myself-video//div[contains(@class,'video-stream-container')][//embed or //canvas]"
CALLING_MYSELF_AVATAR_XPATH = "//calling-myself-video/div[contains(@class, 'audioOnly')]"
CALLING_SCREEN_TOGGLE_FULLSCREEN = "//calling-header//button[@ngsf-toggle-fullscreen]"
CALLING_SCREEN_TOGGLE_CHAT_ENABLED_XPATH = "//button[not(@disabled) and contains(@class, 'toggle-chat')]"
CALLING_SCREEN_TOGGLE_CHAT_ENABLED_NOT_ACTIVE_XPATH = "//button[not(@disabled) and contains(@class, 'toggle-chat') and not(contains(@class, 'active'))]"
CALLING_SCREEN_TOGGLE_CHAT_ENABLED_ACTIVE_XPATH = "//button[not(@disabled) and contains(@class, 'toggle-chat') and contains(@class, 'active')]"
CALLING_SCREEN_ADD_PARTICIPANT_BUTTON_XPATH = "//button[not(@disabled) and contains(@class, 'toggle-roster') and not(contains(@class, 'active'))]"
CALLING_SCREEN_DEVICE_SETTINGS_BUTTON_XPATH = "//calling-header//button[contains(@class, 'toggle-device-settings')]"
CALLING_SCREEN_IN_CHAT_PANE_XPATH = "//context-message-pane"
CALLING_SCREEN_MESSAGE_EDITOR_XPATH = "//div[@data-tid = 'messageEditor']"
CALLING_SCREEN_MESSAGES_PANE_TEXT_XPATH_TEMPLATE = "//div[@data-tid = 'messageBodyContent']//div[contains(., '%s')]"
TEAM_CHANNEL_NEW_MESSAGE_INPUT_XPATH = "//div[@data-tid='messageEditor']//div[contains(@class,'cke_editor')]//div[@data-tid='ckeditor-newConversation']"
TEAM_CHANNEL_NEW_MESSAGE_INPUT_FOCUSED_XPATH = "//div[@data-tid='messageEditor']//div[contains(@class,'cke_editor')][contains(@class,'cke_focus')]//div[@data-tid='ckeditor-newConversation']"
CHAT_NEW_MESSAGE_INPUT = "//div[@data-tid='ckeditor-newP2PMessage']"
CHAT_NEW_MESSAGE_INPUT_COMMON = "//div[@data-tid='messageEditor']" + CHAT_NEW_MESSAGE_INPUT
CHAT_NEW_MESSAGE_INPUT_FOCUSED = "//div[@data-tid='messageEditor']//div[contains(@class,'cke_focus')]" + CHAT_NEW_MESSAGE_INPUT
CHAT_NEW_MESSAGE_INPUT_NOT_FOCUSED = "//div[@data-tid='messageEditor']//div[not(contains(@class,'cke_focus'))]" + CHAT_NEW_MESSAGE_INPUT
CALLING_SCREEN_NEW_MESSAGE_INPUT = "//calling-chat[contains(@class,'active') and not(contains(@class,'ng-hide'))]//div[@data-tid='messageEditor']" + CHAT_NEW_MESSAGE_INPUT
CALLING_SCREEN_NEW_MESSAGE_INPUT_FOCUSED = "//calling-chat[contains(@class,'active') and not(contains(@class,'ng-hide'))]//div[@data-tid='messageEditor'][.//div[contains(@class,'cke_focus')]]" + CHAT_NEW_MESSAGE_INPUT
CALLING_SCREEN_ADD_PARTICIPANT_PANE_XPATH = "//calling-roster"
CALLING_SCREEN_INVITE_INPUT_XPATH = "//calling-roster-search//input[@id = 'searchInput']"
CALLING_SCREEN_CURRENTLY_IN_MEETING_LABEL_XPATH = "//calling-roster-section[@data-tid = 'participantsInCall']//div[contains(@class, 'roster_list_title')]"
CALLING_SCREEN_FROM_THREAD_LABEL_XPATH = "//calling-roster-section[@data-tid = 'participantsFromThread']//div[contains(@class, 'roster_list_title')]"
CALLING_SCREEN_ROSTER_LIST_LABEL_XPATH = "//calling-roster-section[@data-tid = 'participantsFromTeam']//div[contains(@class, 'roster_list_title')]"
CALLING_SCREEN_FROM_MEETING_LABEL_XPATH = "//calling-roster-section[@data-tid = 'participantsFromMeeting']//div[contains(@class, 'roster_list_title')]"
CALLING_SCREEN_SEARCH_RESULT_USER_XPATH_TEMPLATE = "//calling-roster-search-results//li[contains(@class,'item')][.//img[@pl-upn='%s']]"
CALLING_SCREEN_USER_CONNECTING_XPATH_TEMPLATE = "//calling-roster-section//div[contains(@class, 'roster_list_title')]/..//img[@pl-upn = '%s']"
CHANNEL_CONVERSATION_MEETUP_ENDED_XPATH_PARTICIPANT_LIST = "//calling-thread-body[.//div[contains(text(), '%s')]]//calling-live-roster"
CALLING_SCREEN_ADD_PARTICIPANT_INVITE_OTHERS_FROM_CONV_ALL_ENTRIES = "//calling-roster-section[@data-tid='participantsFromThread']//ul[@class='items']/li"
IMAGE_CONTAINS_EMAIL_ADDRESS = "[.//img[@pl-upn = '%s']]"
CHANNEL_REPLY_BTN_FOR_CALL_ID_TEMPLATE = "//thread[." + CHANNEL_CONVERSATION_MEETUP_ENDED_XPATH_DTID_TEMPLATE + "]//button[@data-tid = 'replyMessageButtonShort']"
CHANNEL_REPLY_MESSAGE_INPUT_XPATH_TEMPLATE = "//thread[." + CHANNEL_CONVERSATION_MEETUP_ENDED_XPATH_DTID_TEMPLATE + "]//div[@data-tid = 'ckeditor-replyConversation']"
CHANNEL_REPLY_CHAIN_MESSAGE_CONTENT_CALL_ID_XPATH_TEMPLATE = "//thread[." + CHANNEL_CONVERSATION_MEETUP_ENDED_XPATH_DTID_TEMPLATE + "]//div[@data-tid = 'messageBodyContent']//div[. = '%s']"
CHANNEL_REPLY_CHAIN_CALL_START_BUTTON_XPATH_TEMPLATE = "//thread[." + CHANNEL_CONVERSATION_MEETUP_ENDED_XPATH_DTID_TEMPLATE + "]//button[contains(@class, 'icons-call')]"
CHANNEL_REPLY_CHAIN_JOIN_BUTTON_BY_CALL_ID_TEMPLATE = "//button[@data-tid = 'join-btn-%s']"
CHANNEL_LIST_XPATH = "//div[@data-tid = 'team-channel-list']"
CHANNEL_LIST_TEAM_NAMED_XPATH = CHANNEL_LIST_XPATH + "[.//span[contains(text(),'%s')]]"
TEAM_CHANNEL_NAMED_XPATH = CHANNEL_LIST_TEAM_NAMED_XPATH + "/..//li[contains(@id,'@thread.skype')][.//span[contains(text(),'%s')]]"
CHAT_LIST_XPATH = "//chat-list"
APP_BAR_CHAT_BUTTON_XPATH = "//app-bar//button[@data-tid = 'app-bar-2']"
APP_BAR_TEAMS_BUTTON_XPATH = "//app-bar//button[@data-tid = 'app-bar-4']"
CALLING_HEADER_MENU_XPATH = "//calling-header//button[contains(@title, 'Toggle sidebar')]"
LEFT_RAIL_USER_INFO_XPATH = "//user-information/div[contains(@class, 'app-user-information')]"
CALL_HANGING_UP_XPATH = "//div[contains(@class, 'call-state-layer')]"
FIND_ELEMENT_BY_XPATH_JS_TEMPLATE = "var %s = document.evaluate(\"%s\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;"
SCROLL_DOWN_ELEMENT_JS = "elem.scrollTop = elem.scrollHeight;"
SCROLL_UP_ELEMENT_JS = "elem.scrollTop = 0;"
CHECK_IF_IN_VIEWPORT_JS = """
function isInViewport(element) {
var rect = element.getBoundingClientRect();
var html = document.documentElement;
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || html.clientHeight) &&
rect.right <= (window.innerWidth || html.clientWidth)
);
}
"""
# SCROLL_TO_ELEMENT_JS_TEMPLATE = CHECK_IF_IN_VIEWPORT_JS + "myElem = %s; if (myElem) { if (!isInViewport(myElem)) { myElem.scrollIntoView();}; };"
SCROLL_TO_ELEMENT_JS_TEMPLATE = "myElem = %s; if (myElem) { myElem.scrollIntoView();};"
LOGOUT_EXE_ANGULAR_JS = "angular.element(document.body).injector().get('authenticationService').logOut();"
CALL_HANGUP_EXE_ANGULAR_JS = "angular.element(document.body).injector().get('callingService').callRegistry.calls[0].stop();"
CALL_STOP_VIDEO_EXE_ANGULAR_JS = "angular.element(document.body).injector().get('callingService').callRegistry.calls[0].stopVideo();"
CALL_START_VIDEO_EXE_ANGULAR_JS = "angular.element(document.body).injector().get('callingService').callRegistry.calls[0].startVideo();"
GET_CALL_ID_ANGULAR_JS = "return angular.element(document.body).injector().get('callingService').callRegistry.calls[0].callId"
TOGGLE_CALLING_HEADER_MENU_JS = "document.evaluate(\"%s\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();"
TYPE_TEXT_TO_XPATH_ELEMENT_JS_TEMPLATE = "document.evaluate(\"%s\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.value = '%s';"
GET_ALL_LOG_EVENTS_JS = "var logs = angular.element(document.body).injector().get('diagnosticsService').getAllEvents(); var result = ''; _.orderBy(logs, ['timeStamp'], ['desc']).forEach((value) => { var date = moment(value.timeStamp).toISOString(); result += angular.element(document.body).injector().get('utilityService').format('{0} {1}\\t{2}\\r\\n', date, value.levelName.substring(0, 3), value.message); }); return result;"
TAB_ORDERS = {
"calling_screen": [
CALLING_SCREEN_TOGGLE_FULLSCREEN,
CALLING_SCREEN_TOGGLE_CHAT_ENABLED_XPATH,
CALLING_SCREEN_ADD_PARTICIPANT_BUTTON_XPATH,
CALLING_SCREEN_DEVICE_SETTINGS_BUTTON_XPATH,
CALLING_SCREEN_INVITE_INPUT_XPATH,
CALLING_SCREEN_CURRENTLY_IN_MEETING_LABEL_XPATH,
CALLING_SCREEN_FROM_THREAD_LABEL_XPATH,
CALLING_SCREEN_ROSTER_LIST_LABEL_XPATH,
CALLING_SCREEN_FROM_MEETING_LABEL_XPATH,
CALLING_SCREEN_TOGGLE_VIDEO_BUTTON_XPATH,
CALLING_SCREEN_TOGGLE_MIC_BUTTON_XPATH,
CALLING_SCREEN_SHARE_DESKTOP_BUTTON_XPATH,
CALLING_SCREEN_HANGUP_BUTTON_XPATH
]
}
####################
# Element data end #
####################
def __init__(self, env_id, build_name, build_path):
# logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s', level=logging.INFO, stream=sys.stdout)
logging.basicConfig(format='%(levelname)s || %(asctime)s || %(funcName)s || %(message)s', datefmt='%I:%M:%S', level=logging.INFO, stream=sys.stdout)
self.is_local = False
self.run_mode = None
self.test_config = None
self.build_name = build_name
self.build_path = build_path
self.env_id = env_id
self.experimental_setting = None
self.spaces_driver = None
self.webdriver_bin = None
self.show_console_logs = True
self.sys = PlatformLib(env_id, build_name, build_path)
self.accessibility = None
self.video_recorder = None
self.recording_in_progress = False
try:
if Castro:
os.environ['CASTRO_DATA_DIR'] = "."
self.video_recorder = Castro()
except NameError:
pass
@staticmethod
def start_debugger():
pdb.set_trace()
@staticmethod
def wait_for_seconds(seconds):
logging.info("Static Pause for : {0} seconds".format(seconds))
time.sleep(seconds)
def prepare_test_env(self, config, user_accounts=None, test_channel_data=None, uninstall_app_before_preparation=UNINSTALL_APP_BEFORE_SETUP):
logging.info("Started prepearing test environment...")
self.test_config = TestConfigLoader(config)
self.run_mode = self.test_config.get_run_mode()
logging.info("Current run mode is: {}".format(self.run_mode))
self.webdriver_bin = self.sys.lib.get_driver_bin(self.run_mode)
if self.test_config.is_local_run():
self.is_local = True
if self.is_teams_desktop_app_run():
if self.test_config.enable_slimcore():
self.ENABLE_SLIMCORE = True
if self.is_local:
self.sys.lib.kill_chromedriver()
else:
if uninstall_app_before_preparation:
self.sys.lib.uninstall_skypespaces()
self.sys.lib.kill_chromedriver()
self.sys.lib.install_skypespaces()
self.initialize(test_channel_data)
self.load_test_accounts(user_accounts)
def is_teams_desktop_app_run(self):
logging.info("is_desktop_run")
if self.run_mode == "electron":
return True
elif self.run_mode == "chrome" or "edge":
return False
else:
logging.info("Unknown run_mode = '{0}'".format(self.run_mode))
return False
def initialize(self, test_channel_data=None):
"""
Sets up test environment on system - launches chromedriver, launches SkypeSpaces app and hooks to it
:return:
"""
logging.info("Microsoft Teams::initialize environment")
self.start_video_recording()
if test_channel_data and len(test_channel_data) == 3:
self.test_config.load_test_data_from_config(team=test_channel_data[0], channel=test_channel_data[1], channel_id=test_channel_data[2])
else:
self.test_config.load_test_data_from_config()
if self.is_teams_desktop_app_run():
logging.info("Running desktop app....")
if not os.path.isfile(self.sys.lib.skypespaces_bin):
logging.error("Cannot find SkypeSpaces binary: {}".format(self.sys.lib.skypespaces_bin))
raise Exception("Cannot find SkypeSpaces binary: {}".format(self.sys.lib.skypespaces_bin))
# Make sure app is not running before we try to attach to it
logging.info("Terminating the app in case if it is currently running...")
self.sys.lib.terminate_app()
else:
# TODO: Browser webdriver init (if needed)
self.wait_for_seconds(1)
# Web Driver Initialization
self.spaces_driver = SpacesWebDriver(skypespaces_bin=self.sys.lib.skypespaces_bin, driver_bin=self.sys.lib.get_driver_bin(self.run_mode), run_mode=self.run_mode, system_lib=self.sys, enable_slimcore=self.ENABLE_SLIMCORE)
self.wait_for_seconds(30)
self.accessibility = Accessibility(self.spaces_driver, self.sys)
self.focus_spaces_app()
if self.is_teams_desktop_app_run():
self.open_teams_app()
else:
if self.run_mode is "edge" or "chrome":
self.enable_calling_in_browser()
self.open_teams_web_app()
return
def is_msteams_app_opened(self):
logging.info("is_msteams_app_opened")
logging.info("Waiting for app to start..")
self.spaces_driver.wait_for_element(locator=self.ELECTRON_APP_HANDLER_XPATH, locator_type=self.XPATH, timeout=self.LOADING_TIMEOUT, fail_on_not_found=False)
if self.spaces_driver.is_element_present(locator=self.ELECTRON_APP_HANDLER_XPATH, locator_type=self.XPATH):
logging.info("SUCCESS - MS Teams App Handler XPath found")
return True
else:
logging.info("WARNING - MS Teams App Handler XPath not found \n Waiting for 20s and re-attempting to focus MS Teams app")
self.wait_for_seconds(20)
self.focus_spaces_app()
logging.info("App window focused checking if MSTeams App handler Xpath is present timeout = 20s")
if self.spaces_driver.is_element_present(locator=self.ELECTRON_APP_HANDLER_XPATH, locator_type=self.XPATH, timeout=20):
return True
else:
logging.info("ERROR - MS Teams app handler xpath not found !!!")
return False
def enable_experimental_setting_in_url(self, setting):
if not setting:
return
logging.info("Enabling experimental setting '%s'" % setting)
if "?" in self.test_config.base_url:
self.test_config.base_url = self.test_config.base_url.replace("?", str("?setting=%s:true&") % setting, 1)
elif "#" in self.test_config.base_url:
self.test_config.base_url = self.test_config.base_url.replace("#", str("?setting=%s:true#") % setting, 1)
def open_teams_app(self):
logging.info("open_teams_app")
try:
logging.info("Obtain opened URL")
loaded_url = self.spaces_driver.driver.current_url
except Exception, e:
logging.info("Exception {0}".format(e))
logging.info("If block reached")
if self.MSFT_LOGIN_PAGE in loaded_url or self.test_config.base_url in loaded_url:
logging.info("Web container initialized successfully")
self.spaces_driver.take_screen_shot("used_web_container")
return True
else:
logging.info("Seems web container not opened correctly.")
logging.info("Url loaded: {0}".format(self.spaces_driver.driver.current_url))
return False
def enable_calling_in_browser(self):
logging.info("enable_calling_in_browser")
if self.run_mode == "edge":
logging.info("Enabling calling in the Edge browser")
self.enable_experimental_setting_in_url("callingEnabledEdge")
if self.run_mode == "chrome":
logging.info("Enabling calling in the Edge browser")
# todo: enable calling in chrome experimental settings enable
# self.enable_experimental_setting_in_url("nameOfSettingForChrome")
def open_teams_web_app(self, enable_calling_in_browser=ENABLE_CALLING_IN_BROWSER, retries=10):
logging.info("open_teams_web_app(enable_calling_in_browser = '{0}', retries = '{1}')".format(enable_calling_in_browser, retries))
if not self.is_teams_desktop_app_run() or self.FORCE_WEB_URL_LOAD or (self.CONTAINER_ARG in self.test_config.base_url) or (self.RING_ARG in self.test_config.base_url):
if enable_calling_in_browser:
self.enable_calling_in_browser()
else:
logging.info("Enabling calling in browser is disabled via PARAMETER 'enable_calling_in_browser' = '{0}'".format(enable_calling_in_browser))
for attempt in range(0, retries):
logging.info("Attempt #{0} of {2}: \n Navigating to MSTeams web_app URL: {1} ".format(attempt, self.test_config.base_url, retries))
try:
self.spaces_driver.driver.get(self.test_config.base_url)
self.spaces_driver.wait_for_page_to_load()
loaded_url = self.spaces_driver.driver.current_url
except Exception, e:
logging.info("Exception {0}".format(e))
if self.MSFT_LOGIN_PAGE in loaded_url or self.test_config.base_url in loaded_url:
logging.info("Teams web app Loaded and matching passed against known URLs")
self.wait_for_seconds(1)
self.spaces_driver.take_screen_shot("opened_teams_web_app")
return
else:
logging.info("ERROR while loading TEAMS web app [wasn't loaded yet tries {0} from {1} or matching against known URLs was unsuccessful]".format(attempt, retries))
logging.info("\n Condition not met 'self.MSFT_LOGIN_PAGE in loaded_url or self.test_config.base_url in loaded_url' \n")
logging.info("self.MSFT_LOGIN_PAGE = {0}".format(self.MSFT_LOGIN_PAGE))
logging.info("self.test_config.base_url = {0}".format(self.test_config.base_url))
logging.info("loaded_url = {0} \n WARNING !!! ".format(self.spaces_driver.driver.current_url))
self.wait_for_seconds(1)
continue
raise Exception("Could not navigate to web container {0}".format(self.test_config.base_url))
def get_test_account(self, index):
logging.info("Getting test account #" + str(index))
return self.test_config.test_accounts [index]
def get_test_accounts(self):
return self.test_config.test_accounts
def get_test_channel_data(self):
return [self.test_config.test_team, self.test_config.test_channel, self.test_config.test_channel_thread_id]
def login_viliams(self, user_account_tuple, retries=6):
logging.info("login_viliams")
username = user_account_tuple ['username']
password = user_account_tuple ['password']
logging.info("Starting login in process for User : {0} with password : {1}".format(username, password))
self.focus_spaces_app(retries=retries)
counter = 0
while not self.spaces_driver.wait_for_page_to_load() and counter <= retries:
logging.info("Attempt number : '{0}'".format(counter))
counter += 1
logging.info("Page not loaded yet waiting for 10 seconds")
self.wait_for_seconds(10)
logging.info("Page Loaded document.readyState == Complete")
another_account_common_presence = self.spaces_driver.is_element_present(locator=self.USE_ANOTHER_ACCOUNT_ELEMENTS_LIST, locator_type=self.XPATH, timeout=0)
another_account_id_is_present = self.spaces_driver.is_element_present(locator=self.SPACES_LOGIN_USE_ANOTHER_ACCOUNT_ID, locator_type=self.ID, timeout=0)
another_account_link_id_is_present = self.spaces_driver.is_element_present(locator=self.SPACES_LOGIN_USE_ANOTHER_ACCOUNT_LINK_ID, locator_type=self.ID, timeout=0)
if another_account_common_presence:
logging.info("Another account screen was detected")
logging.info("another_account_common_presence is True =?= {0}".format(another_account_common_presence))
if another_account_id_is_present:
logging.info("another_account_id_is_present is True =?= {0}".format(another_account_id_is_present))
element = self.spaces_driver.wait_for_element(locator=self.SPACES_LOGIN_USE_ANOTHER_ACCOUNT_ID, locator_type=self.ID, timeout=self.LOADING_TIMEOUT)
element.click()
elif another_account_link_id_is_present:
logging.info("another_account_link_id_is_present is True =?= {0}".format(another_account_link_id_is_present))
element = self.spaces_driver.wait_for_element(locator=self.SPACES_LOGIN_USE_ANOTHER_ACCOUNT_LINK_ID, locator_type=self.ID, timeout=self.LOADING_TIMEOUT)
element.click()
logging.info("Another account screen was proceeded successfully")
username_input = self.spaces_driver.wait_for_element(locator=self.SPACES_LOGIN_USERNAME_INPUT, locator_type=self.XPATH, timeout=self.LOADING_TIMEOUT)
username_input.send_keys(username)
username_input.send_keys(self.spaces_driver.keys.TAB)
password_input = self.spaces_driver.wait_for_element(locator=self.SPACES_LOGIN_PASSWORD_INPUT, locator_type=self.XPATH, timeout=self.LOADING_TIMEOUT)
logging.info("Going to Fill in Password : '{0}'".format(password))
password_input.send_keys(password)
submit = self.spaces_driver.wait_for_element(locator=self.SPACES_LOGIN_SUBMIT_BUTTON_XPATH, locator_type=self.XPATH, timeout=self.LOADING_TIMEOUT)
submit.click()
def login(self, user_account):
logging.info("login")
self.logout_if_logged_in()
self.focus_spaces_app()
self.spaces_driver.wait_for_page_to_load()
logging.info("Logging in user {0}".format(str(user_account)))
self.spaces_driver.take_screen_shot("going_to_login")
another_account_elem_id = None
need_to_use_another_account = False
if self.spaces_driver.is_element_present(self.SPACES_LOGIN_USE_ANOTHER_ACCOUNT_ID, self.ID, 0):
another_account_elem_id = self.SPACES_LOGIN_USE_ANOTHER_ACCOUNT_ID
need_to_use_another_account = True
elif self.spaces_driver.is_element_present(self.SPACES_LOGIN_USE_ANOTHER_ACCOUNT_LINK_ID, self.ID, 0):
another_account_elem_id = self.SPACES_LOGIN_USE_ANOTHER_ACCOUNT_LINK_ID
need_to_use_another_account = True
if need_to_use_another_account:
logging.info("Clicking at 'Use another account' link on login page.")
use_another_account = self.spaces_driver.driver.find_element_by_id(another_account_elem_id)
use_another_account.click()
username = self.spaces_driver.wait_for_element(locator=self.SPACES_LOGIN_USERNAME_INPUT, locator_type=self.XPATH, timeout=self.LOADING_TIMEOUT)
username.send_keys(user_account ['username'])
username.send_keys(self.spaces_driver.keys.TAB)
self.login_page_redirection_detection_and_handling()
#self.un_focus_spaces_app()
#self.spaces_driver.take_screen_shot("logging_in")
#self.focus_spaces_app()
if self.spaces_driver.is_element_present(self.SPACES_LOGIN_PASSWORD_INPUT, self.XPATH, 5):
logging.info("User is non-corporate account")
self.spaces_driver.take_screen_shot("non-corp_login")
self.spaces_driver.wait_for_element(self.SPACES_LOGIN_PASSWORD_INPUT, self.XPATH)
password = self.spaces_driver.driver.find_element_by_id(self.SPACES_LOGIN_PASSWORD_ID)
password.send_keys(user_account ['password'])
submit = self.spaces_driver.driver.find_element_by_id(self.SPACES_LOGIN_SUBMIT_ID)
self.spaces_driver.take_screen_shot("going_click_at_login")
submit.click()
# self.spaces_driver.click_js(submit)
self.un_focus_spaces_app()
self.wait_for_seconds(30)
self.spaces_driver.wait_for_page_to_load()
logging.info("User '" + user_account ['username'] + "' is being logged in..")
return
elif self.spaces_driver.is_element_present(locator=self.MSFT_LOGIN_PASSWORD_ID, locator_type=self.ID, timeout=5) or self.spaces_driver.is_element_present(locator=self.MSFT_LOG_IN_WITH_USERNAME_AND_PASSWORD_LINK_XPATH, locator_type=self.XPATH, timeout=5):
logging.info("User is corporate account")
self.spaces_driver.take_screen_shot("corp_login")
self.login_msftcorp(user_account ['password'])
return
raise Exception("ERROR - something went wrong while logging in.....")
def is_login_page_redirecting(self):
logging.info("is_login_page_redirecting")
if self.spaces_driver.is_element_visible(locator=self.TEAMS_LOGIN_REDIRECTING_IS_VISIBLE, locator_type=self.XPATH, timeout=1):
logging.info("Redirecting detected @!!!")
return True
else:
logging.info("Redirecting wasn't to be visible on page")
return False
def login_page_redirection_detection_and_handling(self):
logging.info("login_page_redirection_detection_and_handling")
for i in range(1, 30):
self.wait_for_seconds(0.5)
logging.info("Detection attempt i = '{0}'".format(i))
if self.is_login_page_redirecting():
logging.info("Redirecting Detected now handling wait till its disappearance")
while self.is_login_page_redirecting():
logging.info("waiting for Redirecting disappearance")
self.wait_for_seconds(1)
logging.info("waiting finished redirecting is not longer detected")
return
logging.info("Exiting 'login_page_redirection_detection_and_handling'")
def login_msftcorp(self, msft_password):
logging.info("login_msftcorp")
self.spaces_driver.wait_for_element(self.MSFT_LOGIN_PASSWORD_ID, self.ID)
if self.spaces_driver.is_element_present(self.MSFT_LOG_IN_WITH_USERNAME_AND_PASSWORD_LINK_XPATH, self.XPATH, 10):
login_username_pass = self.spaces_driver.wait_for_element(locator=self.MSFT_LOG_IN_WITH_USERNAME_AND_PASSWORD_LINK_XPATH, locator_type=self.XPATH, timeout=self.LOADING_TIMEOUT)
login_username_pass.click()
self.wait_for_seconds(5)
password = self.spaces_driver.driver.find_element_by_id(self.MSFT_LOGIN_PASSWORD_ID)
submit_button = self.spaces_driver.driver.find_element_by_id(self.MSFT_LOGIN_BUTTON_ID)
password.send_keys(msft_password)
submit_button.click()
self.un_focus_spaces_app()
self.wait_for_seconds(30)
logging.info("User is being logged in..")
def is_channel_loading_spinner_visible(self):
logging.info("is_channel_loading_spinner_visible")
self.spaces_driver.wait_for_element(locator=self.SPACES_USER_INFO_ELEM_XPATH, locator_type=self.XPATH, timeout=90, fail_on_not_found=False)
if self.spaces_driver.is_element_visible(locator=self.CHANNEL_LOADING_SPINNER_DISPAYED, locator_type=self.XPATH, timeout=0):
logging.info("TRUE - is_channel_loading_spinner_visible --> returns True")
return True
else:
logging.info("FALSE - is_channel_loading_spinner_visible --> returns False")
return False
def loading_spinner_detection_and_wait_to_dissappear(self):
logging.info("loading_spinner_detection_and_wait_to_dissappear")
if self.is_channel_loading_spinner_visible():
logging.info("Detected Loading Spinner")
self.spaces_driver.take_screen_shot("Channel_Loading_Detected")
self.spaces_driver.wait_for_not_visible(self.CHANNEL_LOADING_SPINNER_DISPAYED, self.XPATH, 120)
self.spaces_driver.wait_for_element(locator=self.CHANNEL_LOADING_SPINNER_NOT_DISPAYED, locator_type=self.XPATH, timeout=15, fail_on_not_found=False)
logging.info("Loading Not Present anymore")
return
def is_refresh_button_present(self):
logging.info("is_refresh_button_present")
if self.spaces_driver.is_element_present(locator=self.REFRESH_BTN_XPATH, locator_type=self.XPATH, timeout=5):
logging.info("TRUE - is_refresh_button_present --> returns True")
return True
else:
logging.info("FALSE - is_refresh_button_present --> returns False")
return False
def refresh_button_detection_and_close(self):
logging.info("refresh_button_detection")
if self.is_refresh_button_present():
logging.info("Refresh button detected")
self.spaces_driver.take_screen_shot("refresh_content_button")
btn = self.spaces_driver.wait_for_element(locator=self.REFRESH_BTN_XPATH, locator_type=self.XPATH, timeout=self.LOADING_TIMEOUT)
btn.click()
self.spaces_driver.wait_for_page_to_load()
self.wait_for_seconds(10)
def lets_go_window_detection_and_close(self):
logging.info("lets_go_window_detection")
if self.is_lets_go_window_present():
logging.info("lets go button is present")
button = self.spaces_driver.wait_for_element(locator=self.WELCOME_TO_MICROSOFT_TEAMS_LETS_GO_BUTTON, locator_type=self.XPATH, timeout=self.LOADING_TIMEOUT)
self.spaces_driver.take_screen_shot("LETS_GO_BTN_BEFORE_CLICK")
button.click()
self.spaces_driver.take_screen_shot("LETS_GO_BTN_AFTER_CLICK")
self.spaces_driver.wait_for_not_visible(locator=self.WELCOME_TO_MICROSOFT_TEAMS_LETS_GO_BUTTON, locator_type=self.XPATH, timeout=15)
def is_lets_go_window_present(self):
logging.info("is_lets_go_window_present")
if self.spaces_driver.is_element_present(locator=self.WELCOME_TO_MICROSOFT_TEAMS_LETS_GO_BUTTON, locator_type=self.XPATH, timeout=5):
logging.info("TRUE - is_lets_go_window_present --> returns True")
return True
else:
logging.info("FALSE - is_lets_go_window_present --> returns False")
return False
def wait_for_channel_to_be_ready(self):
logging.info("wait_for_channel_to_be_ready")
if self.is_channel_loading_spinner_visible() or self.is_refresh_button_present() or self.is_lets_go_window_present():
logging.info("Detected Loading Spinner or Refresh Button or Welcome Window")
self.lets_go_window_detection_and_close()
self.refresh_button_detection_and_close()
self.loading_spinner_detection_and_wait_to_dissappear()
return
else:
if not self.spaces_driver.is_element_present(locator=self.CHANNEL_LOADING_SPINNER_NOT_DISPAYED, locator_type=self.XPATH, timeout=10):
logging.info("Loading not detected at all")
return
else:
self.spaces_driver.take_screen_shot("WARNING_New_channel_layout_is_used")
logging.info("Warning - Probably new channel layout is being used")
return
def is_user_logged_in(self):
logging.info("is_user_logged_in")
"""
Checks if user is logged in to the SkypeSpaces app
:return:
"""
logging.info("Checking whether user is already logged in..")
self.spaces_driver.take_screen_shot("login_check")
for i in range(1, 30):
self.wait_for_seconds(1)
if self.spaces_driver.is_element_present(locator=self.WELCOME_TO_MICROSOFT_TEAMS_LETS_GO_BUTTON, locator_type=self.XPATH, timeout=0.33):
logging.info("Lets go teams welcome window detected means user is logged in")
self.spaces_driver.take_screen_shot("teams_welcome_window_is_logged_in")
return True
elif self.spaces_driver.is_element_present(locator=self.SPACES_USER_INFO_ELEM_XPATH, locator_type=self.XPATH, timeout=0.33):
logging.info("User is logged in.")
self.spaces_driver.take_screen_shot("is_logged_in")
return True
elif self.spaces_driver.is_element_present(locator=self.SPACES_LOGIN_USERNAME_INPUT, locator_type=self.XPATH, timeout=0.33):
logging.info("User is NOT logged in we detected presence of '{0}'".format(self.SPACES_LOGIN_USERNAME_INPUT))
self.spaces_driver.take_screen_shot("not_logged_in")
return False
elif self.spaces_driver.is_element_present(locator=XPathBuilder.xpath_body_contains_text("Sign in to your Microsoft corporate account"), locator_type=self.XPATH, timeout=0.33):
logging.info("User is NOT logged we detected : '{0}'".format(XPathBuilder.xpath_body_contains_text("Sign in to your Microsoft corporate account")))
self.spaces_driver.take_screen_shot("not_logged_in_corporate_account")
return False
else:
logging.error("Error detecting whether user is logged in or not.")
self.spaces_driver.dump_html_for_actual_page("user_not_logged_in.html")
return Exception("Error detecting whether user is logged in or not.")
def logout_if_logged_in(self):
logging.info("logout_if_logged_in")
self.focus_spaces_app()
if self.is_user_logged_in():
logging.info("Logout is required")
self.spaces_driver.driver.execute_script(self.LOGOUT_EXE_ANGULAR_JS)
self.wait_for_seconds(3)
logging.info("Logout Finished")
def logout(self):
logging.info("logout")
self.logout_if_logged_in()
def load_test_accounts(self, accounts=None):
logging.info("load_test_accounts")
"""
Loads test users credentials from test configuration
:param accounts: If specified, just fills up test users credentials to test context (when test accounts already loaded on 2nd party agent)
:return:
"""
self.test_config.load_test_accounts(accounts)
def focus_spaces_app(self, retries=50):
logging.info("focus_spaces_app")
step = 0
while not self.is_focused_spaces_app() and step < retries:
logging.info("attempt {0} - to focus teams app window".format(step))
step += 1
self.wait_for_seconds(1)
if self.is_focused_spaces_app():
return
else:
self.spaces_driver.take_screen_shot("Teams_window_not_focused")
logging.error("Teams window not focused")
raise Exception("Teams window not focused")
def is_focused_spaces_app(self):
logging.info("is_focused_spaces_app")
i = 0
for window_handle in self.spaces_driver.driver.window_handles:
self.spaces_driver.driver.switch_to.window(window_handle)
logging.info("switching to window handle '{0}' from possible'{1}'".format(i, len(self.spaces_driver.driver.window_handles)))
i += 1
for elem in [self.SPACES_LOGIN_USERNAME_INPUT, self.SPACES_USER_INFO_ELEM_XPATH, self.LOGIN_AREA]:
logging.info("Trying presence of element '{0}'".format(elem))
if self.spaces_driver.is_element_present(locator=elem, locator_type=self.XPATH, timeout=0):
logging.info("Element detected in Window so Teams app window is focused")
return True
return False
def un_focus_spaces_app(self):
logging.info("un_focus_spaces_app")
i = 0
for i in range(i, len(self.spaces_driver.driver.window_handles)):
logging.info("for i = {0} from {1} window handles".format(i, len(self.spaces_driver.driver.window_handles)))
logging.info("window_handle = {0}".format(str(self.spaces_driver.driver.current_window_handle)))
if self.spaces_driver.driver.current_window_handle != self.spaces_driver.driver.window_handles[i]:
logging.info("current handle is not same as window handle so getting unfocused")
self.spaces_driver.driver.switch_to.window(self.spaces_driver.driver.window_handles[i])
return
i += 1
try:
self.unfocus_spaces_app()
except Exception, e:
logging.error("Couldn't unfocus Teams app window {0}".format(e))
raise Exception("Couldn't unfocus Teams app window")
def unfocus_spaces_app(self, wait=0):
logging.info("unfocus_spaces_app")
"""
Hack for make Chrome driver to work with electron during 302 redirects
"""
logging.info("if self.spaces_driver.driver.current_window_handle != self.spaces_driver.driver.window_handles[0]")
logging.info("if current handle = '{0}' != {1} all window handles[0]".format(str(self.spaces_driver.driver.current_window_handle), str(self.spaces_driver.driver.window_handles[0])))
if self.spaces_driver.driver.current_window_handle != self.spaces_driver.driver.window_handles[0]:
self.spaces_driver.driver.switch_to.window(self.spaces_driver.driver.window_handles[0])
logging.info("Switched to window #0")
else :
logging.info("elif len(self.spaces_driver.driver.window_handles) > 1:")
logging.info("elif {%d} > 1" % len(self.spaces_driver.driver.window_handles))
if len(self.spaces_driver.driver.window_handles) > 1:
self.spaces_driver.driver.switch_to.window(self.spaces_driver.driver.window_handles[1])
logging.info("Switched to window #1")
else:
logging.info("Nothing to unfocus. Seems this is browser run.")
self.wait_for_seconds(wait)
logging.info("App window unfocused")
def is_focused_call_notification_window(self):
logging.info("is_focused_call_notification_window")
i = 0
for window_handle in self.spaces_driver.driver.window_handles:
self.spaces_driver.driver.switch_to.window(window_handle)
logging.info("switching to window handle '{0}' from possible'{1}'".format(i, len(self.spaces_driver.driver.window_handles)))
i += 1
for elem in [self.CALL_NOTIFICATION_WINDOW_IS_NUDGING_MESG_XPATH, self.CALL_NOTIFICATION_WINDOW_IS_CALLING_MESG_XPATH]:
logging.info("Trying presence of element '{0}'".format(elem))
if self.spaces_driver.is_element_present(elem, self.XPATH, 0):
logging.info("Element detected in Window so Call notification window is focused")
return True
return False
def focus_call_notification_window(self):
logging.info("focus_call_notification_window")
retry = 60
step = 0
while not self.is_focused_call_notification_window() and step < retry:
logging.info("attempt {0} - call notification not found".format(step))
step += 1
self.wait_for_seconds(1)
if self.is_focused_call_notification_window():
return
else:
self.spaces_driver.take_screen_shot("Call_notification_not_shown")
logging.error("Call notification not shown")
raise Exception("Call notification not shown")
def print_notification_source(self):
logging.info("print_notification_source")
while True:
self.focus_call_notification_window()
print("================================")
print(self.spaces_driver.driver.page_source.encode('utf-8').strip())
def wait_for_call_notification_to_be_opened(self, is_meetup=False):
logging.info("wait_for_call_notification_to_be_opened")
retry = 60
step = 0
while not self.is_focused_call_notification_window() and step < retry:
logging.info("#%d - not opened" % step)
step += 1
self.wait_for_seconds(1)
if self.is_focused_call_notification_window():
logging.info("#%d - opened" % step)
self.spaces_driver.take_screen_shot("call_notification_opened")
return
else:
logging.info("#%d - not opened" % step)
self.spaces_driver.take_screen_shot("call_notification_not_opened")
return
def start_video_recording(self):
logging.info("start_video_recording")
if self.video_recorder:
try:
self.video_recorder.start()
self.recording_in_progress = True
logging.info("Video recording started.")
except Exception, e:
logging.info("Could not start screen video recording. VNC server not running... exception was : %s" %e)
def stop_video_recording(self):
logging.info("stop_video_recording")
if self.video_recorder and self.recording_in_progress:
self.video_recorder.stop()
self.recording_in_progress = False
logging.info("Video recording stopped.")
def show_more_channels(self, fail_on_not_present=False):
logging.info("show_more_channels")
try:
more_button = self.spaces_driver.wait_for_element(handler=self.SHOW_MORE_TEAMS_BUTTON_XPATH, method=self.XPATH, timeout=5, fail_on_not_found=fail_on_not_present)
more_button.click()
self.spaces_driver.take_screen_shot("more_channels")
except TimeoutException:
if fail_on_not_present:
logging.info("More channels button not found TimeoutException")
raise TimeoutException("More channels button not found TimeoutException")
else:
logging.info("More channels button not found TimeoutException")
def navigate_to_channel(self, team_name=None, channel_name=None, channel_thread_id=None, wait_for_load=True, attempts=3):
logging.info("navigate_to_channel")
self.wait_for_seconds(15)
for attempt in range(0, attempts):
if not team_name:
team_name = self.test_config.test_team
if not channel_name:
channel_name = self.test_config.test_channel
if not channel_thread_id:
channel_thread_id = self.test_config.test_channel_thread_id
channel_url = str(str(self.test_config.base_url) + "channel/{0}/{1}/{2}/conversations?ctx=channel".format(str(team_name), str(channel_name).replace(" ", "%20"), str(channel_thread_id)))
logging.info("Navigating to: {0}".format(channel_url))
self.focus_spaces_app()
self.spaces_driver.driver.get(channel_url)
logging.info("Navigated to url: {0}".format(self.spaces_driver.driver.current_url))
if wait_for_load:
logging.info("wait for page to load")
self.spaces_driver.wait_for_page_to_load()
self.wait_for_channel_to_be_ready()
self.spaces_driver.take_screen_shot("navigating_to_channel")
channel_xpath = str("//h2[@data-tid = 'messagesHeader-Title' and . = '{0}']".format(str(self.test_config.test_channel)))
self.spaces_driver.wait_for_element(locator=channel_xpath, locator_type=self.XPATH, timeout=self.LOADING_TIMEOUT)
if self.spaces_driver.is_element_present(self.REFRESH_BTN_XPATH, self.XPATH, 5):
self.spaces_driver.take_screen_shot("refresh_content_button")
btn = self.spaces_driver.wait_for_element(locator=self.REFRESH_BTN_XPATH, locator_type=self.XPATH, timeout=self.LOADING_TIMEOUT)
btn.click()
self.spaces_driver.wait_for_page_to_load()
self.spaces_driver.wait_for_element(locator=channel_xpath, locator_type=self.XPATH, timeout=self.LOADING_TIMEOUT)
self.wait_for_channel_to_be_ready()
break
def channel_scroll_up_down(self, scroll_down=True):
logging.info("channel_scroll_up_down")
self.wait_for_channel_to_be_ready()
self.spaces_driver.take_screen_shot("before_scroll")
scroll_js = "%s %s" % (self.FIND_ELEMENT_BY_XPATH_JS_TEMPLATE % ("elem", self.CHANNEL_MESSAGE_LIST_XPATH), self.SCROLL_DOWN_ELEMENT_JS if scroll_down else self.SCROLL_UP_ELEMENT_JS)
self.spaces_driver.driver.execute_script(scroll_js)
self.wait_for_seconds(0.3)
self.spaces_driver.take_screen_shot("after_scroll")
logging.info("Scrolling done.")
def scroll_channel_to_specified_element_by_xpath(self, xpath):
logging.info("scroll_channel_to_specified_element_by_xpath")
"""
Scrolls to specified element by xpath
:return:
"""
self.wait_for_channel_to_be_ready()
logging.info("Going to scroll to specified element (xpath)...")
self.spaces_driver.take_screen_shot("before_scroll_to_elem")
scroll_js = "%s %s" % (self.FIND_ELEMENT_BY_XPATH_JS_TEMPLATE % ("elemToScroll", xpath), self.SCROLL_TO_ELEMENT_JS_TEMPLATE % "elemToScroll")
logging.info("Executing scroll script: %s" % scroll_js)
self.spaces_driver.driver.execute_script(scroll_js)
self.wait_for_seconds(3)
self.spaces_driver.take_screen_shot("after_scroll_to_elem")
logging.info("Scrolling to element done.")
def check_if_calling_supported(self, error_on_fail=True):
logging.info("check_if_calling_supported")