Forum Discussion

Stub's avatar
Stub
Occasional Contributor
9 years ago

Handling potential alert boxes via WaitWindow or aliases?

So I'm learning how to use TC10 and doing some experimentation with writing my own scripts to find out what I can do. I've come across an issue handling sort-of-unexpected (but not entirely unexpected!) dialog boxes appearing. By recording scripts I have acquired TC script code that does the job but I wanted to know if I was doing this right.

 

I'm testing a Windows Desktop app and my example scenario is a File/SaveAs operation. If the save as filename already exists you get a prompt asking if you want to overwrite it. So the first run the save-as filename won't exist and hence no prompt will appear, but might thereafter. So I want to handle the prompt dialog appearing or not for a robust test.

 

I can test for this alert thus and press Yes to confirm the overwrite:

 

  if (myApp.dlgConfirmSaveAs.Exists)
    myApp.dlgConfirmSaveAs.Confirm_Save_As.CtrlNotifySink.btnYes.ClickButton();

 

But this results in a noticable delay while the tell-tale indicator says it's waiting a few seconds for dlgConfirmSaveAs.

 

I have found that I can also do this:

 

  if (Sys.Process("MyApp").WaitWindow("#32770", "Confirm Save As", 1, 500).Exists)
      myApp.dlgConfirmSaveAs.Confirm_Save_As.CtrlNotifySink.btnYes.ClickButton();

 

I don't really know where this "dlgConfirmSaveAs" came from or whether I can use that alias/namemapping (?) more directly than going via Sys.Process and using WaitWindow.

 

As mentioned I'm exploring options, learning as I go, and wondering about better techniques.

 

4 Replies

  • Stub's avatar
    Stub
    Occasional Contributor

    I now see I could use aqFile.Delete to remove the file so I never see the prompt, but I'm interested in how to handle alert message boxes in general. I'm just using the save/as operation as an example as that's where I've just solved it.

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    If you look at your name mapping, those two are probably part of the same branch.

     

    "Noticeable delay" is relative.  You're going to have to have some delays in places for TC to wait for a window or for data to load or like in this case, to see if a window pops up.  How long is it actually waiting?  A second or two likely won't matter in the long run.  You can control this delay time in a few ways, and you can also put a message to the indicator so you know why it's waiting and that it's not just broken.

    • Stub's avatar
      Stub
      Occasional Contributor

      You're not wrong, it's not that long a delay, 2s maybe. Just that I can control it in one way via Sys.Process so things move along, hence I was wondering if I was tackling the 'problem' in the right way given the two approaches I've found thus far.

       

      I haven't quite figured out the name mapping system yet I must admit.

       

      I like the idea of an indicator message though.