Forum Discussion

dyarwood's avatar
dyarwood
Contributor
11 years ago

Unexpected Error using If...Then function in keyword test

Hi,



I'm doing some web testing and I find the Internet Explorer doesn't always shut down cleanly at the end of my test.



So, I've looked on the forums and found a way to kill the process using sys.process("iexplore.exe").Terminate and have added it as the last step of my test in an If...Then loop



If...Then sys.process("iexplore.exe").Exists equals False

[do nothing]

ELSE

Run Code Snippet Sys.process("iexplore.exe").Terminate()



When I run my test this code loop is executed. I'm confused though - it throws an Error everytime the iexplore.exe process doesn't exist (the do nothing condition).



Why does it throw an error and make the test report that if failed?

9 Replies

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3
    i don't know if it will make a difference with the error but I would have written it more like this:



    If  sys.process("iexplore.exe").Exists equals True  Then

    Run Code Snippet Sys.process("iexplore.exe").Terminate()





    and left off the Else.
  • Thanks Marsha,



    I actually tried it that way also but still got the error.



    David
  • Marsha_R's avatar
    Marsha_R
    Champion Level 3
    Darn!  :)



    What does your code actually look like?  Are you scripting or using keyword tests?









  • Hi,



    It's a keyword test. I'm far too new for anything else ;)



    I've attached a new screenshot showing all the test code.



    David
  • Marsha_R's avatar
    Marsha_R
    Champion Level 3
    No problem.  I use keyword tests too.



    It sounds counterintuitive, but I think what is happening is that TC wants to find iexplore.exe to see if its Exists property is True and since it can't find it, there's an error.



    Assuming that's the problem, I'll see if I can come up with a suggestion for an alternative.
  • I think that's a possibility too, it has to find the process to evaulate it.



    Thanks for looking into it.



    David
  • Hi,



    I think I found a solution.



    Use "If Object" instead of "If...Then" when checking to see if a process Exists.



    I'm still not sure why If...Then fails, but If Object doesn't give an error.



    Hopefully this will be useful to someone else out there.



    David
  • maximojo's avatar
    maximojo
    Frequent Contributor
    Hi,



    When looking at your original example the "Else" part needs to be moved out to the same level as the "If", otherwise it won't execute.



    So in script the way you have it in your original keyword test example it would look like:



    if(blah)

    {

       // do stuff





      else // sytax error!

      {



      }

    }



    Cheers

    m
  • Try below code


    if sys.Browser("iexplore").Exists then



        sys.Browser.Terminate



    Else



       [Do Nothing - This section not at all needed]



    End If