Forum Discussion

cg-ngc's avatar
cg-ngc
Occasional Contributor
1 year ago

Re: [Java AUT / JavaScript test] .Exists waits when window exists but is not visible

WaitAliasChild does indeed always return immediately.

Your statement "Property Exists will return immediately" is, however, incorrect (At least in my case)

It will ONLY return immediately if the element is visible.
If it's invisible, it will wait for the default timeout

WRT the enclosing of an if statement - yeah, in production code, I would indeed do that. For the sample code, however, I KNEW whether it would return true or false, I just did it that way to keep the sample code shorter

11 Replies

      • cg-ngc's avatar
        cg-ngc
        Occasional Contributor

        Isn't that a web app? My AUT is Java, so does not seem like a representative test

    • cg-ngc's avatar
      cg-ngc
      Occasional Contributor

      RefreshMappingInfo() makes it worse. It causes the waitAliasChild() to wait as well.

      Here is proof that the issue is nothing to do with a quirk of the AUT.

      Example Java App:

      package com.example;
      
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      
      public class App extends JPanel implements ActionListener {
          private static JFrame childFrame;
          private static boolean secondFrameVisible = false;
      
          public App() {
              childFrame = new JFrame("Child Window");
              childFrame.setName("Child Frame");
              JLabel childLabel = new JLabel("This is a child frame");
              childLabel.setPreferredSize(new Dimension(400, 400));
              childFrame.getContentPane().add(childLabel);
              childFrame.pack();
              toggleSecondFrameVisibility();
      
              JButton toggleButton = new JButton("Toggle visibility");
              toggleButton.setActionCommand("vis");
              toggleButton.addActionListener(this);
              add(toggleButton);
          }
      
          private static void createAndShowGUI() {
              JFrame frame = new JFrame("FrameDemo");
              frame.setName("Main Frame");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setContentPane(new App());
              frame.pack();
              frame.setVisible(true);
          }
      
          @Override
          public void actionPerformed(ActionEvent e) {
              toggleSecondFrameVisibility();
          }
      
      
          private static void toggleSecondFrameVisibility(){
              secondFrameVisible = !secondFrameVisible;
              childFrame.setVisible(secondFrameVisible);
          }
      
          public static void main(String[] args) {
              javax.swing.SwingUtilities.invokeLater(new Runnable() {
                  public void run() {
                      createAndShowGUI();
                  }
              });
          }
      }

      It looks like this - a main window ("FrameDemo") with a child window ("Child Window").
      When you click the "Toggle Visibility" button in the main window, the Child Window is set to invisible.

       

      Then create a Javascript project in TestComplete, add the following code to script Unit1:

      function debugme(){
        Aliases.javaw.WaitAliasChild("Child_Frame").Exists; // <-- set breakpoint here
        Aliases.javaw.WaitAliasChild("Child_Frame").Exists; // <-- set breakpoint here
        Aliases.javaw.WaitAliasChild("Child_Frame").Exists; // <-- set breakpoint here
        Aliases.javaw.WaitAliasChild("Child_Frame").Exists; // <-- set breakpoint here
      }
      1. Run the sample Java app
      2. Put a breakpoint on line 2 in the TestComplete IDE (The .Exists line)
      3. Right click the function -> run this routine
      4. F10 to step - no wait
      5. Click the "Toggle Visibility" button in the sample app to hide the child frame
      6. F10 to step - WAITS!!
      7. Click the "Toggle Visibility" button in the sample app to show the child frame
      8. F10 to step - no wait

       

      • rraghvani's avatar
        rraghvani
        Icon for Champion Level 3 rankChampion Level 3

        I'm not able to reproduce your issue. If I run the following code against a new project,

        function main()
        {
            Log.Message("Start");
            var mf = Aliases.java.WaitAliasChild("Main_Frame")
            if (mf.Exists) {
                Log.Message(mf.Exists);
                Log.Message(mf.Visible);
            }
            
            var cf = Aliases.java.WaitAliasChild("Child_Frame");
            if (cf.Exists) {
                Log.Message(cf.Exists);
                Log.Message(cf.Visible);
            }
            Log.Message("Finish");
        }

        the following output is shown,

        Main window visible and Child window visibleMain window visible and Child window invisible

        Notice the time differences, it's not waiting X number of seconds.

        What version of TC are you using?

        By the way, your instructions were perfect. Thanks!