@@ -1763,20 +1763,21 @@ class Playwright extends Helper {
17631763 async dragAndDrop ( srcElement , destElement , options ) {
17641764 const src = new Locator ( srcElement )
17651765 const dst = new Locator ( destElement )
1766+ const context = await this . _getContext ( )
17661767
17671768 if ( options ) {
1768- return this . page . dragAndDrop ( buildLocatorString ( src ) , buildLocatorString ( dst ) , options )
1769+ return context . dragAndDrop ( buildLocatorString ( src ) , buildLocatorString ( dst ) , options )
17691770 }
17701771
17711772 const _smallWaitInMs = 600
1772- await this . page . locator ( buildLocatorString ( src ) ) . hover ( )
1773+ await context . locator ( buildLocatorString ( src ) ) . hover ( )
17731774 await this . page . mouse . down ( )
17741775 await this . page . waitForTimeout ( _smallWaitInMs )
17751776
1776- const destElBox = await this . page . locator ( buildLocatorString ( dst ) ) . boundingBox ( )
1777+ const destElBox = await context . locator ( buildLocatorString ( dst ) ) . boundingBox ( )
17771778
17781779 await this . page . mouse . move ( destElBox . x + destElBox . width / 2 , destElBox . y + destElBox . height / 2 )
1779- await this . page . locator ( buildLocatorString ( dst ) ) . hover ( { position : { x : 10 , y : 10 } } )
1780+ await context . locator ( buildLocatorString ( dst ) ) . hover ( { position : { x : 10 , y : 10 } } )
17801781 await this . page . waitForTimeout ( _smallWaitInMs )
17811782 await this . page . mouse . up ( )
17821783 }
@@ -2820,6 +2821,17 @@ class Playwright extends Helper {
28202821 *
28212822 */
28222823 async grabTextFrom ( locator ) {
2824+ // Handle role locators with text/exact options
2825+ if ( locator && typeof locator === 'object' && locator . role && ! locator . type ) {
2826+ const options = { }
2827+ if ( locator . text ) options . name = locator . text
2828+ if ( locator . exact !== undefined ) options . exact = locator . exact
2829+ const text = await this . page . getByRole ( locator . role , Object . keys ( options ) . length > 0 ? options : undefined ) . first ( ) . textContent ( )
2830+ assertElementExists ( text , JSON . stringify ( locator ) )
2831+ this . debugSection ( 'Text' , text )
2832+ return text
2833+ }
2834+
28232835 const locatorObj = new Locator ( locator , 'css' )
28242836
28252837 if ( locatorObj . isCustom ( ) ) {
@@ -4338,6 +4350,18 @@ async function findElements(matcher, locator) {
43384350 if ( isVueLocator ) return findVue ( matcher , locator )
43394351 if ( isPwLocator ) return findByPlaywrightLocator . call ( this , matcher , locator )
43404352
4353+ // Handle role locators with text/exact options (e.g., {role: 'button', text: 'Submit', exact: true})
4354+ if ( locator && typeof locator === 'object' && locator . role && ! locator . type ) {
4355+ const options = { }
4356+ if ( locator . text ) {
4357+ options . name = locator . text
4358+ }
4359+ if ( locator . exact !== undefined ) {
4360+ options . exact = locator . exact
4361+ }
4362+ return matcher . getByRole ( locator . role , Object . keys ( options ) . length > 0 ? options : undefined ) . all ( )
4363+ }
4364+
43414365 locator = new Locator ( locator , 'css' )
43424366
43434367 // Handle custom locators directly instead of relying on Playwright selector engines
@@ -4585,6 +4609,14 @@ async function findCheckable(locator, context) {
45854609 contextEl = contextEl [ 0 ]
45864610 }
45874611
4612+ // Handle role locators with text/exact options
4613+ if ( locator && typeof locator === 'object' && locator . role && ! locator . type ) {
4614+ const options = { }
4615+ if ( locator . text ) options . name = locator . text
4616+ if ( locator . exact !== undefined ) options . exact = locator . exact
4617+ return contextEl . getByRole ( locator . role , Object . keys ( options ) . length > 0 ? options : undefined ) . all ( )
4618+ }
4619+
45884620 const matchedLocator = new Locator ( locator )
45894621 if ( ! matchedLocator . isFuzzy ( ) ) {
45904622 return findElements . call ( this , contextEl , matchedLocator )
@@ -4611,6 +4643,15 @@ async function proceedIsChecked(assertType, option) {
46114643}
46124644
46134645async function findFields ( locator ) {
4646+ // Handle role locators with text/exact options
4647+ if ( locator && typeof locator === 'object' && locator . role && ! locator . type ) {
4648+ const options = { }
4649+ if ( locator . text ) options . name = locator . text
4650+ if ( locator . exact !== undefined ) options . exact = locator . exact
4651+ const page = await this . page
4652+ return page . getByRole ( locator . role , Object . keys ( options ) . length > 0 ? options : undefined ) . all ( )
4653+ }
4654+
46144655 const matchedLocator = new Locator ( locator )
46154656 if ( ! matchedLocator . isFuzzy ( ) ) {
46164657 return this . _locate ( matchedLocator )
0 commit comments