-
-
Notifications
You must be signed in to change notification settings - Fork 737
/
Copy pathPlaywright_test.js
1602 lines (1400 loc) · 51.4 KB
/
Playwright_test.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
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
let assert
let expect
import('chai').then((chai) => {
assert = chai.assert
expect = chai.expect
})
const path = require('path')
const fs = require('fs')
const playwright = require('playwright')
const TestHelper = require('../support/TestHelper')
const Playwright = require('../../lib/helper/Playwright')
const AssertionFailedError = require('../../lib/assert/error')
const webApiTests = require('./webapi')
const FileSystem = require('../../lib/helper/FileSystem')
const { deleteDir } = require('../../lib/utils')
const Secret = require('../../lib/secret')
global.codeceptjs = require('../../lib')
const dataFile = path.join(__dirname, '/../data/app/db')
const formContents = require('../../lib/utils').test.submittedData(dataFile)
let I
let page
let FS
const siteUrl = TestHelper.siteUrl()
describe('Playwright', function () {
this.timeout(35000)
this.retries(1)
before(() => {
global.codecept_dir = path.join(__dirname, '/../data')
I = new Playwright({
url: siteUrl,
windowSize: '500x700',
browser: process.env.BROWSER || 'chromium',
show: false,
waitForTimeout: 5000,
waitForAction: 500,
timeout: 2000,
restart: true,
chrome: {
args: ['--no-sandbox', '--disable-setuid-sandbox'],
},
defaultPopupAction: 'accept',
})
I._init()
return I._beforeSuite()
})
beforeEach(async () => {
webApiTests.init({
I,
siteUrl,
})
return I._before().then(() => {
page = I.page
browser = I.browser
})
})
afterEach(async () => {
return I._after()
})
describe('restart browser: #restartBrowser', () => {
it('should open a new tab after restart of browser', async () => {
await I.restartBrowser()
await I.wait(1)
const numPages = await I.grabNumberOfOpenTabs()
assert.equal(numPages, 1)
})
})
describe('open page : #amOnPage', () => {
it('should open main page of configured site', async () => {
await I.amOnPage('/')
const url = await page.url()
await url.should.eql(`${siteUrl}/`)
})
it('should open any page of configured site', async () => {
await I.amOnPage('/info')
const url = await page.url()
return url.should.eql(`${siteUrl}/info`)
})
it('should open absolute url', async () => {
await I.amOnPage(siteUrl)
const url = await page.url()
return url.should.eql(`${siteUrl}/`)
})
it('should open any page of configured site without leading slash', async () => {
await I.amOnPage('info')
const url = await page.url()
return url.should.eql(`${siteUrl}/info`)
})
it('should open blank page', async () => {
await I.amOnPage('about:blank')
const url = await page.url()
return url.should.eql('about:blank')
})
})
describe('grabDataFromPerformanceTiming', () => {
it('should return data from performance timing', async () => {
await I.amOnPage('/')
const res = await I.grabDataFromPerformanceTiming()
expect(res).to.have.property('responseEnd')
expect(res).to.have.property('domInteractive')
expect(res).to.have.property('domContentLoadedEventEnd')
expect(res).to.have.property('loadEventEnd')
})
})
describe('#seeCssPropertiesOnElements', () => {
it('should check background-color css property for given element', async () => {
try {
await I.amOnPage('https://codecept.io/helpers/Playwright/')
await I.seeCssPropertiesOnElements('.navbar', { 'background-color': 'rgb(128, 90, 213)' })
} catch (e) {
e.message.should.include(
"expected element (.navbar) to have CSS property { 'background-color': 'rgb(128, 90, 213)' }",
)
}
})
})
webApiTests.tests()
describe('#click', () => {
it('should not try to click on invisible elements', async () => {
await I.amOnPage('/invisible_elements')
await I.click('Hello World')
})
})
describe('#grabCheckedElementStatus', () => {
it('check grabCheckedElementStatus', async () => {
await I.amOnPage('/invisible_elements')
let result = await I.grabCheckedElementStatus({ id: 'html' })
assert.equal(result, true)
result = await I.grabCheckedElementStatus({ id: 'css' })
assert.equal(result, false)
result = await I.grabCheckedElementStatus({ id: 'js' })
assert.equal(result, true)
result = await I.grabCheckedElementStatus({ id: 'ts' })
assert.equal(result, false)
try {
await I.grabCheckedElementStatus({ id: 'basic' })
} catch (e) {
assert.equal(e.message, 'Element is not a checkbox or radio input')
}
})
})
describe('#grabDisabledElementStatus', () => {
it('check isElementDisabled', async () => {
await I.amOnPage('/invisible_elements')
let result = await I.grabDisabledElementStatus({ id: 'fortran' })
assert.equal(result, true)
result = await I.grabDisabledElementStatus({ id: 'basic' })
assert.equal(result, false)
})
})
describe('#waitForFunction', () => {
it('should wait for function returns true', () => {
return I.amOnPage('/form/wait_js').then(() => I.waitForFunction(() => window.__waitJs, 3))
})
it('should pass arguments and wait for function returns true', () => {
return I.amOnPage('/form/wait_js').then(() => I.waitForFunction((varName) => window[varName], ['__waitJs'], 3))
})
})
describe('#waitForVisible #waitForInvisible - within block', () => {
it('should wait for visible element', async () => {
await I.amOnPage('/iframe')
await I._withinBegin({
frame: '#number-frame-1234',
})
await I.waitForVisible('h1')
})
it('should wait for invisible element', async () => {
await I.amOnPage('/iframe')
await I._withinBegin({
frame: '#number-frame-1234',
})
await I.waitForInvisible('h9')
})
it('should wait for element to hide', async () => {
await I.amOnPage('/iframe')
await I._withinBegin({
frame: '#number-frame-1234',
})
await I.waitToHide('h9')
})
})
describe('#waitToHide', () => {
it('should wait for hidden element', () => {
return I.amOnPage('/form/wait_invisible')
.then(() => I.see('Step One Button'))
.then(() => I.waitToHide('#step_1', 2))
.then(() => I.dontSeeElement('#step_1'))
.then(() => I.dontSee('Step One Button'))
})
it('should wait for hidden element by XPath', () => {
return I.amOnPage('/form/wait_invisible')
.then(() => I.see('Step One Button'))
.then(() => I.waitToHide('//div[@id="step_1"]', 2))
.then(() => I.dontSeeElement('//div[@id="step_1"]'))
.then(() => I.dontSee('Step One Button'))
})
})
describe('#waitNumberOfVisibleElements', () => {
it('should wait for a specified number of elements on the page', () =>
I.amOnPage('/info')
.then(() => I.waitNumberOfVisibleElements('//div[@id = "grab-multiple"]//a', 3))
.then(() => I.waitNumberOfVisibleElements('//div[@id = "grab-multiple"]//a', 2, 0.1))
.then(() => {
throw Error('It should never get this far')
})
.catch((e) => {
e.message.should.include('The number of elements (//div[@id = "grab-multiple"]//a) is not 2 after 0.1 sec')
}))
it('should wait for a specified number of elements on the page using a css selector', () =>
I.amOnPage('/info')
.then(() => I.waitNumberOfVisibleElements('#grab-multiple > a', 3))
.then(() => I.waitNumberOfVisibleElements('#grab-multiple > a', 2, 0.1))
.then(() => {
throw Error('It should never get this far')
})
.catch((e) => {
e.message.should.include('The number of elements (#grab-multiple > a) is not 2 after 0.1 sec')
}))
it('should wait for a specified number of elements which are not yet attached to the DOM', () =>
I.amOnPage('/form/wait_num_elements')
.then(() => I.waitNumberOfVisibleElements('.title', 2, 3))
.then(() => I.see('Hello'))
.then(() => I.see('World')))
it('should wait for 0 number of visible elements', async () => {
await I.amOnPage('/form/wait_invisible')
await I.waitNumberOfVisibleElements('#step_1', 0)
})
})
describe('#moveCursorTo', () => {
it('should trigger hover event', () =>
I.amOnPage('/form/hover')
.then(() => I.moveCursorTo('#hover'))
.then(() => I.see('Hovered', '#show')))
it('should not trigger hover event because of the offset is beyond the element', () =>
I.amOnPage('/form/hover')
.then(() => I.moveCursorTo('#hover', 100, 100))
.then(() => I.dontSee('Hovered', '#show')))
})
describe('#switchToNextTab, #switchToPreviousTab, #openNewTab, #closeCurrentTab, #closeOtherTabs, #grabNumberOfOpenTabs, #waitForNumberOfTabs', () => {
it('should only have 1 tab open when the browser starts and navigates to the first page', () =>
I.amOnPage('/')
.then(() => I.wait(1))
.then(() => I.grabNumberOfOpenTabs())
.then((numPages) => assert.equal(numPages, 1)))
it('should switch to next tab', () =>
I.amOnPage('/info')
.then(() => I.wait(1))
.then(() => I.grabNumberOfOpenTabs())
.then((numPages) => assert.equal(numPages, 1))
.then(() => I.click('New tab'))
.then(() => I.switchToNextTab())
.then(() => I.wait(2))
.then(() => I.seeCurrentUrlEquals('/login'))
.then(() => I.grabNumberOfOpenTabs())
.then((numPages) => assert.equal(numPages, 2)))
it('should assert when there is no ability to switch to next tab', () =>
I.amOnPage('/')
.then(() => I.click('More info'))
.then(() => I.wait(1)) // Wait is required because the url is change by previous statement (maybe related to #914)
.then(() => I.switchToNextTab(2))
.then(() => I.wait(2))
.then(() => assert.equal(true, false, 'Throw an error if it gets this far (which it should not)!'))
.catch((e) => {
assert.equal(e.message, 'There is no ability to switch to next tab with offset 2')
}))
it('should close current tab', () =>
I.amOnPage('/info')
.then(() => I.click('New tab'))
.then(() => I.switchToNextTab())
.then(() => I.wait(2))
.then(() => I.seeInCurrentUrl('/login'))
.then(() => I.grabNumberOfOpenTabs())
.then((numPages) => assert.equal(numPages, 2))
.then(() => I.closeCurrentTab())
.then(() => I.wait(1))
.then(() => I.seeInCurrentUrl('/info'))
.then(() => I.grabNumberOfOpenTabs())
.then((numPages) => assert.equal(numPages, 1)))
it('should close other tabs', () =>
I.amOnPage('/')
.then(() => I.openNewTab())
.then(() => I.waitForNumberOfTabs(2))
.then(() => I.seeInCurrentUrl('about:blank'))
.then(() => I.amOnPage('/info'))
.then(() => I.openNewTab())
.then(() => I.amOnPage('/login'))
.then(() => I.closeOtherTabs())
.then(() => I.waitForNumberOfTabs(1))
.then(() => I.seeInCurrentUrl('/login'))
.then(() => I.grabNumberOfOpenTabs())
.then((numPages) => assert.equal(numPages, 1)))
it('should open new tab', () =>
I.amOnPage('/info')
.then(() => I.openNewTab())
.then(() => I.wait(1))
.then(() => I.seeInCurrentUrl('about:blank'))
.then(() => I.grabNumberOfOpenTabs())
.then((numPages) => assert.equal(numPages, 2)))
it('should switch to previous tab', () =>
I.amOnPage('/info')
.then(() => I.openNewTab())
.then(() => I.wait(1))
.then(() => I.seeInCurrentUrl('about:blank'))
.then(() => I.switchToPreviousTab())
.then(() => I.wait(2))
.then(() => I.seeInCurrentUrl('/info')))
it('should assert when there is no ability to switch to previous tab', () =>
I.amOnPage('/info')
.then(() => I.openNewTab())
.then(() => I.wait(1))
.then(() => I.waitInUrl('about:blank'))
.then(() => I.switchToPreviousTab(2))
.then(() => I.wait(2))
.then(() => I.waitInUrl('/info'))
.catch((e) => {
assert.equal(e.message, 'There is no ability to switch to previous tab with offset 2')
}))
})
describe('popup : #acceptPopup, #seeInPopup, #cancelPopup, #grabPopupText', () => {
it('should accept popup window', () =>
I.amOnPage('/form/popup')
.then(() => I.amAcceptingPopups())
.then(() => I.click('Confirm'))
.then(() => I.acceptPopup())
.then(() => I.see('Yes', '#result')))
it('should accept popup window (using default popup action type)', () =>
I.amOnPage('/form/popup')
.then(() => I.click('Confirm'))
.then(() => I.acceptPopup())
.then(() => I.see('Yes', '#result')))
it('should cancel popup', () =>
I.amOnPage('/form/popup')
.then(() => I.amCancellingPopups())
.then(() => I.click('Confirm'))
.then(() => I.cancelPopup())
.then(() => I.see('No', '#result')))
it('should check text in popup', () =>
I.amOnPage('/form/popup')
.then(() => I.amCancellingPopups())
.then(() => I.click('Alert'))
.then(() => I.seeInPopup('Really?'))
.then(() => I.cancelPopup()))
it('should grab text from popup', () =>
I.amOnPage('/form/popup')
.then(() => I.amCancellingPopups())
.then(() => I.click('Alert'))
.then(() => I.grabPopupText())
.then((text) => assert.equal(text, 'Really?')))
it('should return null if no popup is visible (do not throw an error)', () =>
I.amOnPage('/form/popup')
.then(() => I.grabPopupText())
.then((text) => assert.equal(text, null)))
})
describe('#seeNumberOfElements', () => {
it('should return 1 as count', () => I.amOnPage('/').then(() => I.seeNumberOfElements('#area1', 1)))
})
describe('#switchTo', () => {
it('should switch reference to iframe content', () => {
I.amOnPage('/iframe')
I.switchTo('[name="content"]')
I.see('Information')
I.see('Lots of valuable data here')
})
it('should return error if iframe selector is invalid', () =>
I.amOnPage('/iframe')
.then(() => I.switchTo('#invalidIframeSelector'))
.catch((e) => {
e.should.be.instanceOf(Error)
e.message.should.be.equal('Element "#invalidIframeSelector" was not found by text|CSS|XPath')
}))
it('should return error if iframe selector is not iframe', () =>
I.amOnPage('/iframe')
.then(() => I.switchTo('h1'))
.catch((e) => {
e.should.be.instanceOf(Error)
e.message.should.be.equal('Element "#invalidIframeSelector" was not found by text|CSS|XPath')
}))
it('should return to parent frame given a null locator', async () => {
I.amOnPage('/iframe')
I.switchTo('[name="content"]')
I.see('Information')
I.see('Lots of valuable data here')
I.switchTo(null)
I.see('Iframe test')
})
it('should switch to iframe using css', () => {
I.amOnPage('/iframe')
I.switchTo('iframe#number-frame-1234')
I.see('Information')
I.see('Lots of valuable data here')
})
it('should switch to iframe using css when there are more than one iframes', () => {
I.amOnPage('/iframes')
I.switchTo('iframe#number-frame-1234')
I.see('Information')
})
})
describe('#seeInSource, #grabSource', () => {
it('should check for text to be in HTML source', () =>
I.amOnPage('/')
.then(() => I.seeInSource('<title>TestEd Beta 2.0</title>'))
.then(() => I.dontSeeInSource('<meta')))
it('should grab the source', () =>
I.amOnPage('/')
.then(() => I.grabSource())
.then((source) =>
assert.notEqual(source.indexOf('<title>TestEd Beta 2.0</title>'), -1, 'Source html should be retrieved'),
))
})
describe('#seeTitleEquals', () => {
it('should check that title is equal to provided one', () =>
I.amOnPage('/')
.then(() => I.seeTitleEquals('TestEd Beta 2.0'))
.then(() => I.seeTitleEquals('TestEd Beta 2.'))
.then(() => assert.equal(true, false, 'Throw an error because it should not get this far!'))
.catch((e) => {
e.should.be.instanceOf(Error)
e.message.should.be.equal('expected web page title "TestEd Beta 2.0" to equal "TestEd Beta 2."')
}))
})
describe('#seeTextEquals', () => {
it('should check text is equal to provided one', () =>
I.amOnPage('/')
.then(() => I.seeTextEquals('Welcome to test app!', 'h1'))
.then(() => I.seeTextEquals('Welcome to test app', 'h1'))
.then(() => assert.equal(true, false, 'Throw an error because it should not get this far!'))
.catch((e) => {
e.should.be.instanceOf(Error)
e.message.should.be.equal('expected element h1 "Welcome to test app" to equal "Welcome to test app!"')
}))
})
describe('#selectOption', () => {
it('should select option by label and partial option text', async () => {
await I.amOnPage('/form/select')
await I.selectOption('Select your age', '21-')
await I.click('Submit')
assert.equal(formContents('age'), 'adult')
})
})
describe('#_locateClickable', () => {
it('should locate a button to click', () =>
I.amOnPage('/form/checkbox')
.then(() => I._locateClickable('Submit'))
.then((res) => {
res.length.should.be.equal(1)
}))
it('should not locate a non-existing checkbox using _locateClickable', () =>
I.amOnPage('/form/checkbox')
.then(() => I._locateClickable('I disagree'))
.then((res) => res.length.should.be.equal(0)))
})
describe('#_locateCheckable', () => {
it('should locate a checkbox', () =>
I.amOnPage('/form/checkbox')
.then(() => I._locateCheckable('I Agree'))
.then((res) => res.should.be.not.undefined))
})
describe('#_locateFields', () => {
it('should locate a field', () =>
I.amOnPage('/form/field')
.then(() => I._locateFields('Name'))
.then((res) => res.length.should.be.equal(1)))
it('should not locate a non-existing field', () =>
I.amOnPage('/form/field')
.then(() => I._locateFields('Mother-in-law'))
.then((res) => res.length.should.be.equal(0)))
})
describe('check fields: #seeInField, #seeCheckboxIsChecked, ...', () => {
it('should throw error if field is not empty', () =>
I.amOnPage('/form/empty')
.then(() => I.seeInField('#empty_input', 'Ayayay'))
.catch((e) => {
e.should.be.instanceOf(AssertionFailedError)
e.inspect().should.be.equal('expected fields by #empty_input to include "Ayayay"')
}))
it('should check values in checkboxes', async () => {
await I.amOnPage('/form/field_values')
await I.dontSeeInField('checkbox[]', 'not seen one')
await I.seeInField('checkbox[]', 'see test one')
await I.dontSeeInField('checkbox[]', 'not seen two')
await I.seeInField('checkbox[]', 'see test two')
await I.dontSeeInField('checkbox[]', 'not seen three')
await I.seeInField('checkbox[]', 'see test three')
})
it('should check values are the secret type in checkboxes', async () => {
await I.amOnPage('/form/field_values')
await I.dontSeeInField('checkbox[]', Secret.secret('not seen one'))
await I.seeInField('checkbox[]', Secret.secret('see test one'))
await I.dontSeeInField('checkbox[]', Secret.secret('not seen two'))
await I.seeInField('checkbox[]', Secret.secret('see test two'))
await I.dontSeeInField('checkbox[]', Secret.secret('not seen three'))
await I.seeInField('checkbox[]', Secret.secret('see test three'))
})
it('should check values with boolean', async () => {
await I.amOnPage('/form/field_values')
await I.seeInField('checkbox1', true)
await I.dontSeeInField('checkbox1', false)
await I.seeInField('checkbox2', false)
await I.dontSeeInField('checkbox2', true)
await I.seeInField('radio2', true)
await I.dontSeeInField('radio2', false)
await I.seeInField('radio3', false)
await I.dontSeeInField('radio3', true)
})
it('should check values in radio', async () => {
await I.amOnPage('/form/field_values')
await I.seeInField('radio1', 'see test one')
await I.dontSeeInField('radio1', 'not seen one')
await I.dontSeeInField('radio1', 'not seen two')
await I.dontSeeInField('radio1', 'not seen three')
})
it('should check values in select', async () => {
await I.amOnPage('/form/field_values')
await I.seeInField('select1', 'see test one')
await I.dontSeeInField('select1', 'not seen one')
await I.dontSeeInField('select1', 'not seen two')
await I.dontSeeInField('select1', 'not seen three')
})
it('should check for empty select field', async () => {
await I.amOnPage('/form/field_values')
await I.seeInField('select3', '')
})
it('should check for select multiple field', async () => {
await I.amOnPage('/form/field_values')
await I.dontSeeInField('select2', 'not seen one')
await I.seeInField('select2', 'see test one')
await I.dontSeeInField('select2', 'not seen two')
await I.seeInField('select2', 'see test two')
await I.dontSeeInField('select2', 'not seen three')
await I.seeInField('select2', 'see test three')
})
})
describe('#clearField', () => {
it('should clear input', async () => {
await I.amOnPage('/form/field')
await I.fillField('Name', 'value that is cleared using I.clearField()')
await I.clearField('Name')
await I.dontSeeInField('Name', 'value that is cleared using I.clearField()')
})
it('should clear div textarea', async () => {
await I.amOnPage('/form/field')
await I.clearField('#textarea')
await I.dontSeeInField('#textarea', 'I look like textarea')
})
it('should clear textarea', async () => {
await I.amOnPage('/form/textarea')
await I.fillField('#description', 'value that is cleared using I.clearField()')
await I.clearField('#description')
await I.dontSeeInField('#description', 'value that is cleared using I.clearField()')
})
xit('should clear contenteditable', async () => {
const isClearMethodPresent = await I.usePlaywrightTo(
'check if new Playwright .clear() method present',
async ({ page }) => {
return typeof page.locator().clear === 'function'
},
)
if (!isClearMethodPresent) {
this.skip()
}
await I.amOnPage('/form/contenteditable')
await I.clearField('#contenteditableDiv')
await I.dontSee('This is editable. Click here to edit this text.', '#contenteditableDiv')
})
})
describe('#pressKey, #pressKeyDown, #pressKeyUp', () => {
it('should be able to send special keys to element', async () => {
await I.amOnPage('/form/field')
await I.appendField('Name', '-')
await I.pressKey(['Right Shift', 'Home'])
await I.pressKey('Delete')
// Sequence only executes up to first non-modifier key ('Digit1')
await I.pressKey(['SHIFT_RIGHT', 'Digit1', 'Digit4'])
await I.pressKey('1')
await I.pressKey('2')
await I.pressKey('3')
await I.pressKey('ArrowLeft')
await I.pressKey('Left Arrow')
await I.pressKey('arrow_left')
await I.pressKeyDown('Shift')
await I.pressKey('a')
await I.pressKey('KeyB')
await I.pressKeyUp('ShiftLeft')
await I.pressKey('C')
await I.seeInField('Name', '!ABC123')
})
it('should use modifier key based on operating system', async () => {
await I.amOnPage('/form/field')
await I.fillField('Name', 'value that is cleared using select all shortcut')
await I.pressKey(['ControlOrCommand', 'a'])
await I.pressKey('Backspace')
await I.dontSeeInField('Name', 'value that is cleared using select all shortcut')
})
it('should show correct numpad or punctuation key when Shift modifier is active', async () => {
await I.amOnPage('/form/field')
await I.fillField('Name', '')
await I.pressKey(';')
await I.pressKey(['Shift', ';'])
await I.pressKey(['Shift', 'Semicolon'])
await I.pressKey('=')
await I.pressKey(['Shift', '='])
await I.pressKey(['Shift', 'Equal'])
await I.pressKey('*')
await I.pressKey(['Shift', '*'])
await I.pressKey(['Shift', 'Multiply'])
await I.pressKey('+')
await I.pressKey(['Shift', '+'])
await I.pressKey(['Shift', 'Add'])
await I.pressKey(',')
await I.pressKey(['Shift', ','])
await I.pressKey(['Shift', 'Comma'])
await I.pressKey(['Shift', 'NumpadComma'])
await I.pressKey(['Shift', 'Separator'])
await I.pressKey('-')
await I.pressKey(['Shift', '-'])
await I.pressKey(['Shift', 'Subtract'])
await I.pressKey('.')
await I.pressKey(['Shift', '.'])
await I.pressKey('/')
await I.pressKey(['Shift', '/'])
await I.pressKey(['Shift', 'Divide'])
await I.pressKey(['Shift', 'Slash'])
await I.seeInField('Name', ';::=++***+++,<<<<-_-.>/?/?')
})
})
describe('#waitForEnabled', () => {
it('should wait for input text field to be enabled', () =>
I.amOnPage('/form/wait_enabled')
.then(() => I.waitForEnabled('#text', 2))
.then(() => I.fillField('#text', 'hello world'))
.then(() => I.seeInField('#text', 'hello world')))
it('should wait for input text field to be enabled by xpath', () =>
I.amOnPage('/form/wait_enabled')
.then(() => I.waitForEnabled("//*[@name = 'test']", 2))
.then(() => I.fillField('#text', 'hello world'))
.then(() => I.seeInField('#text', 'hello world')))
it('should wait for a button to be enabled', () =>
I.amOnPage('/form/wait_enabled')
.then(() => I.waitForEnabled('#text', 2))
.then(() => I.click('#button'))
.then(() => I.see('button was clicked', '#message')))
})
describe('#waitForDisabled', () => {
it('should wait for input text field to be disabled', () =>
I.amOnPage('/form/wait_disabled').then(() => I.waitForDisabled('#text', 1)))
it('should wait for input text field to be enabled by xpath', () =>
I.amOnPage('/form/wait_disabled').then(() => I.waitForDisabled("//*[@name = 'test']", 1)))
it('should wait for a button to be disabled', () =>
I.amOnPage('/form/wait_disabled').then(() => I.waitForDisabled('#text', 1)))
})
describe('#waitForValue', () => {
it('should wait for expected value for given locator', () =>
I.amOnPage('/info')
.then(() => I.waitForValue('//input[@name= "rus"]', 'Верно'))
.then(() => I.waitForValue('//input[@name= "rus"]', 'Верно3', 0.1))
.then(() => {
throw Error('It should never get this far')
})
.catch((e) => {
e.message.should.include(
'element (//input[@name= "rus"]) is not in DOM or there is no element(//input[@name= "rus"]) with value "Верно3" after 0.1 sec',
)
}))
it('should wait for expected value for given css locator', () =>
I.amOnPage('/form/wait_value')
.then(() => I.seeInField('#text', 'Hamburg'))
.then(() => I.waitForValue('#text', 'Brisbane', 2.5))
.then(() => I.seeInField('#text', 'Brisbane')))
it('should wait for expected value for given xpath locator', () =>
I.amOnPage('/form/wait_value')
.then(() => I.seeInField('#text', 'Hamburg'))
.then(() => I.waitForValue('//input[@value = "Grüße aus Hamburg"]', 'Brisbane', 2.5))
.then(() => I.seeInField('#text', 'Brisbane')))
it('should only wait for one of the matching elements to contain the value given xpath locator', () =>
I.amOnPage('/form/wait_value')
.then(() => I.waitForValue('//input[@type = "text"]', 'Brisbane', 4))
.then(() => I.seeInField('#text', 'Brisbane'))
.then(() => I.seeInField('#text2', 'London')))
it('should only wait for one of the matching elements to contain the value given css locator', () =>
I.amOnPage('/form/wait_value')
.then(() => I.waitForValue('.inputbox', 'Brisbane', 4))
.then(() => I.seeInField('#text', 'Brisbane'))
.then(() => I.seeInField('#text2', 'London')))
})
describe('#grabHTMLFrom', () => {
it('should grab inner html from an element using xpath query', () =>
I.amOnPage('/')
.then(() => I.grabHTMLFrom('//title'))
.then((html) => assert.equal(html, 'TestEd Beta 2.0')))
it('should grab inner html from an element using id query', () =>
I.amOnPage('/')
.then(() => I.grabHTMLFrom('#area1'))
.then((html) => assert.equal(html.trim(), '<a href="/form/file" qa-id="test" qa-link="test"> Test Link </a>')))
it('should grab inner html from multiple elements', () =>
I.amOnPage('/')
.then(() => I.grabHTMLFromAll('//a'))
.then((html) => assert.equal(html.length, 5)))
it('should grab inner html from within an iframe', () =>
I.amOnPage('/iframe')
.then(() => I.switchTo({ frame: 'iframe' }))
.then(() => I.grabHTMLFrom('#new-tab'))
.then((html) => assert.equal(html.trim(), '<a href="/login" target="_blank">New tab</a>')))
})
describe('#grabBrowserLogs', () => {
it('should grab browser logs', () =>
I.amOnPage('/')
.then(() =>
I.executeScript(() => {
console.log('Test log entry')
}),
)
.then(() => I.grabBrowserLogs())
.then((logs) => {
const matchingLogs = logs.filter((log) => log.text().indexOf('Test log entry') > -1)
assert.equal(matchingLogs.length, 1)
}))
it('should grab browser logs in new tab', () =>
I.amOnPage('/')
.then(() => I.openNewTab())
.then(() =>
I.executeScript(() => {
console.log('Test log entry')
}),
)
.then(() => I.grabBrowserLogs())
.then((logs) => {
const matchingLogs = logs.filter((log) => log.text().indexOf('Test log entry') > -1)
assert.equal(matchingLogs.length, 1)
}))
it('should grab browser logs in two tabs', () =>
I.amOnPage('/')
.then(() =>
I.executeScript(() => {
console.log('Test log entry 1')
}),
)
.then(() => I.openNewTab())
.then(() =>
I.executeScript(() => {
console.log('Test log entry 2')
}),
)
.then(() => I.grabBrowserLogs())
.then((logs) => {
const matchingLogs = logs.filter((log) => log.text().includes('Test log entry'))
assert.equal(matchingLogs.length, 2)
}))
it('should grab browser logs in next tab', () =>
I.amOnPage('/info')
.then(() => I.click('New tab'))
.then(() => I.switchToNextTab())
.then(() =>
I.executeScript(() => {
console.log('Test log entry')
}),
)
.then(() => I.grabBrowserLogs())
.then((logs) => {
const matchingLogs = logs.filter((log) => log.text().indexOf('Test log entry') > -1)
assert.equal(matchingLogs.length, 1)
}))
})
describe('#dragAndDrop', () => {
it('Drag item from source to target (no iframe) @dragNdrop - customized steps', () =>
I.amOnPage('https://jqueryui.com/resources/demos/droppable/default.html')
.then(() => I.seeElementInDOM('#draggable'))
.then(() => I.dragAndDrop('#draggable', '#droppable'))
.then(() => I.see('Dropped')))
it('Drag item from source to target (no iframe) @dragNdrop - using Playwright API', () =>
I.amOnPage('https://jqueryui.com/resources/demos/droppable/default.html')
.then(() => I.seeElementInDOM('#draggable'))
.then(() => I.dragAndDrop('#draggable', '#droppable', { force: true }))
.then(() => I.see('Dropped')))
xit('Drag and drop from within an iframe', () =>
I.amOnPage('https://jqueryui.com/droppable')
.then(() => I.resizeWindow(700, 700))
.then(() => I.switchTo('//iframe[@class="demo-frame"]'))
.then(() => I.seeElementInDOM('#draggable'))
.then(() => I.dragAndDrop('#draggable', '#droppable'))
.then(() => I.see('Dropped')))
})
describe('#switchTo frame', () => {
it('should switch to frame using name', () =>
I.amOnPage('/iframe')
.then(() => I.see('Iframe test', 'h1'))
.then(() => I.dontSee('Information', 'h1'))
.then(() => I.switchTo('iframe'))
.then(() => I.see('Information', 'h1'))
.then(() => I.dontSee('Iframe test', 'h1')))
it('should switch to root frame', () =>
I.amOnPage('/iframe')
.then(() => I.see('Iframe test', 'h1'))
.then(() => I.dontSee('Information', 'h1'))
.then(() => I.switchTo('iframe'))
.then(() => I.see('Information', 'h1'))
.then(() => I.dontSee('Iframe test', 'h1'))
.then(() => I.switchTo())
.then(() => I.see('Iframe test', 'h1')))
it('should switch to frame using frame number', () =>
I.amOnPage('/iframe')
.then(() => I.see('Iframe test', 'h1'))
.then(() => I.dontSee('Information', 'h1'))
.then(() => I.switchTo(0))
.then(() => I.see('Information', 'h1'))
.then(() => I.dontSee('Iframe test', 'h1')))
})
describe('#dragSlider', () => {
it('should drag scrubber to given position', async () => {
await I.amOnPage('/form/page_slider')
await I.seeElementInDOM('#slidecontainer input')
const before = await I.grabValueFrom('#slidecontainer input')
await I.dragSlider('#slidecontainer input', 20)
const after = await I.grabValueFrom('#slidecontainer input')
assert.notEqual(before, after)
})
})
describe('#uncheckOption', () => {
it('should uncheck option that is currently checked', async () => {
await I.amOnPage('/info')
await I.uncheckOption('interesting')
await I.dontSeeCheckboxIsChecked('interesting')
})
it('should NOT uncheck option that is NOT currently checked', async () => {
await I.amOnPage('/info')
await I.uncheckOption('interesting')
// Unchecking again should not affect the current 'unchecked' status
await I.uncheckOption('interesting')
await I.dontSeeCheckboxIsChecked('interesting')
})
})
describe('#usePlaywrightTo', () => {
it('should return title', async () => {
await I.amOnPage('/')
const title = await I.usePlaywrightTo('test', async ({ page }) => {
return page.title()
})
assert.equal('TestEd Beta 2.0', title)
})
it('should pass expected parameters', async () => {
await I.amOnPage('/')
const params = await I.usePlaywrightTo('test', async (params) => {
return params
})
expect(params.page).to.exist
expect(params.browserContext).to.exist
expect(params.browser).to.exist
})
})
describe('#mockRoute, #stopMockingRoute', () => {
it('should mock a route', async () => {
await I.amOnPage('/form/fetch_call')
await I.mockRoute('https://reqres.in/api/comments/1', (route) => {
route.fulfill({
status: 200,
headers: { 'Access-Control-Allow-Origin': '*' },
contentType: 'application/json',
body: '{"name": "this was mocked" }',
})
})
await I.click('GET COMMENTS')
await I.see('this was mocked')
await I.stopMockingRoute('https://reqres.in/api/comments/1')
await I.click('GET COMMENTS')
await I.see('data')
await I.dontSee('this was mocked')
})
})
describe('#makeApiRequest', () => {
it('should make 3rd party API request', async () => {
const response = await I.makeApiRequest('get', 'https://reqres.in/api/users?page=2')
expect(response.status()).to.equal(200)
expect(await response.json()).to.include.keys(['page'])
})
it('should make local API request', async () => {
const response = await I.makeApiRequest('get', '/form/fetch_call')
expect(response.status()).to.equal(200)
})
it('should convert to axios response with onResponse hook', async () => {
let response