@@ -396,21 +396,23 @@ async function dragBlockTypeFromFlyout(browser, categoryName, type, x, y) {
396396 * context menu item.
397397 *
398398 * @param browser The active WebdriverIO Browser object.
399- * @param block The block to click, as an interactable element.
399+ * @param block The block to click, as an interactable element. This block must
400+ * have text on it, because we use the text element as the click target.
400401 * @param itemText The display text of the context menu item to click.
401402 * @return A Promise that resolves when the actions are completed.
402403 */
403404async function contextMenuSelect ( browser , block , itemText ) {
404405 // Clicking will always happen in the middle of the block's bounds
405406 // (including children) by default, which causes problems if it has holes
406407 // (e.g. statement inputs).
407- // Instead we want to click 10px from the left and 10px from the top.
408- const blockWidth = await block . getSize ( 'width' ) ;
409- const blockHeight = await block . getSize ( 'height' ) ;
410- const xOffset = - Math . round ( blockWidth * 0.5 ) + 10 ;
411- const yOffset = - Math . round ( blockHeight * 0.5 ) + 10 ;
408+ // Instead, we'll click directly on the first bit of text on the block.
409+ const clickEl = block . $ ( '.blocklyText' ) ;
412410
413- await block . click ( { button : 2 , x : xOffset , y : yOffset } ) ;
411+ // Even though the element should definitely already exist,
412+ // one specific test breaks if you remove this...
413+ await clickEl . waitForExist ( ) ;
414+
415+ await clickEl . click ( { button : 2 } ) ;
414416
415417 const item = await browser . $ ( `div=${ itemText } ` ) ;
416418 await item . waitForExist ( ) ;
0 commit comments