Forum Discussion

fayrehouse's avatar
fayrehouse
Frequent Contributor
12 years ago

Currently foregrounded page

Folks,



Our website being tested has (as most sites do!) a number of links/buttons you can click on for various reasons.  Some of these load a different URL in the current page, some open a document (eg PDF), others open a new window, some cause some back end processing to begin (which MAY take several seconds) etc.



I have a function that clicks on the object, regardless of type etc (identifying the correct object by "meaningful" text identifier - which isn't ALWAYS contentText!) - and I need it to wait for the system to finish doing whatever. For the most part, all is well. Except for when a new window is produced.



Depending on the link, the for the new window can vary. This, together with the use of the above "click" function I described, I cannot do something like



Sys.Browser().Page("http://some.specific.url").Wait()

Sys.Browser().Refresh



And if I try something generic:



Sys.Browser().Page("*").Wait()

Sys.Browser().Refresh



This matches against the "parent" page, and decides there is nothing to wait for.



Can anyone advise of a way (non Browser specific, as I have to test across FF, IE, Chrome and Safari) of identifying the current foreground web page - and using that in the Sys.Browser().Page("SOMEURL").Wait() ??



Thanks



Steve





  • fayrehouse's avatar
    fayrehouse
    Frequent Contributor
    Just to add to this - I thought the "focused" property would be what I was seeking. To get around problems of object browser/spy somehow stealing focus, I tried the following code - clicking from one IE browser to the next every few seconds....




    {


      var PropArray = new Array("Focused", "ObjectType")


      var ValArray = new Array("true","BrowserWindow")


      while (1==1)


      {


        var browwin = Sys.Browser("iexplore").FindChild(PropArray, ValArray, 1, true)


        if (browwin.Exists)


          Log.Checkpoint(browwin.Caption)


        else


          Log.Warning("No focused browser window")


        aqUtils.Delay(5000,"Waiting 5s")


        Sys.Browser("iexplore").Refresh()  


        


      } 


    }



    The only think that got logged (repeatedly) was "No focused browser window". - ie, the "focused" property doesnt seem to know when a browser window is active/focused?



     

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Steve,


     


    You can check the Visible or VisibleOnScreen properties of the Page objects. Here is the example:




    //JScript


    function getVisiblePage()


    {


      var PropArray = new Array("Visible", "ObjectType");


      var ValuesArray = new Array(true, "Page");


     


      // Searches for the page


      var page = Sys.Browser("iexplore").Find(PropArray, ValuesArray, 1);


     


      // Processes the search results


      if(page.Exists)


        Log.Message("The following page is visible: " + page.LocationURL);


      


      return page;


    }



  • fayrehouse's avatar
    fayrehouse
    Frequent Contributor
    Hi Tanya,



    Unfortunately it seems that doesn't work in this case. If I have two browser windows, neither is maximised, and one partially overlapping the other, then both Visible and VisibleOnScreen are TRUE for both pages.



    If I line them both up so they are completely aligned and the same size, or of course if one is smaller than the other which is completely overlapping it - then VisibleOnScreen is FALSE for the hidden one. 



    But by default, the new window is opened the same size, partially offset from the original window - and as such, both windows have both visible settings TRUE



    NOW, that said - the above is in IE. If I repeat the test in Chrome then a new TAB is opened, rather than a window - and in this case, both Visible settings are TRUE/FALSE as you would expect. Also in this case, there is only ONE Sys.Browser("chrome").BrowserWindow object - whereas of course when IE opens new windows, there is a BrowserWindow object "per page". 



    If it helps, I can tell you that as part of my test I have a test start event that closes ALL browser windows first - so only the browser windows related to the test are open.



    As an aside, I've yet to see what happens in FF or Safari. I'm guessing FF will be in line with either IE or Chrome, and that's fine. Safari will probably go off and do something completely different ;-)



    One idea I had was Sys.Browser().FindAllChildren("ObjectType","BrowserWindow")

    then take the window with the highest ObjectIdentifier value, and link to the visible (and probably only) page belonging to this value - but its the "belonging" relationship I cannot work out!



    So in summary - multiple tabs is easily dealt with, as per your suggestion. multiple browser windows - not so easy - vislble and visibleonscreen don't help, and focused doesn't seem to work as one might expect. 









  • fayrehouse's avatar
    fayrehouse
    Frequent Contributor
    Hi Tanya,



    From what I've seen, Chrome, and FF default to opening the additional pages as Tabs, with IE opening in new pages - your fix above would make all three of these the same, and mean the "Visible" solution would work.



    My Safari installation has gone pop (even uninstall / reinstall doesnt help!) - so I can't comment on which way round Safari works - but I'm sure I can find a similar fix to make it behave the same too.... Although I'm hoping I can persuade the powers that be to drop support for Safari ;)



    So this could well be the way forward!



    Many thanks!
  • jorgesimoes1983's avatar
    jorgesimoes1983
    Regular Contributor
    I had a similar problem, so I always use only one window (using Tanya's instructions above).



    When I need to close the last window I run a little .bat script to kill IE, a start a fresh one:



    "killIE.bat"



    taskkill /f /im "iexplore.exe"

    start /MAX iexplore.exe





    In what concerns the waiting, you can always write a script to wait for a property (ObjectIdentifier or Text).