Forum Discussion

lrbehmer's avatar
lrbehmer
Contributor
15 years ago

JScript Popup Window

I apologize in advance, but I haven't been able to find any information on this.



I'm trying to be able to create a generic popup window during a test, kind of like you would with Javascript on an html page, but we're using a compiled executable, not a web app.



I want to be able to create one whenever I need to in order to check variable values, etc.  So, I started with this code:

var alertWindow ;

alertWindow = window.confirm("My Text String") ;




When run, TestComplete stops the test and gives me this notification:

Micosoft JScript runtime error

'window' is undefined




What do I need to do to fix this up?  Is there a special class for this?



TIA.

9 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Check the help file for documentation concerning creating user forms to display messages for confirmation.
  • karkadil's avatar
    karkadil
    Valued Contributor
    User forms are too monstrous for this task.



    Try BuiltIn.ShowMessage("text")
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    DOH!  Forgot about "Builtin.ShowMessage".  I've always used standalone automation so I've never really had a need for script interaction.



    Thanks!
  • karkadil's avatar
    karkadil
    Valued Contributor
    Yeah, I completely agree that any messages/forms/etc. shouldn't be used in automation scripts, and for debug purposes debug mode should be used.
  • Thanks, guys!



    Both of these avenues are going to be useful.  It looks like I need to
    investigate user forms in order to display values of variables within
    the test.  I tried passing variable values to Builtin.ShowMessage() and it errored-out.
  • karkadil's avatar
    karkadil
    Valued Contributor
    Passing variables to ShowMessage() method shouldn't be a problem. The following VBScript example works fine




    Sub Main

      Dim textVar

      Dim intVar

      textVar = "My message"

      intVar = 15

      BuiltIn.ShowMessage textVar & ",  " & intVar

    End Sub
  • Weird.  Well, this is what I did using JScript:

        var appName = TestedApps.Items(0).ItemName ;

        BuiltIn.ShowMessage("My App Name: " & appName) ;




    Is there something I'm doing wrong?
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Change your code to



     var appName = TestedApps.Items(0).ItemName;

     BuiltIn.ShowMessage("My App Name: " + appName)




    Note the syntax difference in concatenating  string.  The & operator in JScript does a bit wise boolean comparison, not a string concatenation.  So, when I used &, I got a "0" in my string because the two strings ("My App Name" and the value of appName) were not equal.