Forum Discussion

joehiatt's avatar
joehiatt
New Contributor
14 years ago

Issue converting Javascript to VBscript - "&&&&" to "and" operator not working.

I'm having some difficulty converting some Javascript that I use to check for a 64 bit OS. I keep getting the error message "An exception occurred in the "CheckOS" unit at line 8: Microsoft VBScript runtime error Object doesn't support this property or method: 'TestedApps.firefox" when I attempt to use it with an "if" statement.



I've included the VBscript I'm attempting to use along with the original working Javascript. Could someone please tell me if this is a flaw with my code or with Testcomplete? I am using version 8.70.727.7



VBscript:




Sub CheckOS()

'Check for Windows 64/32 bit and assign the correct path for IE and Firefox Tested Apps.





' Checks if OS is 64 bit and if FireFox Tested App Exists in TC. Then sets tested app path.

  if Sys.OsInfo.Windows64bit and TestedApps.firefox <> null then    

    TestedApps.firefox.Path = "C:\\Program Files (x86)\\Mozilla Firefox\\"

  elseIf TestedApps.iexplore <> null then

    TestedApps.firefox.Path = "C:\\Program Files\\Mozilla Firefox\\"

 

 '/* Checks if OS is 64 bit and if iexplore Tested App Exists in TC then sets TestedApp Path*/

   if Sys.OsInfo.Windows64bit & TestedApps.iexplore <> null then

    TestedApps.iexplore.Path = "C:\\Program Files (x86)\\internet explorer\\" 

   elseIf TestedApps.iexplore <> null then

    TestedApps.iexplore.Path = "C:\\Program Files\\internet explorer\\"   

    

      

'/* Checks if OS is 64 bit and if AcroRd32 Tested App Exists in TC then set TestedApp Path*/

  if Sys.OsInfo.Windows64bit & TestedApps.AcroRd32 <> null then

    TestedApps.AcroRd32.Path = "C:\\Program Files (x86)\\Adobe\\Reader 9.0\\Reader\\"

  elseIf TestedApps.AcroRd32 <> null then

    TestedApps.AcroRd32.Path = "C:\\Program Files\\Adobe\\Reader 9.0\\Reader\\"

    

end if   

'    

'/*Functions for testing that Path is correct. - Should remain commented out -*/ 

' TestedApps.iexplore.Run()

' TestedApps.firefox.Run()    

   



Javascript&colon;




/*Check for Windows 64/32 bit and assign 

the correct path for IE and Firefox Tested Apps*/

function CheckOS()

{

  /* Checks if OS is 64 bit and if firefox Tested App Exists in TC then sets

  TestedApp Path*/

  if (Sys.OsInfo.Windows64bit && TestedApps.firefox !=null) 

  {  

    TestedApps.firefox.Path = "C:\\Program Files (x86)\\Mozilla Firefox\\"; 

  } 

  else if (TestedApps.firefox !=null)  

  {  

    TestedApps.firefox.Path = "C:\\Program Files\\Mozilla Firefox\\";       

  }

  

   /* Checks if OS is 64 bit and if iexplore Tested App Exists in TC then sets

  TestedApp Path*/

   if (Sys.OsInfo.Windows64bit && TestedApps.iexplore !=null) 

  { 

    TestedApps.iexplore.Path = "C:\\Program Files (x86)\\internet explorer\\"; 

  } 

  else if (TestedApps.iexplore !=null)

  {  

    TestedApps.iexplore.Path = "C:\\Program Files\\internet explorer\\";      

  }

  

  /* Checks if OS is 64 bit and if AcroRd32 Tested App Exists in TC then sets

  TestedApp Path*/

  if (Sys.OsInfo.Windows64bit && TestedApps.AcroRd32 !=null)

  {

    TestedApps.AcroRd32.Path = "C:\\Program Files (x86)\\Adobe\\Reader 9.0\\Reader\\";

  }

  else if (TestedApps.AcroRd32 !=null)

  {

    TestedApps.AcroRd32.Path = "C:\\Program Files\\Adobe\\Reader 9.0\\Reader\\";

  }

   

/*Functions for testing that Path is correct. - 

Should remain commented out -*/ 

  //TestedApps.iexplore.Run();

  //TestedApps.firefox.Run();     

}













1 Reply

  • Hi Joseph,



    First of all, to check whether an application exists in TestedApps, you need to use TestedApps.Find:

     if it doesn't exist.



    Next, there's no need to escape backslashes in VBScript, because they aren't special characters. So, path strings should be simply like this: C:\Program Files (x86)\Mozilla Firefox\.



    You're also missing End If's after each If block.





    Finally, I'd recommend using the %ProgramFiles% environment variable in place of the hard-coded path to the Program Files folder. The benefit is that it will automatically resolve to C:\Program Files or C:\Program Files (x86) depending on the OS bitness. This way, the script will be simpler and neater. :)

    Sub CheckOS

      If TestedApps.Find("firefox") >= 0 Then

        TestedApps.firefox.Path = "%ProgramFiles%\Mozilla Firefox"

      End If



      If TestedApps.Find("iexplore") >= 0 Then

        TestedApps.iexplore.Path = "%ProgramFiles%\Internet Explorer"

      End If



      If TestedApps.Find("AcroRd32") >= 0 Then

        TestedApps.AcroRd32.Path = "%ProgramFiles%\Adobe\Reader 9.0\Reader"

      End If

    End Sub


    Or, using a With block and one-line If's:

    Sub CheckOS

      With TestedApps

        If .Find("firefox")  >= 0 Then .firefox.Path  = "%ProgramFiles%\Mozilla Firefox"

        If .Find("iexplore") >= 0 Then .iexplore.Path = "%ProgramFiles%\Internet Explorer"

        If .Find("AcroRd32") >= 0 Then .AcroRd32.Path = "%ProgramFiles%\Adobe\Reader 9.0\Reader"

      End With

    End Sub