forked from PrestaShop/ui-testing-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBOBasePage.ts
1250 lines (1019 loc) · 38.9 KB
/
BOBasePage.ts
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
// Import pages
import {type BOBasePagePageInterface} from '@interfaces/BO';
import CommonPage from '@pages/commonPage';
import {Frame, Page} from '@playwright/test';
import testContext from '@utils/test';
import type {PageFunction} from 'playwright-core/types/structs';
import semver from 'semver';
/**
* BO parent page, contains functions that can be used on all BO page
* @class
* @extends CommonPage
*/
export default class BOBasePage extends CommonPage implements BOBasePagePageInterface {
public successfulCreationMessage: string;
public successfulUpdateMessage: string;
public successfulDeleteMessage: string;
public successfulMultiDeleteMessage: string;
public readonly accessDeniedMessage: string;
public readonly pageNotFoundMessage: string;
private readonly userProfileIconNonMigratedPages: string;
protected readonly userProfileIcon: string;
private readonly userProfileFirstname: string;
private readonly userProfileAvatar: string;
private readonly userProfileYourProfileLinkNonMigratedPages: string;
private readonly userProfileYourProfileLink: string;
private readonly userProfileLogoutLink: string;
private readonly shopVersionBloc: string;
private readonly headerShopNameLink: string;
private readonly quickAccessContainer: string;
private readonly quickAccessDropdownToggle: string;
private readonly quickAccessLink: (linkName: string) => string;
private readonly quickAddCurrentLink: string;
private readonly quickAccessRemoveLink: string;
private readonly manageYourQuickAccessLink: string;
private readonly navbarSearchInput: string;
protected readonly helpButton: string;
private readonly menuMobileButton: string;
private readonly notificationsLink: string;
private readonly notificationsDropDownMenu: string;
private readonly totalNotificationsValue: string;
private readonly notificationsTab: (tabName: string) => string;
private readonly notificationsNumberInTab: (tabName: string) => string;
private readonly notificationRowInTab: (tabName: string, row: number) => string;
private readonly desktopNavbar: string;
private readonly navbarCollapseButton: string;
private readonly navbarCollapsed: (isCollapsed: boolean) => string;
private readonly dashboardLink: string;
public readonly ordersParentLink: string;
public readonly ordersLink: string;
public readonly invoicesLink: string;
public readonly creditSlipsLink: string;
public readonly deliverySlipslink: string;
public readonly shoppingCartsLink: string;
public readonly catalogParentLink: string;
public readonly productsLink: string;
public readonly categoriesLink: string;
public readonly monitoringLink: string;
public readonly attributesAndFeaturesLink: string;
public readonly brandsAndSuppliersLink: string;
public readonly filesLink: string;
public readonly discountsLink: string;
public readonly stocksLink: string;
public readonly customersParentLink: string;
public readonly customersLink: string;
public readonly addressesLink: string;
public readonly outstandingLink: string;
public readonly customerServiceParentLink: string;
public readonly customerServiceLink: string;
public readonly orderMessagesLink: string;
public readonly merchandiseReturnsLink: string;
public readonly modulesParentLink: string;
public readonly moduleCatalogueLink: string;
public readonly moduleManagerLink: string;
public readonly designParentLink: string;
public readonly themeAndLogoParentLink: string;
public readonly themeAndLogoLink: string;
public readonly emailThemeLink: string;
public readonly pagesLink: string;
public readonly positionsLink: string;
public readonly imageSettingsLink: string;
public readonly linkWidgetLink: string;
public readonly shippingLink: string;
public readonly carriersLink: string;
public readonly shippingPreferencesLink: string;
public readonly paymentParentLink: string;
public readonly paymentMethodsLink: string;
public readonly preferencesLink: string;
public readonly internationalParentLink: string;
public readonly taxesLink: string;
public readonly localizationLink: string;
public readonly locationsLink: string;
public readonly translationsLink: string;
public readonly shopParametersParentLink: string;
public readonly shopParametersGeneralLink: string;
public readonly orderSettingsLink: string;
public readonly productSettingsLink: string;
public readonly customerSettingsLink: string;
public readonly contactLink: string;
public readonly trafficAndSeoLink: string;
public readonly searchLink: string;
public readonly advancedParametersLink: string;
public readonly informationLink: string;
public readonly performanceLink: string;
public readonly administrationLink: string;
public readonly emailLink: string;
public readonly importLink: string;
public readonly teamLink: string;
public readonly databaseLink: string;
public readonly webserviceLink: string;
public readonly logsLink: string;
public readonly adminAPILink: string;
public readonly featureFlagLink: string;
public readonly securityLink: string;
public readonly multistoreLink: string;
public readonly menuTabLink: string;
public readonly menuTree: { parent: string; children: string[] }[];
protected readonly growlDiv: string;
private readonly growlDefaultDiv: string;
protected growlMessageBlock: string;
protected growlCloseButton: string;
protected alertBlock: string;
protected alertTextBlock: string;
protected alertBlockCloseButton: string;
protected alertSuccessBlock: string;
private readonly alertDangerBlock: string;
private readonly alertInfoBlock: string;
protected alertSuccessBlockParagraph: string;
protected alertDangerBlockParagraph: string;
private readonly alertInfoBlockParagraph: string;
private readonly confirmationModal: string;
protected readonly modalDialog: string;
protected readonly modalDialogYesButton: string;
private readonly sfToolbarMainContentDiv: string;
private readonly sfCloseToolbarLink: string;
protected readonly rightSidebar: string;
private readonly helpDocumentURL: string;
private readonly invalidTokenContinueLink: string;
private readonly invalidTokenCancelLink: string;
public readonly debugModeToolbar: string;
public readonly multistoreHeader: string;
public readonly multistoreButton: string;
public readonly multistoreModal: string;
public readonly viewMyStoreButton: string;
public readonly multistoreTopBar: string;
public readonly storeName: string;
public readonly pageSubtitle: string;
public readonly chooseShopName: (shopNumber: number) => string;
/**
* @constructs
* Setting up texts and selectors to use on all BO pages
*/
constructor() {
super();
// Successful Messages
this.successfulCreationMessage = 'Successful creation';
this.successfulUpdateMessage = 'Successful update';
this.successfulDeleteMessage = 'Successful deletion';
this.successfulMultiDeleteMessage = 'The selection has been successfully deleted.';
// Access denied message
this.accessDeniedMessage = 'Access denied';
this.pageNotFoundMessage = 'Page not found';
this.pageSubtitle = '#content .page-subtitle';
// top navbar
this.userProfileIconNonMigratedPages = '#employee_infos';
this.userProfileIcon = '#header_infos #header-employee-container';
this.userProfileFirstname = '.employee-wrapper-avatar .employee_profile';
this.userProfileAvatar = '.employee-avatar img';
this.userProfileYourProfileLinkNonMigratedPages = '.employee-wrapper-profile > a.admin-link';
this.userProfileYourProfileLink = '.employee-link.profile-link';
this.userProfileLogoutLink = 'a#header_logout';
this.shopVersionBloc = '#shop_version';
this.headerShopNameLink = '#header_shopname';
this.quickAccessDropdownToggle = '#quick_select';
this.quickAccessContainer = '#quick-access-container';
this.quickAccessLink = (linkName) => `${this.quickAccessContainer} [data-item='${linkName}']`;
this.quickAddCurrentLink = `${this.quickAccessContainer} #quick-add-link`;
this.quickAccessRemoveLink = `${this.quickAccessContainer} #quick-remove-link`;
this.manageYourQuickAccessLink = `${this.quickAccessContainer} #quick-manage-link`;
this.navbarSearchInput = '#bo_query';
// Header links
this.helpButton = '#product_form_open_help';
this.menuMobileButton = '.js-mobile-menu';
this.notificationsLink = '#notification,#notif';
this.notificationsDropDownMenu = '#notification div.dropdown-menu-right.notifs_dropdown,#notif div.dropdown-menu';
this.totalNotificationsValue = '#total_notif_value,#notifications-total';
this.notificationsTab = (tabName: string) => `#${tabName}-tab`;
this.notificationsNumberInTab = (tabName: string) => `#${tabName}_notif_value,#_nb_new_${tabName}_`;
this.notificationRowInTab = (tabName: string, row: number) => `#${tabName}-notifications div a:nth-child(${row})`;
// left navbar
this.desktopNavbar = '.nav-bar:not(.mobile-nav)';
this.navbarCollapseButton = '.nav-bar > .menu-collapse';
this.navbarCollapsed = (isCollapsed) => `body${isCollapsed
? '.page-sidebar-closed'
: ':not(.page-sidebar-closed)'}`;
this.debugModeToolbar = 'div[id*=sfToolbarMainContent]';
// Multistore selectors
this.multistoreHeader = '#header-multishop';
this.multistoreButton = `${this.multistoreHeader} button.header-multishop-button`;
this.multistoreModal = '#multishop-modal';
this.chooseShopName = (shopNumber: number) => `${this.multistoreModal} li:nth-child(${2 + shopNumber})`
+ ' a.multishop-modal-shop-name';
this.viewMyStoreButton = `${this.multistoreHeader} div.header-multishop-right a.header-multishop-view-action`;
this.multistoreTopBar = `${this.multistoreHeader} div.header-multishop-top-bar`;
this.storeName = `${this.multistoreTopBar} div h2`;
// Dashboard
this.dashboardLink = '#tab-AdminDashboard';
// SELL
// Orders
this.ordersParentLink = 'li#subtab-AdminParentOrders';
this.ordersLink = '#subtab-AdminOrders';
// Invoices
this.invoicesLink = '#subtab-AdminInvoices';
// Credit slips
this.creditSlipsLink = '#subtab-AdminSlip';
// Delivery slips
this.deliverySlipslink = '#subtab-AdminDeliverySlip';
// Shopping carts
this.shoppingCartsLink = '#subtab-AdminCarts';
// Catalog
this.catalogParentLink = 'li#subtab-AdminCatalog';
// Products
this.productsLink = '#subtab-AdminProducts';
// Categories
this.categoriesLink = '#subtab-AdminCategories';
// Monitoring
this.monitoringLink = '#subtab-AdminTracking';
// Attributes and Features
this.attributesAndFeaturesLink = '#subtab-AdminParentAttributesGroups';
// Brands And Suppliers
this.brandsAndSuppliersLink = '#subtab-AdminParentManufacturers';
// files
this.filesLink = '#subtab-AdminAttachments';
// Discounts
this.discountsLink = '#subtab-AdminParentCartRules';
// Stocks
this.stocksLink = '#subtab-AdminStockManagement';
// Customers
this.customersParentLink = 'li#subtab-AdminParentCustomer';
this.customersLink = '#subtab-AdminCustomers';
this.addressesLink = '#subtab-AdminAddresses';
this.outstandingLink = '#subtab-AdminOutstanding';
// Customer Service
this.customerServiceParentLink = '#subtab-AdminParentCustomerThreads';
this.customerServiceLink = '#subtab-AdminCustomerThreads';
// Order Messages
this.orderMessagesLink = '#subtab-AdminOrderMessage';
// Merchandise returns
this.merchandiseReturnsLink = '#subtab-AdminReturn';
// Improve
// Modules
this.modulesParentLink = '#subtab-AdminParentModulesSf';
this.moduleCatalogueLink = '#subtab-AdminParentModulesCatalog';
this.moduleManagerLink = '#subtab-AdminModulesSf';
// Design
this.designParentLink = '#subtab-AdminParentThemes';
// Theme & Logo
this.themeAndLogoParentLink = '#subtab-AdminThemesParent';
this.themeAndLogoLink = '#subtab-AdminThemes';
// Email theme
this.emailThemeLink = '#subtab-AdminParentMailTheme';
// Pages
this.pagesLink = '#subtab-AdminCmsContent';
// Positions
this.positionsLink = '#subtab-AdminModulesPositions';
// Image settings
this.imageSettingsLink = '#subtab-AdminImages';
// Link widget
this.linkWidgetLink = '#subtab-AdminLinkWidget';
// Shipping
this.shippingLink = '#subtab-AdminParentShipping';
this.carriersLink = '#subtab-AdminCarriers';
this.shippingPreferencesLink = '#subtab-AdminShipping';
// Payment
this.paymentParentLink = '#subtab-AdminParentPayment';
// Preferences
this.paymentMethodsLink = '#subtab-AdminPayment';
// Preferences
this.preferencesLink = '#subtab-AdminPaymentPreferences';
// International
this.internationalParentLink = '#subtab-AdminInternational';
// Taxes
this.taxesLink = '#subtab-AdminParentTaxes';
// Localization
this.localizationLink = '#subtab-AdminParentLocalization';
// Locations
this.locationsLink = '#subtab-AdminParentCountries';
// Translations
this.translationsLink = '#subtab-AdminTranslations';
// Shop Parameters
this.shopParametersParentLink = '#subtab-ShopParameters';
// General
this.shopParametersGeneralLink = '#subtab-AdminParentPreferences';
// Order Settings
this.orderSettingsLink = '#subtab-AdminParentOrderPreferences';
// Product Settings
this.productSettingsLink = '#subtab-AdminPPreferences';
// Customer Settings
this.customerSettingsLink = '#subtab-AdminParentCustomerPreferences';
// Contact
this.contactLink = '#subtab-AdminParentStores';
// traffic and SEO
this.trafficAndSeoLink = '#subtab-AdminParentMeta';
// Search
this.searchLink = '#subtab-AdminParentSearchConf';
// Advanced Parameters
this.advancedParametersLink = '#subtab-AdminAdvancedParameters';
// Information
this.informationLink = '#subtab-AdminInformation';
// Performance
this.performanceLink = '#subtab-AdminPerformance';
// Administration
this.administrationLink = '#subtab-AdminAdminPreferences';
// E-mail
this.emailLink = '#subtab-AdminEmails';
// Import
this.importLink = '#subtab-AdminImport';
// Team
this.teamLink = '#subtab-AdminParentEmployees';
// Database
this.databaseLink = '#subtab-AdminParentRequestSql';
// Webservice
this.webserviceLink = '#subtab-AdminWebservice';
// Logs
this.logsLink = '#subtab-AdminLogs';
// Authorization Server
this.adminAPILink = '#subtab-AdminAdminAPI';
// New & Experimental Features
this.featureFlagLink = '#subtab-AdminFeatureFlag';
// Security
this.securityLink = '#subtab-AdminParentSecurity';
// Multistore
this.multistoreLink = '#subtab-AdminShopGroup';
// Deprecated tab used for regression test
this.menuTabLink = '#subtab-AdminTabs';
this.menuTree = [
{
parent: this.ordersParentLink,
children: [
this.ordersLink,
this.invoicesLink,
this.creditSlipsLink,
this.deliverySlipslink,
this.shoppingCartsLink,
],
},
{
parent: this.customersParentLink,
children: [
this.customersLink,
this.addressesLink,
],
},
{
parent: this.customerServiceParentLink,
children: [
this.customerServiceLink,
this.orderMessagesLink,
this.merchandiseReturnsLink,
],
},
{
parent: this.modulesParentLink,
children: [
this.moduleManagerLink,
],
},
{
parent: this.designParentLink,
children: [
this.themeAndLogoParentLink,
this.emailThemeLink,
this.pagesLink,
this.positionsLink,
this.imageSettingsLink,
this.linkWidgetLink,
],
},
{
parent: this.shippingLink,
children: [
this.carriersLink,
this.shippingPreferencesLink,
],
},
{
parent: this.paymentParentLink,
children: [
this.paymentMethodsLink,
this.preferencesLink,
],
},
{
parent: this.internationalParentLink,
children: [
this.localizationLink,
this.locationsLink,
this.taxesLink,
this.translationsLink,
],
},
{
parent: this.shopParametersParentLink,
children: [
this.shopParametersGeneralLink,
this.orderSettingsLink,
this.productSettingsLink,
this.customerSettingsLink,
this.contactLink,
this.trafficAndSeoLink,
this.searchLink,
],
},
{
parent: this.advancedParametersLink,
children: [
this.informationLink,
this.performanceLink,
this.administrationLink,
this.emailLink,
this.importLink,
this.teamLink,
this.databaseLink,
this.logsLink,
this.webserviceLink,
this.featureFlagLink,
this.securityLink,
],
},
];
// Growls
this.growlDiv = '#growls';
this.growlDefaultDiv = '#growls-default';
this.growlMessageBlock = `${this.growlDefaultDiv} .growl-message`;
this.growlCloseButton = `${this.growlDefaultDiv} .growl-close`;
// Alert Text
this.alertBlock = 'div.alert';
this.alertTextBlock = `${this.alertBlock} div.alert-text`;
this.alertBlockCloseButton = `${this.alertBlock} button[aria-label='Close']`;
this.alertSuccessBlock = `${this.alertBlock}.alert-success`;
this.alertDangerBlock = `${this.alertBlock}.alert-danger`;
this.alertInfoBlock = `${this.alertBlock}.alert-info`;
this.alertSuccessBlockParagraph = `${this.alertSuccessBlock} div.alert-text p`;
this.alertDangerBlockParagraph = `${this.alertDangerBlock} div.alert-text p`;
this.alertInfoBlockParagraph = `${this.alertInfoBlock} div.alert-text, ${this.alertInfoBlock} p.alert-text`;
// Modal dialog
this.confirmationModal = '#confirmation_modal.show';
this.modalDialog = `${this.confirmationModal} .modal-dialog`;
this.modalDialogYesButton = `${this.modalDialog} button.continue`;
// Symfony Toolbar
this.sfToolbarMainContentDiv = "div[id*='sfToolbarMainContent']";
this.sfCloseToolbarLink = "[id*='sfToolbarHideButton']";
// Sidebar
this.rightSidebar = '#right-sidebar';
this.helpDocumentURL = `${this.rightSidebar} div.quicknav-scroller._fullspace object`;
// Invalid token block
this.invalidTokenContinueLink = '#security-compromised-page #csrf-white-container div a:nth-child(1)';
this.invalidTokenCancelLink = '#security-compromised-page #csrf-white-container div a:nth-child(2)';
}
/*
Methods
*/
/**
* Get page subtitle
* @param page {Page} Browser tab
* @returns {Promise<string>}
*/
async getPageSubTitle(page: Page): Promise<string> {
return this.getTextContent(page, this.pageSubtitle);
}
/**
* Go to dashboard page
* @param page {Page} Browser tab
*/
async goToDashboardPage(page: Page): Promise<void> {
await this.clickAndWaitForURL(page, this.dashboardLink);
}
/**
* Click on link from Quick access dropdown toggle
* @param page {Page} Browser tab
* @param linkName {linkName} Page name
* @returns {Promise<void>}
*/
async quickAccessToPage(page: Page, linkName: string): Promise<void> {
await this.waitForSelectorAndClick(page, this.quickAccessDropdownToggle);
await this.clickAndWaitForURL(page, this.quickAccessLink(linkName));
await this.waitForPageTitleToLoad(page);
}
/**
* Quick access to page with frame
* @param page {Page} Browser tab
* @param linkName {linkName} Page name
* @returns {Promise<Page>}
*/
async quickAccessToPageWithFrame(page: Page, linkName: string): Promise<void> {
await this.waitForSelectorAndClick(page, this.quickAccessDropdownToggle);
await this.waitForSelectorAndClick(page, this.quickAccessLink(linkName));
}
/**
* Click on link from Quick access dropdown toggle and get the opened Page
* @param page {Page} Browser tab
* @param linkName {linkName} Page name
* @returns {Promise<Page>}
*/
async quickAccessToPageNewWindow(page: Page, linkName: string): Promise<Page> {
await this.waitForSelectorAndClick(page, this.quickAccessDropdownToggle);
return this.openLinkWithTargetBlank(page, this.quickAccessLink(linkName));
}
/**
* Remove link from quick access
* @param page {Page} Browser tab
* @returns {Promise<string>}
*/
async removeLinkFromQuickAccess(page: Page): Promise<string | null> {
await this.waitForSelectorAndClick(page, this.quickAccessDropdownToggle);
await this.waitForSelectorAndClick(page, this.quickAccessRemoveLink);
return page.locator(this.growlDiv).textContent();
}
/**
* Add current page to quick access
* @param page {Page} Browser tab
* @param pageName {string} Page name to add on quick access
* @returns {Promise<string|null>}
*/
async addCurrentPageToQuickAccess(page: Page, pageName: string): Promise<string | null> {
await this.dialogListener(page, true, pageName);
await this.waitForSelectorAndClick(page, this.quickAccessDropdownToggle);
await this.waitForSelectorAndClick(page, this.quickAddCurrentLink);
return page.locator(this.growlDiv).textContent();
}
/**
* Click on manage quick access link
* @param page {Page} Browser tab
* @returns {Promise<void>}
*/
async goToManageQuickAccessPage(page: Page): Promise<void> {
await this.waitForSelectorAndClick(page, this.quickAccessDropdownToggle);
await this.clickAndWaitForURL(page, this.manageYourQuickAccessLink);
}
/**
* Open a subMenu if closed and click on a sublink
* @param page {Page} Browser tab
* @param parentSelector {string} Selector of the parent menu
* @param linkSelector {string} Selector of the child menu
* @returns {Promise<void>}
*/
async goToSubMenu(page: Page, parentSelector: string, linkSelector: string): Promise<void> {
await this.clickSubMenu(page, parentSelector);
await this.scrollTo(page, linkSelector);
await this.clickAndWaitForURL(page, linkSelector);
const psVersion = testContext.getPSVersion();
let linkActiveClass: string = '-active';
// >= 1.7.8.0
if (semver.gte(psVersion, '7.8.0')) {
linkActiveClass = 'link-active';
}
if (await this.isSidebarCollapsed(page)) {
await this.waitForHiddenSelector(page, `${linkSelector}.${linkActiveClass}`);
} else {
await this.waitForVisibleSelector(page, `${linkSelector}.${linkActiveClass}`);
}
}
/**
* Open a subMenu
* @param page {Page} Browser tab
* @param parentSelector {string} Selector of the parent menu
* @returns {Promise<void>}
*/
async clickSubMenu(page: Page, parentSelector: string): Promise<void> {
const openSelector = await this.isSidebarCollapsed(page) ? '.ul-open' : '.open';
if (await this.elementNotVisible(page, `${parentSelector}${openSelector}`, 1000)) {
// open the block
await this.scrollTo(page, parentSelector);
await Promise.all([
page.locator(parentSelector).click(),
this.waitForVisibleSelector(page, `${parentSelector}${openSelector}`),
]);
}
}
/**
* Return is a submenu is active
* @param page {Page} Browser tab
* @param linkSelector {string} Selector of the menu
* @return {Promise<boolean>}
*/
async isSubMenuActive(page: Page, linkSelector: string): Promise<boolean> {
return ((await page.locator(`${linkSelector}.link-active`).count()) > 0);
}
/**
* Return is the navbar is visible
* @param page {Page} Browser tab
* @return {Promise<boolean>}
*/
async isNavbarVisible(page: Page): Promise<boolean> {
return this.elementVisible(page, this.desktopNavbar, 1000);
}
/**
* Return is the navbar is visible
* @param page {Page} Browser tab
* @return {Promise<boolean>}
*/
async isMobileMenuVisible(page: Page): Promise<boolean> {
return this.elementVisible(page, this.menuMobileButton, 1000);
}
/**
* Returns if Submenu is visible
* @param page {Page} Browser tab
* @param parentSelector {string} Selector of the parent menu
* @param linkSelector {string} Selector of the child menu
* @return {Promise<boolean>}
*/
async isSubmenuVisible(page: Page, parentSelector: string, linkSelector: string): Promise<boolean> {
const openSelector = await this.isSidebarCollapsed(page) ? '.ul-open' : '.open';
if (await this.elementNotVisible(page, `${parentSelector}${openSelector}`, 1000)) {
// Scroll before opening menu
await this.scrollTo(page, parentSelector);
await Promise.all([
page.locator(parentSelector).click(),
this.waitForVisibleSelector(page, `${parentSelector}${openSelector}`),
]);
await this.waitForVisibleSelector(page, `${parentSelector}${openSelector}`);
}
return this.elementVisible(page, linkSelector, 1000);
}
/**
* Collapse the sidebar
* @param page {Page} Browser tab
* @param isCollapsed {boolean} Selector of the parent menu
* @return {Promise<void>}
*/
async setSidebarCollapsed(page: Page, isCollapsed: boolean): Promise<void> {
const isCurrentCollapsed = await this.isSidebarCollapsed(page);
if (isCurrentCollapsed !== isCollapsed) {
await Promise.all([
page.locator(this.navbarCollapseButton).click(),
this.waitForVisibleSelector(
page,
this.navbarCollapsed(isCollapsed),
),
]);
}
}
/**
* Returns if the sidebar is collapsed
* @param page {Page} Browser tab
* @return {Promise<boolean>}
*/
async isSidebarCollapsed(page: Page): Promise<boolean> {
return this.elementVisible(page, this.navbarCollapsed(true), 1000);
}
/**
* Is notifications link visible
* @param page {Page} Browser tab
* @return {Promise<boolean>}
*/
async isNotificationsLinkVisible(page: Page): Promise<boolean> {
return this.elementVisible(page, this.notificationsLink, 1000);
}
/**
* Click on notifications link
* @param page {Page} Browser tab
* @return {Promise<boolean>}
*/
async clickOnNotificationsLink(page: Page): Promise<boolean> {
await this.waitForSelectorAndClick(page, this.notificationsLink);
return this.elementVisible(page, this.notificationsDropDownMenu, 1000);
}
/**
* Get all notifications number
* @param page {Page} Browser tab
* @return {Promise<number>}
*/
async getAllNotificationsNumber(page: Page): Promise<number> {
return this.getNumberFromText(page, this.totalNotificationsValue, 2000);
}
/**
* Is notifications tab visible
* @param page {Page} Browser tab
* @param tabName {string} Messages, customers or orders tab
* @return {Promise<boolean>}
*/
async isNotificationsTabVisible(page: Page, tabName: string): Promise<boolean> {
return this.elementVisible(page, this.notificationsTab(tabName));
}
/**
* Click on notifications tab
* @param page {Page} Browser tab
* @param tabName {string} Messages, customers or orders tab
* @return {Promise<void>}
*/
async clickOnNotificationsTab(page: Page, tabName: string): Promise<void> {
await this.waitForSelectorAndClick(page, this.notificationsTab(tabName));
}
/**
* Get notifications number in tab
* @param page {Page} Browser tab
* @param tabName {string} Messages, customers or orders tab
* @return {Promise<number>}
*/
async getNotificationsNumberInTab(page: Page, tabName: string): Promise<number> {
return this.getNumberFromText(page, this.notificationsNumberInTab(tabName), 2000);
}
/**
* Click on notification on tab
* @param page {Page} Browser tab
* @param tabName {string} Messages, customers or orders tab
* @param row {number} row in notification tab
*/
async clickOnNotification(page: Page, tabName: string, row: number = 1): Promise<void> {
await this.clickAndWaitForURL(page, this.notificationRowInTab(tabName, row));
}
/**
* Go to my profile page
* @param page {Page} Browser tab
* @returns {Promise<void>}
* @return {Promise<void>}
*/
async goToMyProfile(page: Page): Promise<void> {
if (await this.elementVisible(page, this.userProfileIcon, 1000)) {
await page.locator(this.userProfileIcon).click();
} else {
await page.locator(this.userProfileIconNonMigratedPages).click();
}
if (await this.elementVisible(page, this.userProfileYourProfileLink, 1000)) {
await this.waitForVisibleSelector(page, this.userProfileYourProfileLink);
} else {
await this.waitForVisibleSelector(page, this.userProfileYourProfileLinkNonMigratedPages);
}
await this.clickAndWaitForURL(page, this.userProfileYourProfileLink);
}
/**
* Returns the URL of the avatar for the current employee from the dropdown
* @param page {Page} Browser tab
* @returns {Promise<string|null>}
*/
async getCurrentEmployeeAvatar(page: Page): Promise<string | null> {
if (await this.elementVisible(page, this.userProfileIcon, 1000)) {
await page.locator(this.userProfileIcon).click();
} else {
await page.locator(this.userProfileIconNonMigratedPages).click();
}
return this.getAttributeContent(page, this.userProfileAvatar, 'src');
}
/**
* Returns to the dashboard then logout
* @param page {Page} Browser tab
* @returns {Promise<void>}
*/
async logoutBO(page: Page): Promise<void> {
if (await this.elementVisible(page, this.userProfileIcon, 1000)) {
await page.locator(this.userProfileIcon).click();
} else {
await page.locator(this.userProfileIconNonMigratedPages).click();
}
await this.waitForVisibleSelector(page, this.userProfileLogoutLink);
await this.clickAndWaitForURL(page, this.userProfileLogoutLink);
}
/**
* Click on View My Shop and wait for page to open in a new Tab
* @param page {Page} Browser tab
* @return {Promise<Page>}
*/
async viewMyShop(page: Page): Promise<Page> {
return this.openLinkWithTargetBlank(page, this.headerShopNameLink);
}
/**
* Set value on tinyMce textarea
* @param page {Page} Browser tab
* @param iFrameSelector {string} Selector of the iFrame to set value on
* @param value {string} Value to set on the iFrame
* @return {Promise<void>}
*/
async setValueOnTinymceInput(page: Page, iFrameSelector: string, value: string): Promise<void> {
const args = {selector: iFrameSelector, vl: value};
// eslint-disable-next-line no-eval
const fn: { fnSetValueOnTinymceInput: PageFunction<{ selector: string, vl: string }, void> } = eval(`({
async fnSetValueOnTinymceInput(args) {
/* eslint-env browser */
const iFrameElement = await document.querySelector(args.selector);
const iFrameHtml = iFrameElement.contentDocument.documentElement;
const textElement = await iFrameHtml.querySelector('body p');
textElement.textContent = args.vl;
}
})`);
await page.evaluate(fn.fnSetValueOnTinymceInput, args);
}
/**
* Set value on tinyMce textarea
* @param page {Page} Browser tab
* @param selector {string} Selector of the input to set value on
* @param value {string} Value
* @param onChange {boolean} Trigger the event 'change' on selector
* @return {Promise<void>}
*/
async setValueOnDateTimePickerInput(page: Page, selector: string, value: string, onChange: boolean = false): Promise<void> {
const args = {selector, value, onChange};