#QUALITY by exept draft
authorClaus Gittinger <cg@exept.de>
Thu, 31 Oct 2019 02:29:24 +0100
changeset 3800 fb1763b613bf
parent 3799 bbb4c1dbce25
child 3801 e45e18e26a7d
#QUALITY by exept class: ShowMeHowItWorks added: #chooseBestComponentFrom: #click:clickTime: changed: #click:inComponent:clickTime: #findComponent:in: #freezePin:ofStep:with: #selectPin:ofStep:
ShowMeHowItWorks.st
--- a/ShowMeHowItWorks.st	Thu Oct 24 00:31:06 2019 +0200
+++ b/ShowMeHowItWorks.st	Thu Oct 31 02:29:24 2019 +0100
@@ -248,6 +248,7 @@
     diagramEditor doubleClickOn:pinPO.
     self fastMoveTo:(lastComponentName,'/','EditField').
     self click.
+    self clear.
     self type:freezeString.
     self key:#Return.
 !
@@ -337,13 +338,19 @@
 selectPin:pinName ofStep:stepName
     <action>
 
-    |diagramEditor pinPO|
+    |diagramEditor pinPO count|
 
     (diagramEditor := lastComponent) isScrollWrapper ifTrue:[
         diagramEditor := lastComponent scrolledView
     ].
-    pinPO := self pinPOForPin:pinName ofStep:stepName. 
-    self movePointerToComponent:diagramEditor offset:pinPO frame center.
+
+    count := 0.
+    [
+        Delay waitForSeconds:0.1.
+        pinPO := self pinPOForPin:pinName ofStep:stepName.
+    ] doWhile:[pinPO isNil and:[ (count := count+1) < 20]].
+
+    self movePointerToComponent:diagramEditor offset:(pinPO frame center).
     diagramEditor selection:{ pinPO }. 
 !
 
@@ -566,6 +573,15 @@
     "Modified: / 19-07-2019 / 16:10:19 / Claus Gittinger"
 !
 
+click:buttonNr clickTime:t
+    "press-release in last component"
+    
+    <action>
+
+    self assert:(buttonNr isInteger).
+    ^ self click:buttonNr inComponent:lastComponent clickTime:t
+!
+
 clickIn:componentName
     "press-release.
      Leaves component in lastComponent"
@@ -1210,6 +1226,26 @@
 
 !ShowMeHowItWorks methodsFor:'helpers - component search'!
 
+chooseBestComponentFrom:foundItems
+    |reallyShown inMyApp|
+
+    foundItems size == 1 ifTrue:[^ foundItems first].
+    foundItems size == 0 ifTrue:[^ nil].
+
+    reallyShown := foundItems select:[:item | item isReallyShown]. 
+    reallyShown size == 1 ifTrue:[^ reallyShown first].
+    reallyShown size == 0 ifTrue:[^ nil].
+
+    "/ is there one in my application
+    application notNil ifTrue:[
+        inMyApp := reallyShown select:[:item | item topView application == application].
+        inMyApp size == 1 ifTrue:[^ inMyApp first].
+    ].
+    "/ there seems to be a mapped view, but underneath
+    "/ select the last one found
+    ^ foundItems last.
+!
+
 componentNamed:componentName
     "retrieve a component by name or report an error if not found.
      Can return either a view or a menu item"
@@ -1451,7 +1487,14 @@
 
     foundByName notEmpty ifTrue:[
         checkIfAllMenuItemsDoTheSame value:foundByName.
-        self assert:(foundByName size == 1) message:'multiple components found by name'.
+        foundByName size > 1 ifTrue:[
+            |item|
+
+            (item := self chooseBestComponentFrom:foundByName) notNil ifTrue:[
+                ^ item
+            ].
+        ].
+        self assert:(foundByName size == 1) message:('multiple components found by name: %1' bindWith:componentNameOrPath).
         ^ foundByName first.
     ].
     foundByHelpKey notEmpty ifTrue:[
@@ -1627,9 +1670,13 @@
                 OperatingSystem 
                     generateMouseMoveEventX:pos x y:pos y;
                     generateButtonEvent:buttonNr down:true x:pos x y:pos y;
+                    yourself.
+                Delay waitForSeconds:clickTime.
+                OperatingSystem 
                     generateButtonEvent:buttonNr down:false x:pos x y:pos y;
-                    generateButtonEvent:buttonNr down:true x:pos x y:pos y;
-                    generateButtonEvent:buttonNr down:false x:pos x y:pos y.
+                    "/ generateButtonEvent:buttonNr down:true x:pos x y:pos y;
+                    "/ generateButtonEvent:buttonNr down:false x:pos x y:pos y;
+                    yourself.
                 ^ self.
             ].
             Display rootView simulateButtonPress:buttonNr at:pos sendDisplayEvent:true.