Skip to content

Commit cb8031c

Browse files
Make end 2 end test util clickOnMoreMenuItem not dependent on aria labels being present on the button
1 parent 7fd6316 commit cb8031c

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* External dependencies
3+
*/
4+
import { first } from 'lodash';
5+
16
/**
27
* Clicks on More Menu item, searches for the button with the text provided and clicks it.
38
*
@@ -7,7 +12,18 @@ export async function clickOnMoreMenuItem( buttonLabel ) {
712
await expect( page ).toClick(
813
'.edit-post-more-menu [aria-label="Show more tools & options"]'
914
);
10-
await page.click(
11-
`.edit-post-more-menu__content button[aria-label="${ buttonLabel }"]`
12-
);
15+
const moreMenuContainerSelector =
16+
'//*[contains(concat(" ", @class, " "), " edit-post-more-menu__content ")]';
17+
let elementToClick = first( await page.$x(
18+
`${ moreMenuContainerSelector }//button[contains(text(), "${ buttonLabel }")]`
19+
) );
20+
// If button is not found, the label should be on the info wrapper.
21+
if ( ! elementToClick ) {
22+
elementToClick = first( await page.$x(
23+
moreMenuContainerSelector +
24+
'//button' +
25+
`/*[contains(concat(" ", @class, " "), " components-menu-item__info-wrapper ")][contains(text(), "${ buttonLabel }")]`
26+
) );
27+
}
28+
await elementToClick.click();
1329
}

0 commit comments

Comments
 (0)