Forum Discussion

jmcpeek's avatar
jmcpeek
Contributor
12 years ago

waitbrowser.exists not consistent


I'm trying to create a pretty straight-forward function that takes in a browser name against which to run a test, close the browser if it's open, and launch the browser. However when I run the code below, I get a different result each time. You'll see I have a check to see if the browser exists and if so, I log an event. Then after that I call a function that has the exact same IF that closes the browser if open. Yes, I know the call to close the browser should be in the IF, not after it, but there is a reason...



projectsuite.variables.browser = "IE" 


    if projectsuite.variables.browser = "IE" then


        browsername = """iexplore"""


    else


        browsername = """" & projectsuite.variables.browser & """"


    end if


 


    statement = "sys.waitbrowser("& browsername &")"


 


    if eval(statement).exists then


        log.event projectsuite.variables.browser & " is already open. Closing it and reopening..."


        


    end if


    


    call forceBrowserClose(statement)


    runstatement = "Browsers.Item("& browsername &")"


    Call eval(runstatement).Run()



I ran this exact chunk of code 10 times with IE open. 



  1. nothing happened. no event, no close/re-open of IE


  2. nothing happened. no event, no close/re-open of IE


  3. nothing happened. no event, no close/re-open of IE


  4. worked as expected, logged event and closed/re-opened IE


  5. closed/re-opened IE, but didn't log event


  6. closed/re-opened IE, but didn't log event


  7. nothing happened. no event, no close/re-open of IE


  8. nothing happened. no event, no close/re-open of IE


  9. worked as expected, logged event and closed/re-opened IE


  10. closed/re-opened IE, but didn't log event




I know the evals are odd, but it was the only way I could get it to work without an actual error.



Any ideas on why this might be happening?

2 Replies


  • Hi Joe,


     


    Does the following code work for you?




    projectsuite.variables.browser = "IE" 


    if projectsuite.variables.browser = "IE" then


        browsername = "iexplore"


    else


        browsername = projectsuite.variables.browser


    end if


     


    if Sys.WaitBrowser(browsername).Exists then


      'The browser is running


      sys.Browser(browsername).Close


      Browsers.Item(browsername).Run       


    end if




     

  • Tanya,



    Your code didn't help. The first 3 times I ran it, I got 3 different results. The first time, it closed IE, but didn't re-open it. The second time, it didn't close or re-open IE. The third time, it did what it was supposed to.



    I decided to simplify it a little and just changed the last block to this:




    if Sys.WaitBrowser(browsername).Exists then


      'The browser is running


      log.event "exists"


      'sys.Browser(browsername).Close


      'Browsers.Item(browsername).Run  


    else


      log.event "doesn't exist"


    end if





    I ran this 5 times and every time it logged "doesn't exist", even though IE was open the entire time. I then decided to restart TC. The next 5 times I ran it, it found IE every time. Do I need a sys.refresh or something at the start to help it along?



    I'll note that since this problem first came up, I have a new computer with a fresh install of IE10 and TC 9.31.