File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -1765,8 +1765,15 @@ class Playwright extends Helper {
1765
1765
const el = els [ 0 ] ;
1766
1766
1767
1767
await highlightActiveElement . call ( this , el ) ;
1768
+ let optionToSelect = '' ;
1768
1769
1769
- if ( ! Array . isArray ( option ) ) option = [ option ] ;
1770
+ try {
1771
+ optionToSelect = await el . locator ( 'option' , { hasText : option } ) . textContent ( ) ;
1772
+ } catch ( e ) {
1773
+ optionToSelect = option ;
1774
+ }
1775
+
1776
+ if ( ! Array . isArray ( option ) ) option = [ optionToSelect ] ;
1770
1777
1771
1778
await el . selectOption ( option ) ;
1772
1779
return this . _waitForAction ( ) ;
Original file line number Diff line number Diff line change @@ -15,6 +15,9 @@ const { deleteDir } = require('../../lib/utils');
15
15
const Secret = require ( '../../lib/secret' ) ;
16
16
global . codeceptjs = require ( '../../lib' ) ;
17
17
18
+ const dataFile = path . join ( __dirname , '/../data/app/db' ) ;
19
+ const formContents = require ( '../../lib/utils' ) . test . submittedData ( dataFile ) ;
20
+
18
21
let I ;
19
22
let page ;
20
23
let FS ;
@@ -438,6 +441,15 @@ describe('Playwright', function () {
438
441
} ) ) ;
439
442
} ) ;
440
443
444
+ describe ( '#selectOption' , ( ) => {
445
+ it ( 'should select option by label and partial option text' , async ( ) => {
446
+ await I . amOnPage ( '/form/select' ) ;
447
+ await I . selectOption ( 'Select your age' , '21-' ) ;
448
+ await I . click ( 'Submit' ) ;
449
+ assert . equal ( formContents ( 'age' ) , 'adult' ) ;
450
+ } ) ;
451
+ } ) ;
452
+
441
453
describe ( '#_locateClickable' , ( ) => {
442
454
it ( 'should locate a button to click' , ( ) => I . amOnPage ( '/form/checkbox' )
443
455
. then ( ( ) => I . _locateClickable ( 'Submit' ) )
You can’t perform that action at this time.
0 commit comments