-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy patheditor-page.js
801 lines (674 loc) · 24.5 KB
/
editor-page.js
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
/**
* Internal dependencies
*/
const {
doubleTap,
isAndroid,
isEditorVisible,
isElementVisible,
longPressMiddleOfElement,
setupDriver,
stopDriver,
swipeDown,
swipeFromTo,
swipeUp,
toggleHtmlMode,
typeString,
waitForVisible,
clickIfClickable,
} = require( '../helpers/utils' );
const initializeEditorPage = async () => {
const driver = await setupDriver();
await isEditorVisible( driver );
return new EditorPage( driver );
};
class EditorPage {
driver;
accessibilityIdKey;
accessibilityIdXPathAttrib;
paragraphBlockName = 'Paragraph';
verseBlockName = 'Verse';
orderedListButtonName = 'Ordered';
constructor( driver ) {
this.driver = driver;
this.accessibilityIdKey = 'name';
this.accessibilityIdXPathAttrib = 'name';
if ( isAndroid() ) {
this.accessibilityIdXPathAttrib = 'content-desc';
this.accessibilityIdKey = 'contentDescription';
}
}
async getBlockList() {
return await this.driver.hasElementByAccessibilityId( 'block-list' );
}
// ===============================
// Text blocks functions
// E.g. Paragraph, Heading blocks
// ===============================
async getTextBlockAtPosition( blockName, position = 1 ) {
// iOS needs a click to get the text element
if ( ! isAndroid() ) {
const textBlockLocator = `(//XCUIElementTypeButton[contains(@name, "${ blockName } Block. Row ${ position }")])`;
const textBlock = await waitForVisible(
this.driver,
textBlockLocator
);
await textBlock.click();
}
const blockLocator = isAndroid()
? `//android.view.ViewGroup[contains(@content-desc, "${ blockName } Block. Row ${ position }.")]//android.widget.EditText`
: `//XCUIElementTypeButton[contains(@name, "${ blockName } Block. Row ${ position }.")]//XCUIElementTypeTextView`;
return await waitForVisible( this.driver, blockLocator );
}
async typeTextToTextBlock( block, text, clear ) {
await typeString( this.driver, block, text, clear );
}
// Finds the wd element for new block that was added and sets the element attribute
// and accessibilityId attributes on this object and selects the block
// position uses one based numbering.
async getBlockAtPosition(
blockName,
position = 1,
options = { autoscroll: false }
) {
let elementType;
switch ( blockName ) {
case blockNames.cover:
elementType = 'XCUIElementTypeButton';
break;
default:
elementType = 'XCUIElementTypeOther';
break;
}
const blockLocator = isAndroid()
? `//android.view.ViewGroup[contains(@${ this.accessibilityIdXPathAttrib }, "${ blockName } Block. Row ${ position }")]`
: `(//${ elementType }[contains(@${ this.accessibilityIdXPathAttrib }, "${ blockName } Block. Row ${ position }")])[1]`;
await waitForVisible( this.driver, blockLocator );
const elements = await this.driver.elementsByXPath( blockLocator );
const lastElementFound = elements[ elements.length - 1 ];
if ( elements.length === 0 && options.autoscroll ) {
const firstBlockVisible = await this.getFirstBlockVisible();
const lastBlockVisible = await this.getLastBlockVisible();
// Exit if no block is found.
if ( ! firstBlockVisible || ! lastBlockVisible ) {
return lastElementFound;
}
const firstBlockAccessibilityId = await firstBlockVisible.getAttribute(
this.accessibilityIdKey
);
const firstBlockRowMatch = /Row (\d+)\./.exec(
firstBlockAccessibilityId
);
const firstBlockRow =
firstBlockRowMatch && Number( firstBlockRowMatch[ 1 ] );
const lastBlockAccessibilityId = await lastBlockVisible.getAttribute(
this.accessibilityIdKey
);
const lastBlockRowMatch = /Row (\d+)\./.exec(
lastBlockAccessibilityId
);
const lastBlockRow =
lastBlockRowMatch && Number( lastBlockRowMatch[ 1 ] );
if ( firstBlockRow && position < firstBlockRow ) {
if ( firstBlockRow === 1 ) {
// We're at the top already stop recursing.
return lastElementFound;
}
// Scroll up.
await swipeDown( this.driver );
} else if ( lastBlockRow && position > lastBlockRow ) {
// Scroll down.
await swipeUp( this.driver );
}
return await this.getBlockAtPosition(
blockName,
position,
options
);
}
return lastElementFound;
}
async getFirstBlockVisible() {
const firstBlockLocator = `//*[contains(@${ this.accessibilityIdXPathAttrib }, " Block. Row ")]`;
return await waitForVisible( this.driver, firstBlockLocator );
}
async getLastBlockVisible() {
const firstBlockLocator = `//*[contains(@${ this.accessibilityIdXPathAttrib }, " Block. Row ")]`;
await waitForVisible( this.driver, firstBlockLocator );
const elements = await this.driver.elementsByXPath( firstBlockLocator );
return elements[ elements.length - 1 ];
}
async hasBlockAtPosition( position = 1, blockName = '' ) {
return (
undefined !==
( await this.getBlockAtPosition( blockName, position ) )
);
}
async addParagraphBlockByTappingEmptyAreaBelowLastBlock() {
const emptyAreaBelowLastBlock = await this.driver.elementByAccessibilityId(
'Add paragraph block'
);
await emptyAreaBelowLastBlock.click();
}
async getTitleElement( options = { autoscroll: false } ) {
// TODO: Improve the identifier for this element
const elements = await this.driver.elementsByXPath(
`//*[contains(@${ this.accessibilityIdXPathAttrib }, "Post title.")]`
);
if ( elements.length === 0 && options.autoscroll ) {
await swipeDown( this.driver );
return this.getTitleElement( options );
}
return elements[ elements.length - 1 ];
}
// iOS loads the block list more eagerly compared to Android.
// This makes this function return elements without scrolling on iOS.
// So we are keeping this Android only.
async androidScrollAndReturnElement( accessibilityLabel ) {
const elements = await this.driver.elementsByXPath(
`//*[contains(@${ this.accessibilityIdXPathAttrib }, "${ accessibilityLabel }")]`
);
if ( elements.length === 0 ) {
await swipeUp( this.driver, undefined, 100, 1 );
return this.androidScrollAndReturnElement( accessibilityLabel );
}
return elements[ elements.length - 1 ];
}
async getLastElementByXPath( accessibilityLabel ) {
const elements = await this.driver.elementsByXPath(
`//*[contains(@${ this.accessibilityIdXPathAttrib }, "${ accessibilityLabel }")]`
);
return elements[ elements.length - 1 ];
}
async getTextViewForHtmlViewContent() {
const accessibilityId = 'html-view-content';
const htmlViewLocator = isAndroid()
? `//*[@${ this.accessibilityIdXPathAttrib }="${ accessibilityId }"]`
: `//XCUIElementTypeTextView[starts-with(@${ this.accessibilityIdXPathAttrib }, "${ accessibilityId }")]`;
return await waitForVisible( this.driver, htmlViewLocator );
}
// Returns html content
// Ensure to take additional steps to handle text being changed by auto correct.
async getHtmlContent() {
await toggleHtmlMode( this.driver, true );
const htmlContentView = await this.getTextViewForHtmlViewContent();
const text = await htmlContentView.text();
await toggleHtmlMode( this.driver, false );
return text;
}
// Set html editor content explicitly.
async setHtmlContent( html ) {
await toggleHtmlMode( this.driver, true );
const base64String = Buffer.from( html ).toString( 'base64' );
await this.driver.setClipboard( base64String, 'plaintext' );
const htmlContentView = await this.getTextViewForHtmlViewContent();
if ( isAndroid() ) {
// Attention! On Android `.type()` replaces the content of htmlContentView instead of appending
// contrary to what iOS is doing. On Android tried calling `driver.pressKeycode( 279 ) // KEYCODE_PASTE`
// before to paste, but for some reason it didn't work on GitHub Actions but worked only on Sauce Labs
await htmlContentView.type( html );
} else {
await htmlContentView.click();
await doubleTap( this.driver, htmlContentView );
// Sometimes double tap is not enough for paste menu to appear, so we also long press.
await longPressMiddleOfElement( this.driver, htmlContentView );
const pasteButton = await waitForVisible(
this.driver,
'//XCUIElementTypeMenuItem[@name="Paste"]'
);
await pasteButton.click();
}
await toggleHtmlMode( this.driver, false );
}
async dismissKeyboard() {
const keyboardShown = await this.driver.isKeyboardShown();
if ( ! keyboardShown ) {
return;
}
if ( isAndroid() ) {
return await this.driver.hideDeviceKeyboard();
}
const hideKeyboardToolbarButton = await this.driver.elementByXPath(
'//XCUIElementTypeButton[@name="Hide keyboard"]'
);
await hideKeyboardToolbarButton.click();
}
async dismissAndroidClipboardSmartSuggestion() {
if ( ! isAndroid() ) {
return;
}
const dismissClipboardSmartSuggestionLocator = `//*[@${ this.accessibilityIdXPathAttrib }="Dismiss Smart Suggestion"]`;
const smartSuggestions = await this.driver.elementsByXPath(
dismissClipboardSmartSuggestionLocator
);
if ( smartSuggestions.length !== 0 ) {
smartSuggestions[ 0 ].click();
}
}
async openBlockSettings( block ) {
await block.click();
const settingsButton = await block.elementByAccessibilityId(
'Open Settings'
);
await settingsButton.click();
}
async dismissBottomSheet() {
return await swipeDown( this.driver );
}
// =========================
// Block toolbar functions
// =========================
async addNewBlock( blockName, relativePosition ) {
const addBlockButtonLocator = isAndroid()
? '//android.widget.Button[@content-desc="Add block, Double tap to add a block"]'
: '//XCUIElementTypeButton[@name="add-block-button"]';
const addButton = await waitForVisible(
this.driver,
addBlockButtonLocator
);
if ( relativePosition === 'before' ) {
await longPressMiddleOfElement( this.driver, addButton );
const addBlockBeforeButtonLocator = isAndroid()
? '//android.widget.Button[@content-desc="Add Block Before"]'
: '//XCUIElementTypeButton[@name="Add Block Before"]';
await clickIfClickable( this.driver, addBlockBeforeButtonLocator );
} else {
await addButton.click();
}
// Click on block of choice.
const blockButton = await this.findBlockButton( blockName );
if ( isAndroid() ) {
await blockButton.click();
} else {
await this.driver.execute( 'mobile: tap', {
element: blockButton,
x: 10,
y: 10,
} );
}
}
static getInserterPageHeight( screenHeight ) {
// Rough estimate of a swipe distance required to scroll one page of blocks.
return screenHeight * 0.82;
}
// Attempts to find the given block button in the block inserter control.
async findBlockButton( blockName ) {
// Wait for the first block, Paragraph block, to load before looking for other blocks
const paragraphBlockLocator = isAndroid()
? '//android.widget.Button[@content-desc="Paragraph block"]/android.widget.TextView'
: '//XCUIElementTypeButton[@name="Paragraph block"]';
await waitForVisible( this.driver, paragraphBlockLocator );
const blockAccessibilityLabel = `${ blockName } block`;
const blockAccessibilityLabelNewBlock = `${ blockAccessibilityLabel }, newly available`;
if ( isAndroid() ) {
const size = await this.driver.getWindowSize();
const x = size.width / 2;
// Checks if the Block Button is available, and if not will scroll to the second half of the available buttons.
while (
! ( await this.driver.hasElementByAccessibilityId(
blockAccessibilityLabel
) ) &&
! ( await this.driver.hasElementByAccessibilityId(
blockAccessibilityLabelNewBlock
) )
) {
swipeFromTo(
this.driver,
{ x, y: size.height - 100 },
{ x, y: EditorPage.getInserterPageHeight( size.height ) }
);
}
if (
await this.driver.hasElementByAccessibilityId(
blockAccessibilityLabelNewBlock
)
) {
return await this.driver.elementByAccessibilityId(
blockAccessibilityLabelNewBlock
);
}
return await this.driver.elementByAccessibilityId(
blockAccessibilityLabel
);
}
const blockButton = ( await this.driver.hasElementByAccessibilityId(
blockAccessibilityLabelNewBlock
) )
? await this.driver.elementByAccessibilityId(
blockAccessibilityLabelNewBlock
)
: await this.driver.elementByAccessibilityId(
blockAccessibilityLabel
);
const size = await this.driver.getWindowSize();
// The virtual home button covers the bottom 34 in portrait and 21 on landscape on iOS.
// We start dragging a bit above it to not trigger home button.
const height = size.height - 50;
while ( ! ( await blockButton.isDisplayed() ) ) {
await this.driver.execute( 'mobile: dragFromToForDuration', {
fromX: 50,
fromY: height,
toX: 50,
toY: EditorPage.getInserterPageHeight( height ),
duration: 0.5,
} );
}
return blockButton;
}
async clickToolBarButton( buttonName ) {
const toolBarButton = await this.driver.elementByAccessibilityId(
buttonName
);
await toolBarButton.click();
}
// =========================
// Inline toolbar functions
// =========================
// position of the block to move up.
async moveBlockUpAtPosition( position, blockName = '' ) {
if ( ! ( await this.hasBlockAtPosition( position, blockName ) ) ) {
throw Error( `No Block at position ${ position }` );
}
const parentLocator = `//*[@${ this.accessibilityIdXPathAttrib }="${ blockName } Block. Row ${ position }."]`;
let blockLocator = `${ parentLocator }/following-sibling::*`;
blockLocator += isAndroid() ? '' : '//*';
blockLocator += `[@${
this.accessibilityIdXPathAttrib
}="Move block up from row ${ position } to row ${ position - 1 }"]`;
const moveUpButton = await this.driver.elementByXPath( blockLocator );
await moveUpButton.click();
}
// position of the block to move down.
async moveBlockDownAtPosition( position, blockName = '' ) {
if ( ! ( await this.hasBlockAtPosition( position, blockName ) ) ) {
throw Error( `No Block at position ${ position }` );
}
const parentLocator = `//*[contains(@${ this.accessibilityIdXPathAttrib }, "${ blockName } Block. Row ${ position }.")]`;
let blockLocator = `${ parentLocator }/following-sibling::*`;
blockLocator += isAndroid() ? '' : '//*';
blockLocator += `[@${
this.accessibilityIdXPathAttrib
}="Move block down from row ${ position } to row ${ position + 1 }"]`;
const moveDownButton = await this.driver.elementByXPath( blockLocator );
await moveDownButton.click();
}
// Position of the block to remove
// Block will no longer be present if this succeeds.
async removeBlockAtPosition( blockName = '', position = 1 ) {
if ( ! ( await this.hasBlockAtPosition( position, blockName ) ) ) {
throw Error( `No Block at position ${ position }` );
}
const buttonElementName = isAndroid()
? '//*'
: '//XCUIElementTypeButton';
const blockActionsMenuButtonIdentifier = `Open Block Actions Menu`;
const blockActionsMenuButtonLocator = `${ buttonElementName }[contains(@${ this.accessibilityIdXPathAttrib }, "${ blockActionsMenuButtonIdentifier }")]`;
const blockActionsMenuButton = await waitForVisible(
this.driver,
blockActionsMenuButtonLocator
);
if ( isAndroid() ) {
const block = await this.getBlockAtPosition( blockName, position );
let checkList = await this.driver.elementsByXPath(
blockActionsMenuButtonLocator
);
while ( checkList.length === 0 ) {
await swipeUp( this.driver, block ); // Swipe up to show remove icon at the bottom.
checkList = await this.driver.elementsByXPath(
blockActionsMenuButtonLocator
);
}
}
await blockActionsMenuButton.click();
const removeActionButtonIdentifier = 'Remove block';
const removeActionButtonLocator = `${ buttonElementName }[contains(@${ this.accessibilityIdXPathAttrib }, "${ removeActionButtonIdentifier }")]`;
const removeActionButton = await waitForVisible(
this.driver,
removeActionButtonLocator
);
await removeActionButton.click();
}
// =========================
// Paragraph Block functions
// =========================
async sendTextToParagraphBlock( position, text, clear ) {
const paragraphs = text.split( '\n' );
for ( let i = 0; i < paragraphs.length; i++ ) {
const block = await this.getTextBlockAtPosition(
blockNames.paragraph,
position + i
);
if ( isAndroid() ) {
await block.click();
}
await this.typeTextToTextBlock( block, paragraphs[ i ], clear );
if ( i !== paragraphs.length - 1 ) {
await this.typeTextToTextBlock( block, '\n', false );
}
}
}
async getTextForParagraphBlockAtPosition( position ) {
const blockLocator = await this.getTextBlockAtPosition(
blockNames.paragraph,
position
);
return await blockLocator.text();
}
async getNumberOfParagraphBlocks() {
const paragraphBlockLocator = isAndroid()
? `//android.view.ViewGroup[contains(@content-desc, "Paragraph Block. Row")]//android.widget.EditText`
: `(//XCUIElementTypeButton[contains(@name, "Paragraph Block. Row")])`;
const locator = await this.driver.elementsByXPath(
paragraphBlockLocator
);
return locator.length;
}
async assertSlashInserterPresent() {
const slashInserterLocator = isAndroid()
? '//android.widget.HorizontalScrollView[@content-desc="Slash inserter results"]/android.view.ViewGroup'
: '(//XCUIElementTypeOther[@name="Slash inserter results"])[1]';
return await isElementVisible( this.driver, slashInserterLocator, 5 );
}
// =========================
// List Block functions
// =========================
async getListBlockAtPosition(
position = 1,
options = { isEmptyBlock: false }
) {
// iOS needs a few extra steps to get the text element
if ( ! isAndroid() ) {
// Click the list in the correct position
await clickIfClickable(
this.driver,
`(//XCUIElementTypeOther[contains(@name, "List Block. Row ${ position }")])[1]`
);
const listBlockLocator = options.isEmptyBlock
? `(//XCUIElementTypeStaticText[contains(@name, "List")])`
: `//XCUIElementTypeButton[contains(@name, "List")]`;
await clickIfClickable( this.driver, listBlockLocator );
}
const listBlockTextLocatorIOS = options.isEmptyBlock
? `(//XCUIElementTypeStaticText[contains(@name, "List")])`
: `//XCUIElementTypeButton[contains(@name, "List")]//XCUIElementTypeTextView`;
const listBlockTextLocator = isAndroid()
? `//android.view.ViewGroup[contains(@content-desc, "List Block. Row ${ position }")]//android.widget.EditText`
: listBlockTextLocatorIOS;
return await waitForVisible( this.driver, listBlockTextLocator );
}
async clickOrderedListToolBarButton() {
const toolBarLocator = isAndroid()
? `//android.widget.Button[@content-desc="${ this.orderedListButtonName }"]`
: `//XCUIElementTypeButton[@name="${ this.orderedListButtonName }"]`;
await waitForVisible( this.driver, toolBarLocator );
await this.clickToolBarButton( this.orderedListButtonName );
}
// =========================
// Cover Block functions
// For iOS only
// =========================
async clickAddMediaFromCoverBlock() {
const mediaSection = await waitForVisible(
this.driver,
'//XCUIElementTypeOther[@name="Media Add image or video"]'
);
const addMediaButton = await mediaSection.elementByAccessibilityId(
'Add image or video'
);
await addMediaButton.click();
}
async replaceMediaImage() {
await clickIfClickable(
this.driver,
'(//XCUIElementTypeButton[@name="Edit image"])[1]'
);
await clickIfClickable(
this.driver,
'//XCUIElementTypeButton[@name="Replace"]'
);
}
// =========================
// Image Block functions
// =========================
async selectEmptyImageBlock( block ) {
const accessibilityId = await block.getAttribute(
this.accessibilityIdKey
);
const blockLocator = `//*[@${ this.accessibilityIdXPathAttrib }="${ accessibilityId }"]//XCUIElementTypeButton[@name="Image block. Empty"]`;
const imageBlockInnerElement = await this.driver.elementByXPath(
blockLocator
);
await imageBlockInnerElement.click();
}
async chooseMediaLibrary() {
const mediaLibraryLocator = isAndroid()
? `//android.widget.Button[@content-desc="WordPress Media Library"]`
: `//XCUIElementTypeButton[@name="WordPress Media Library"]`;
const mediaLibraryButton = await waitForVisible(
this.driver,
mediaLibraryLocator
);
await mediaLibraryButton.click();
}
async enterCaptionToSelectedImageBlock( caption, clear = true ) {
const imageBlockCaptionField = await this.driver.elementByXPath(
'//XCUIElementTypeButton[starts-with(@name, "Image caption.")]'
);
await imageBlockCaptionField.click();
await typeString( this.driver, imageBlockCaptionField, caption, clear );
}
async closePicker() {
if ( isAndroid() ) {
// Wait for media block picker to load before closing
const locator =
'//android.view.ViewGroup[2]/android.view.ViewGroup/android.view.ViewGroup';
await waitForVisible( this.driver, locator );
await swipeDown( this.driver );
} else {
const cancelButton = await waitForVisible(
this.driver,
'//XCUIElementTypeButton[@name="Cancel"]'
);
await cancelButton.click();
}
}
// =============================
// Search Block functions
// =============================
async getSearchBlockTextElement( testID ) {
const child = await this.driver.elementByAccessibilityId( testID );
if ( isAndroid() ) {
// Get the child EditText element of the ViewGroup returned by
// elementByAccessibilityId.
return await child.elementByClassName( 'android.widget.EditText' );
}
return child;
}
async sendTextToSearchBlockChild( testID, text ) {
const textViewElement = await this.getSearchBlockTextElement( testID );
return await typeString( this.driver, textViewElement, text );
}
async toggleHideSearchLabelSetting( block ) {
await this.openBlockSettings( block );
const elementName = isAndroid() ? '//*' : '//XCUIElementTypeOther';
const locator = `${ elementName }[starts-with(@${ this.accessibilityIdXPathAttrib }, "Hide search heading")]`;
const hideSearchHeadingToggle = await waitForVisible(
this.driver,
locator
);
return await hideSearchHeadingToggle.click();
}
async changeSearchButtonPositionSetting( block, buttonPosition ) {
await this.openBlockSettings( block );
const elementName = isAndroid() ? '//*' : '//XCUIElementTypeButton';
const locator = `${ elementName }[starts-with(@${ this.accessibilityIdXPathAttrib }, "Button position")]`;
let optionMenuButton = await waitForVisible( this.driver, locator );
await optionMenuButton.click();
const optionMenuButtonLocator = `${ elementName }[contains(@${ this.accessibilityIdXPathAttrib }, "${ buttonPosition }")]`;
optionMenuButton = await waitForVisible(
this.driver,
optionMenuButtonLocator
);
return await optionMenuButton.click();
}
async toggleSearchIconOnlySetting( block ) {
await this.openBlockSettings( block );
const elementName = isAndroid() ? '//*' : '//XCUIElementTypeOther';
const locator = `${ elementName }[starts-with(@${ this.accessibilityIdXPathAttrib }, "Use icon button")]`;
const useIconButton = await waitForVisible( this.driver, locator );
return await useIconButton.click();
}
async isSearchSettingsVisible() {
const elementName = isAndroid() ? '//*' : '//XCUIElementTypeButton';
const buttonPositionLocator = `${ elementName }[starts-with(@${ this.accessibilityIdXPathAttrib }, "Button position")]`;
return await waitForVisible( this.driver, buttonPositionLocator );
}
// =============================
// Unsupported Block functions
// =============================
async getUnsupportedBlockHelpButton() {
const accessibilityId = 'Help button';
const blockLocator = isAndroid()
? `//android.widget.Button[starts-with(@content-desc, "${ accessibilityId }")]`
: `//XCUIElementTypeButton[@name="${ accessibilityId }"]`;
return await waitForVisible( this.driver, blockLocator );
}
async getUnsupportedBlockBottomSheetEditButton() {
const accessibilityId = 'Edit using web editor';
const blockLocator = isAndroid()
? `//android.widget.Button[@content-desc="${ accessibilityId }"]`
: `//XCUIElementTypeButton[@name="${ accessibilityId }"]`;
return await waitForVisible( this.driver, blockLocator );
}
async getUnsupportedBlockWebView() {
const blockLocator = isAndroid()
? '//android.webkit.WebView'
: '//XCUIElementTypeWebView';
return await waitForVisible( this.driver, blockLocator );
}
async stopDriver() {
await stopDriver( this.driver );
}
async sauceJobStatus( allPassed ) {
await this.driver.sauceJobStatus( allPassed );
}
}
const blockNames = {
audio: 'Audio',
columns: 'Columns',
cover: 'Cover',
embed: 'Embed',
file: 'File',
gallery: 'Gallery',
heading: 'Heading',
image: 'Image',
latestPosts: 'Latest Posts',
list: 'List',
more: 'More',
paragraph: 'Paragraph',
search: 'Search',
separator: 'Separator',
spacer: 'Spacer',
verse: 'Verse',
};
module.exports = { initializeEditorPage, blockNames };