File tree Expand file tree Collapse file tree 2 files changed +12
-12
lines changed Expand file tree Collapse file tree 2 files changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -270,16 +270,7 @@ export class StringifyExtension extends PuppeteerStringifyExtension {
270270 if ( idSelector ) return idSelector
271271
272272 /**
273- * use xPath selector if available
274- */
275- const xPathSelector = findByCondition (
276- selectors ,
277- ( s ) => s . startsWith ( XPATH_PREFIX )
278- )
279- if ( xPathSelector ) return `"${ xPathSelector . slice ( XPATH_PREFIX . length + 1 ) } `
280-
281- /**
282- * use WebdriverIOs aria selector
273+ * Use WebdriverIOs aria selector as second option
283274 * https://webdriver.io/docs/selectors#accessibility-name-selector
284275 */
285276 const ariaSelector = findByCondition (
@@ -291,6 +282,15 @@ export class StringifyExtension extends PuppeteerStringifyExtension {
291282 // Remove Aria selectors
292283 const nonAriaSelectors = this . filterArrayByString ( selectors , ARIA_PREFIX )
293284
285+ /**
286+ * use xPath selector if aria selector is not available
287+ */
288+ const xPathSelector = findByCondition (
289+ selectors ,
290+ ( s ) => s . startsWith ( XPATH_PREFIX )
291+ )
292+ if ( xPathSelector ) return `"${ xPathSelector . slice ( XPATH_PREFIX . length + 1 ) } `
293+
294294 let preferredSelector
295295
296296 // Give preference to user selector
Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ describe('StringifyExtension', () => {
8787 expect ( writer . toString ( ) ) . toBe ( 'await browser.$("#heading").setValue("webdriverio")\n' )
8888 } )
8989
90- it ( 'should prefer xPath selector' , async ( ) => {
90+ it ( 'should prefer aria selector over xpath ' , async ( ) => {
9191 const ext = new StringifyExtension ( )
9292 const step = {
9393 type : StepType . Change as const ,
@@ -98,7 +98,7 @@ describe('StringifyExtension', () => {
9898 const flow = { title : 'change step' , steps : [ step ] }
9999 const writer = new InMemoryLineWriter ( ' ' )
100100 await ext . stringifyStep ( writer , step , flow )
101- expect ( writer . toString ( ) ) . toBe ( 'await browser.$("//*[@data-test=\\"heading\\"] ").setValue("webdriverio")\n' )
101+ expect ( writer . toString ( ) ) . toBe ( 'await browser.$("aria/Search ").setValue("webdriverio")\n' )
102102 } )
103103
104104 it ( 'should prefer link text selectors' , async ( ) => {
You can’t perform that action at this time.
0 commit comments