Forum Discussion

matt_tarka's avatar
matt_tarka
New Contributor
11 years ago

JavaFX Tooltip

I am trying to get TesComplete 10.30 to confirm that a tooltip came up on screen in a JavaFX GUI.



The underlying JavaFX code checks a configuration file to determine the correct text to display for the tooltip.  Thus, the text associated for the tooltip field that one can access through the object browser does not match what appears on screen.  Alternately, what the GUI displays is not the same as what the tooltip field for the associated object has stored for the tooltip field.



Also, I cannot determine how to identify whether the tooltip actually appeared at a given time (outside of manually inspecting the Visualizer).  I can get the Visualizer to capture the frame when the tooltip is onscreeen, but the Visualizer will not recognize the tooltip as an object.  



I've been able to do this in script



set button1Obj = Sys.Process("java").JavaFXObject("Stage", "JDMS").JavaFXObject("Scene", "").JavaFXObject("ScrollPane", "").JavaFXObject("provisionTitledPane").JavaFXObject("button1")

 

‘I then got the ‘tooltip’ field for the button1Obj by looking at the fields of button1Obj

 

set result = aqObject.GetFields(button1Obj, True)

  

 

   for i = 0 to result.Count - 1

    set objField = result(i)

    if objField.Name = "tooltip" then

 

      set tooltipField = objField

      set tooltipVObj = tooltipField.Value

 

       set tooltipVObj = tooltipField.Value

       ‘tooltipVObj has JavaFullClassName: javafx.scene.control.Control$3

           

      set tooltipVVObj = aqObject.GetPropertyValue(tooltipVObj, "Value")

      ‘tooltipVVObj has JavaFullClassname: javafx.scene.control.Tooltip

 

     set tooltipVVTObj = aqObject.GetPropertyValue(tooltipVVObj, "Text")

     ‘tooltipVVObj has tooltipVVTObj JavaFullClassName: javafx.beans.property.SimpleStringProperty     

 

     set tooltipText = aqObject.GetPropertyValue(tooltipVVTObj, "Value")

     ‘tooltipText has JavaFullClassName: java.lang.String

 

      log.checkpoint "Tooltip OleValue: " + tooltipTextOleValue

      ‘the OleValue is the default value that the code overwrites when it generates the tooltip

      log.checkpoint "Tooltip JavaFullClassName: " + tooltipTextFullClassName

 

      exit for

     end if

   Next





Tooltip OleValue is a default value for the tooltip that the code replaces after looking up the button name in a configuration file.



When I try to run the FindChild on any of the objects (except the button1Obj which is a JavaFX object) that I set, I get an error (see attached), if not visisble below.  I did not find any children of the button1Obj with the FindChild("JavaFullClassName","*").

 

Here is an example of the command:

 

               set javaClass = tooltipField.FindChild("JavaFullClassName","*")



I am at a loss for here.  I've looked at other threads, but they were not JavaFX-specific and didn't lead me to where I want to be.  I wince at the thought of needing to access the JavaRuntime.JavaClasses because I toyed with that approach already and was not able to access the value that I wanted (because the values weren't easily identifiable in the class).



  • matt_tarka's avatar
    matt_tarka
    New Contributor

    I was able to find the phantom Tooltip object

     

    Here is what I normally see in the Object Browser when testing the JavaFX GUI.

     

    Object_Browser_Java_Process.png

     

    The JavaFXObject(“Stage”, “JDMS”) contain the buttons, panes, etc.  The problem with Tooltips is that they come and go quickly.  The Object Browser will not usually show them.

     

    I was lucky enough to see a flicker in the Object Browser.  The flicker was the appearance and disappearance of this.

     

    JavaFXObject("Tooltip", "")

     

    This flicker seemed to occur directly under the Process(“java”) and not within the branch that contains the buttons, panels, panes, etc. So, I went looking there.

     

    I wrote a script to look for the creation of the tooltip while I moved the mouse around on the tested application.  Initially, I just looked for a of Sys.Process(“java”) child that contained “tooltip” in the full name.  Once, I captured that object I was able to determine the exact full name that I sought to find.  There was a trick in that as well.  By looking at the Java code for javafx.scene.control.Tooltip, I was able to identify the getText() method for the class (because I couldn’t see the object in the object browser I was unable to see which methods of the object that TestComplete would support).  Anyway, the getText() method returned the displayed text, not default text associated with the tooltip field for the button (over which the mouse hover occurs).

     

    Here is the script.

     

    Sub FindTooltipObject

     

    dim Timer1

    dim i

    dim iChildren

    dim tooltipObj

    dim tooltipObjFullName

    dim bFlag

     

      bFlag = false

     

      'tooltipObj full name = Sys.Process("java").JavaFXObject("Tooltip", "")

      'build strings with Ascii character for quotes

     

      tooltipObjFullName = "Sys.Process(" + chr(34) + "java" + chr(34) + ").JavaFXObject(" + chr(34) + _

                "Tooltip" + chr(34) + ", " + chr(34) + chr(34) + ")"

      

      Timer1 = Time

     

      Set javaObj = Sys.Process("java")

      javaObj.Refresh

     

      'Run do loop and look for conditions that indicate a tooltip is present

      'normally Sys.Process("java") will have 11 children --

      'When a tooltip appears, it bumps the total to twelve -- look for the tooltipObj only when

      ' the javaObj has greater than 11 children

      'looking for the tooltip by object when it doesn't occur will slow code execution and

      'possibly allow the tooltip to disappear.

     

      do

        'remember to force refresh to have the javaObj current and containing the tooltip

        'object in a child

        javaObj.Refresh

     

        if cint(javaObj.ChildCount) > 11 then

          for i = 0 to javaObj.ChildCount - 1

            'Log.Message javaObj.Child(i).FullName

            'comparison by full name without InStr function should be faster

            if tooltipObjFullName = javaObj.Child(i).FullName then

            'if InStr(javaObj.Child(i).FullName, "Tooltip") <> 0 then 

              set tooltipObj = javaObj.Child(i)

              log.Picture tooltipObj, "Captured tooltip image."

              'Log.Message "Tooltip JavaFXObject full name: " + tooltipObj.FullName

             

              'check javafx code for javafx.scene.control.Tooltip for available methods

              'because the TestComplete doesn't map this object and finding it and its methods in the object browser will

              'be extremely difficult - still getText method works.

              log.Checkpoint "Displayed tooltip text: " + tooltipObj.GetText()

              bFlag = true

              exit do

            end if

          Next

        else

          'log.message "nothing to report"

        end if

     

     

      Loop Until ((Time - Timer1)*20000) > 2

     

      if Not(bFlag) then

        log.Warning "Fail. No tooltip displayed."

      end if

     

    End sub