Forum Discussion

arijken's avatar
arijken
Occasional Contributor
11 hours ago

Access Form opend with a menuitem

I iterate through submenus in javascript  and when I click a menuitem a Form opens 
On the open form I want to click a toolbar button
this is my script 
        activeForm = Sys.Desktop.ActiveWindow();
        var Toolbar = activeForm.FindChild('Name', "tbFuncties");
        Toolbar.ClickItem("bNew");
but the toolbar.Clickitem does not open the expected window

I'll get the correct activeForm, but not the Toolbar
any help will be appreciated 

9 Replies

  • arijken's avatar
    arijken
    Occasional Contributor

    So there is no way to click a random menu item en get access to the window opened?
    Does this mean that I have to map every menu item to the window object it opens? 
    I want a generic script that click a menu item and on the opened form I like to click some buttons It seems that my idea is not possible 

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

      If you know the Object Hierarchy of your application, as shown in the Object Browser. Then it's possible to get the object in question, without using Name Mappings

      The object obj.WinFormsObject("Form2"), is shown for the Form.

      You can use the property Exists, to check whether the Form object exists e.g. obj.WinFormsObject("Form2").Exists.

      The example codes I have provided, don't use name mappings, it's all object based.

  • arijken's avatar
    arijken
    Occasional Contributor

    Match is a Delphi application so I can access it by using namemapping

    I have access to my application because I can open a menu item

           var mainMenu = Aliases.Match.fMain.MainMenu;
            mainMenu.Click(menuPad);  <-- this opens a from in my application 

          activeForm = ??????    <- how do I get the window opened by clicking on the menu item?

       activeForm = Aliases.Match.fMain.ActiveWindow(); does not work

    My question is still how do I get access to the form that is opened AFTER I click a Menu item?

  • arijken's avatar
    arijken
    Occasional Contributor

    My application is called Match.

     When I try activeForm = Aliases.Match.ActiveWindow(); and try to find the name of the active window I get "Non-existent object"

    when I use sys.Desktop.activewindow I get the correct name of the widow that is open. 

    because I don't know the name of the window that should be open when I click a menu item I cannot use the name to get the correct active window  

    My problem is that after I click a menu item I want to access  to the opened window so in your example the window that is open after wndNotepad.MainMenu.Click("File|Open...");
    I hope this explains my problem better. 

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

      You should be accessing your application using the Process method like so,

      function Example()
      {
        var match = Sys.Process("match");
        var wndMatch = match.Window("Match");
        
        match.MainMenu.Click("File|Open...");
      }

      You need to ensure that your have access to your application first, before attempting to interact with it. 

      Notepad is visible in Object Browser, and it can be accessed via Sys.Process("Notepad")

       

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

    You seem to be referencing the Desktop and not your Application Under Test. 

    Here's example code in accessing Notepad, which is already opened and visible in the Object Browser of TC.

    function Example()
    {
      var notepad = Sys.Process("notepad");
      var wndNotepad = notepad.Window("Notepad");
    
      // Open a file in Notepad
      wndNotepad.MainMenu.Click("File|Open...");
    }

     

    • arijken's avatar
      arijken
      Occasional Contributor

      I know how to open the menu item. When I click on the menu item a window opens. 

      The window contains a grid.  In that window I need to click toolbar buttons which opens a window for editing values 

      I got 3 buttons I want to test
      bNew -> Opens a input form and I Like to add some data en and click the OK button on the form which saves the input

      bEdit -> Opens the same window with data. I want to modify some data and click the OK button on the form 

      bDelete -> Delete the selected row in the grid

      I don't get input window when running my script

      Close the window with the grid and go the the next menu item. 

       

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

        You need to access your Application Under Test rather than the Desktop (unless your test specifically involves the Desktop).

        I have provided sample code showing how to access the application under test using Notepad as an example, since I don’t know the name of your actual application.