@@ -22,6 +22,7 @@ import toNS from 'mongodb-ns';
2222import path from 'path' ;
2323import os from 'os' ;
2424import fs from 'fs/promises' ;
25+ import type { ChainablePromiseElement } from 'webdriverio' ;
2526
2627interface Node {
2728 id : string ;
@@ -42,6 +43,34 @@ type DiagramInstance = {
4243 getEdges : ( ) => Array < Edge > ;
4344} ;
4445
46+ /**
47+ * Clicks on a specific element at the given coordinates.
48+ * element.click({ x: number, y: number }) doesn't work as expected,
49+ * so we do this manually using the actions API.
50+ * @param browser The Compass browser instance.
51+ * @param element The WebdriverIO element to click on.
52+ * @param coordinates The coordinates to click at.
53+ */
54+ async function clickElementAtCoordinates (
55+ browser : CompassBrowser ,
56+ element : ChainablePromiseElement ,
57+ coordinates : {
58+ x : number ;
59+ y : number ;
60+ }
61+ ) {
62+ await element . waitForClickable ( ) ;
63+ const location = await element . getLocation ( ) ;
64+ await browser
65+ . action ( 'pointer' )
66+ . move ( {
67+ x : location . x + coordinates . x ,
68+ y : location . y + coordinates . y ,
69+ } )
70+ . down ( { button : 0 } ) // Left mouse button
71+ . perform ( ) ;
72+ }
73+
4574async function setupDiagram (
4675 browser : CompassBrowser ,
4776 options : {
@@ -107,7 +136,12 @@ async function selectCollectionOnTheDiagram(
107136 const collectionNode = browser . $ ( Selectors . DataModelPreviewCollection ( ns ) ) ;
108137 await collectionNode . waitForClickable ( ) ;
109138
110- await collectionNode . click ( ) ;
139+ await clickElementAtCoordinates ( browser , collectionNode , {
140+ // we're aiming for the header (top of the node)
141+ // the default click is in the middle, most likely on a field
142+ x : 100 ,
143+ y : 15 ,
144+ } ) ;
111145
112146 await drawer . waitForDisplayed ( ) ;
113147
@@ -178,7 +212,7 @@ async function dragNode(
178212 . action ( 'pointer' )
179213 . move ( {
180214 x : Math . round ( startPosition . x + nodeSize . width / 2 ) ,
181- y : Math . round ( startPosition . y + nodeSize . height / 2 ) ,
215+ y : 15 , // we're aiming for the header area (top of the node)
182216 } )
183217 . down ( { button : 0 } ) // Left mouse button
184218 . move ( { duration : 1000 , origin : 'pointer' , ...pointerActionMoveParams } )
0 commit comments