Forum Discussion

AlexBorelli's avatar
8 years ago

Failure to run test



I'm a problem to run tests. Sometimes this happend. I have a lot of test to access this menu.


procedure cargos_do_vendedor;
var vezes;
  for vezes := 1 to 4 do
    if not (Aliases.control.WaitAliasChild('Cargos', 1000).Exists) then
        Log.Message('Essa é a ' + IntToStr(vezes) + 'ª tentativa de acesso ao menu.')


How do I not occur error when access to the menu?

Thank you.

Alex Borelli

8 Replies

  • Your first screen capture shows it failing trying to click "2".


    Your second one shows a failure trying to click "1".




    So does it randomly fail? Sometimes on 1, sometimes on 2, sometimes not at all?


    In which case it's probably a timing/state problem. Which the "Menu item 1 is disabled" message would also suggest. ie. The menu is not quite ready to accept clicks at the point you are trying to click it.


    You are using indexes. Are 1 & 2 both on the first menu? Or do you want to click 1 on the first menu, and 2 on the sub-menu. The sub-menu may well be in a different menu object ....


    (Sub-menu's are sometime completely separate objects to their parent menu object which spawns them)

    • AlexBorelli's avatar

      The menu is unique. You do not have sub-menu. By the code to view.
      Sometimes failure. I have specific units to access the menu, not to have to write or to maintenance in the same code in different places.

      If it fails to run all tests. If you run the same individual test, then passes. Can I run 10 times and not fail, or run 5 times and fails.

      I put a "for" to try more than 1 to not be able to open the window. But this problem I passed you, I do not know how to solve.

      Use indices in the menu and submenu. I click on the menu 1 and 2 in the submenu.

      • Colin_McCrae's avatar
        Community Hero



        Given that description my guess is synchronisation/ready state issues.


        I can't see all your code, but I think you have it set up with a small function for each menu selection you want to make?


        Each one goes in, then drops straight into a loop that runs 9 times. Inside that loop you check if something exists, if that something does NOT exist, then you press CTRL+C (to open the menu?) then click option 1/2/whatever.


        However, there is nothing between those lines?


        You have:



        CLICK 1

        CLICK 2


        What might work better would be:



        <wait until menu is visible and ready - or timeout>

        {check the element you want exists in the menu - except you are using index numbers so probably wouldn't do this}

        CLICK 1

        <wait until the sub-menu is visible and ready - or timeout>

        {check the element you want is there - again ... index numbers so not for you}

        CLICK 2

        <wait until the object that clicking 2 appears - or timeout>


        ^^^ is about the best guess I can come up with without seeing the application, all the code, and how it fails.


        Intermittent failures like this are usually sync/state issues. And if you are waiting on objects or states, you should always have a timeout escape clause so you don't get stuck in an endless loop.


        Or they could be due to unreliable mapping of objects. (So I'm assuming your mappings are reliable)


        Not sure about your "unknown name" error? Support page for it:


        Not sure if it throws that if the object is not yet ready so the method is not yet available? Not one that's come up for me.


        Your other error is "menu item 1 is disabled". Which is more the type of error I'd expect if the menu is not fully ready when you try clicking it.


        Also, I suspect your loop is in the wrong place. You've put the whole thing inside the loop? What if it opens the menu, clicks 1, but fails on 2 (and doesn't stop due to that failure). If that happens, things will be in a different state second time round. You'll be pressing CTRL+C on a menu that's already open? What happens then? I can see that getting messy.


        If you want to put it in a loop you would better to loop over the menu a few times until it's ready, then go onto the selections.


        I have a single handler function for 3 or 4 different types of dropdown as a central shared function of my code. It takes in a locator to the control based on onscreen labels, the required selection items - never index numbers, and what to do with the selection - eg. find, click, right click, make sure it's gone, etc. It has TONS of checks and validations as it goes through. It has to - especially with 3 or 4 different types of dropdown to deal with. They're similar, but not the same so checks vary between them. To keep them reliable, automated tests often consist more of checks and validations than anything else. Especially if you are allowing user data to populate and drive your tests as you then have to account for people errors too ....