Forum Discussion

Oferv's avatar
Oferv
Super Contributor
13 years ago

Ho to get WPF submenu item state

Hi,



can someone please let me know how to get a WPF submenu object's state.i tried to use the two following options.none is working:



1.


Log["AppendFolder"]("Reset project")

Aliases["FusionDesktop"]["HwndSource_MainWindow"]["MainWindow"]["Grid"]["TabControl"]["Grid"]["DockPanel"]["WaitAliasChild"]("Menu",5000)

Aliases["FusionDesktop"]["HwndSource_MainWindow"]["MainWindow"]["Grid"]["TabControl"]["Grid"]["DockPanel"]["Menu"]["WPFMenu"]["Click"]("File");

//Moves the mouse cursor to the menu item specified and then simulates a single click.

  if(Aliases["FusionDesktop"]["WPFObject"]("HwndSource: PopupRoot", "")["WPFObject"]("PopupRoot", "", 1)["WPFObject"]("Decorator", "", 1)["WPFObject"]("NonLogicalAdornerDecorator", "", 1)["WPFObject"]("MenuItem", "_Reset Project", 4)["Enabled"] == "False")

    {

    Aliases["FusionDesktop"]["HwndSource_MainWindow"]["MainWindow"]["Grid"]["TabControl"]["Grid"]["DockPanel"]["WaitAliasChild"]("Menu",5000)

    Aliases["FusionDesktop"]["HwndSource_MainWindow"]["MainWindow"]["Grid"]["TabControl"]["Grid"]["DockPanel"]["Menu"]["WPFMenu"]["Click"]("File|Reset Project");

    }

  else

    LoadProject["Open_Project"]()

    ResetProject()  

  Log["PopLogFolder"]()

}


2.


var FusionDesktop, Window, MainMenu, Submenu, Item;

  // Obtains the Windows Notepad main menu 

  FusionDesktop = Sys["Process"]("FusionDesktop");

  Window = FusionDesktop["Window"]("gDoc Fusion", "*");

  MainMenu = Window["MainMenu"];





  // Obtains the View submenu 

  Submenu = MainMenu["Items"]("File")["SubMenu"];





  // Obtains the "Status Bar" menu item 

  Item = Submenu["Items"]("Reset project");





  // Checks whether the item is enabled 

  if (Item["Enabled"])

    Log["Message"]("The Status Bar menu item is enabled");

  else 

    Log["Message"]("The Status Bar menu item is disabled");


i'll be happy if someone can help me solve that out.



Thanks
  • Oferv's avatar
    Oferv
    Super Contributor
    sorry,ignore that




    // Checks whether the item is enabled 

      if (Item["Enabled"])

        Log["Message"]("The Status Bar menu item is enabled");

      else 

        Log["Message"]("The Status Bar menu item is disabled");


    it's an example from your website
  • Oferv's avatar
    Oferv
    Super Contributor
    OK,i got that out.this is the code i wrote.




    //USEUNIT LoadProject









    function ResetProject()

    {

    var FusionDesktop, Window, MainMenu, Submenu, Item;

      // Obtains the Windows Notepad main menu    

      FusionDesktop = Sys["Process"]("FusionDesktop");

      Window = Aliases["FusionDesktop"]["HwndSource_MainWindow"] //  FusionDesktop["HwndSource_MainWindow"]["MainWindow"]["Grid"]["TabControl"]["Grid"]["DockPanel"];

      MainMenu = Window["MainWindow"]["Grid"]["TabControl"]["Grid"]["DockPanel"]["Menu"]["WPFMenu"]





      // Obtains the View submenu 

      Submenu = MainMenu["Items"]("File")["SubMenu"]





      // Obtains the "Status Bar" menu item 

      Item = Submenu["Items"]("Reset project");





      // Checks whether the item is enabled 

      if (Item["Enabled"])

        Log["Message"]("The Status Bar menu item is enabled");

      else 

        Log["Message"]("The Status Bar menu item is disabled");


    but,now the bold line failed to get the correct value of Enabled.

    when adding watch to the Item object i can see that its Enabled value is True but, when using the object spy to pint the same object its Enabled value is false TC is not consistent.i've tried to refresh the Watch list by checking and unchecking the Item object but the Enabled value was still True which is not true.



    why is that happening?



    thanks
  • Oferv's avatar
    Oferv
    Super Contributor
    Please see attached file.



    under Watch list the Enabled is True and under the object spy the Enabled is False for the same object

    also(I think),it's position is not the same 3 here and 4 there



    FYI



    I'll be happy to know what is going on here



    thanks
  • AlexeyK's avatar
    AlexeyK
    SmartBear Alumni (Retired)

    Hi Ofer,


    I am guessing the Enabled properties you are seeing for the Reset Project item in the Object Spy window and the Watch panel are different.


    In the Object Spy, the Enabled property belongs to the Standard category. This means the Enabled property indicates the state of the underlying windowed object which the OS uses to draw the item on screen. This Enabled property is provided by TestComplete. Native .NET properties are listed in the .NET category. In the Watch List panel you see the .NET-native property of your object.


    Since the property names coincide, in the Object Spy TestComplete displays the Enabled property under the Standard category and puts the native property to the NativeClrObject namespace. In other words, in the Object Spy, you can reach the native property via the Standard | NativeClrObject item.


     

  • Oferv's avatar
    Oferv
    Super Contributor
    Hi Alex,



    thanks for the explanation,still need to figure out what you meant there :) but,you still haven't told me how my script which looks fine to me doesn't get the correct state of the submenu item.



    thanks,
  • Oferv's avatar
    Oferv
    Super Contributor
    ok Alex,

    I got what you said.

    but the - IsEnabled under Standard | NativeClrObject also doesn't reflect the true state of the object.

    it's always True!!!.why is that?



    Thanks
  • AlexeyK's avatar
    AlexeyK
    SmartBear Alumni (Retired)

    Ofer,


    The IsEnabled property returns the value that is specified in the component's property. So, I suppose that the property is "true" in the application. Could you please open the menu and check whether the item is disabled? (displayed in gray).


    Also, I'd suggest that your test open the submenu before checking the item state in your test. I don't know your application, but, perhaps, it enables or disables items before displaying the menu.

  • Oferv's avatar
    Oferv
    Super Contributor
    Alex,



    the item can have 2 states,one is enabled when a project is open and the second state is disabled(gray)when there's no project open.

    but,when using the Standard | NativeClrObject item Enabled property to get the property state i get True for both states so something is going wrong here.i also did what you've asked and clicked the File menu which Reset Project is its submenu in order to expose it to TC but that also didn't work.

    you guys actually have the application i'm testing,your friend downloaded it using FTP we shared with you.so,can you please take a look at the application and help me solve this one?



    thanks
  • Oferv's avatar
    Oferv
    Super Contributor
    Well Alex,



    i solved that one :).

    It seems like the problem was that i had to click the File menu in order to expose the sub-menu to TC.so now it can see its state.



    thanks for the help thou