How to set the active browser

18 posts, 0 answers
  1. Flavia
    Flavia avatar
    6 posts
    Member since:
    Sep 2010

    Posted 05 Dec 2011 Link to this post

    Hi,

    I'm using webAii for test automation. In the following scenarion:
    1. Launch a browser and navigate to page1
    2. From page1, click a button which open page2 in a new browser window (not a modal popup or a new tab)
    3. With page2 opened, make a click inside page 1, so page1 is the active browser window
    4. Execute a javascript method on page1 (which is not available on page2)

    The test fails with "ExecuteCommand failed! InError set by the client. Client Error: System.InvalidOperationException: Javascript call 'myFunction' failed" because the active browser is the last opened - page2 (not page1 as it has the actual focus)

    If between step 3 and 4 i close the active browser (but this action is against my test case), the ActiveBrowser property points to page1.

    How can i set the ActiveBrowser to page1 without closing page2?

    Thank you,
    Flavia

  2. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 07 Dec 2011 Link to this post

    Hello Flavia,

    After page 2 is opened, try acting on page 1 with code like this:

    //Set focus to page 1 and perform actions.
    Manager.Browsers[0].Window.SetFocus();
    Manager.Browsers[0].NavigateTo("http://www.bing.com");
    Manager.Browsers[0].Find.ById<HtmlInputText>("sb_form_q").Text = "Telerik";
    Manager.Browsers[0].Find.ById<HtmlInputSubmit>("sb_form_go").Click();
     
    //Set focus to page 2, perform actions, and close.
    ActiveBrowser.Window.SetFocus();
    Find.ByAttributes<HtmlAnchor>("href=http://www.google.com").Click();
    ActiveBrowser.Close();


    While page 2 remains the ActiveBrowser, this code returns to and acts on the first browser instance opened through a zero-based index. The focus returns to page 2 and it's closed. Greetings,
    Anthony
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Flavia
    Flavia avatar
    6 posts
    Member since:
    Sep 2010

    Posted 09 Dec 2011 Link to this post

    Hi,

    Thanks for your reply, but what i need is:
    1. Have page2 open (not visible) while page1 is open (keyboard focus is on page1) 
    2. Invoke a javascript method on page1 (without closing page2)

    I wanted to try Manager.Browser[0].ExecuteCommand, this was not successful because i did not have enough information how to pass the method name and parameters in the WebAii (online) documentation.

    Can you please give more details how to access javascript on non active Browser[s]?

    Regards,
    Flavia
  4. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 09 Dec 2011 Link to this post

    Hello Flavia,

    See our group of articles on Invoking Javascript in code.

    The key is to define the elements on which you'll invoke JavaScript while page 1 is still the ActiveBrowser (before opening page 2):

    [TestMethod]
    public void InvokeJS()
    {
        Manager.LaunchNewBrowser();
        ActiveBrowser.NavigateTo("c:\\html\\javascript\\main.html");
         
        //Define the element on page 1 on which to invoke JavaScript
        HtmlInputText txt = Find.ByTagIndex<HtmlInputText>("input", 0);
         
        //Click the link to open page 2       
        Manager.SetNewBrowserTracking(true);
        Find.ById<HtmlAnchor>("bing").Click();
        Manager.WaitForNewBrowserConnect("http://www.bing.com", true, 3000)
        Manager.SetNewBrowserTracking(false);
     
        //Minimize page 2
        ActiveBrowser.Window.Minimize();
     
        //Set focus to page 1 and invoke OnFocus
        Manager.Browsers[0].Window.SetFocus();     
        txt.InvokeEvent(ScriptEventType.OnFocus);
     
     
        //Set focus to page 2, perform actions, and close
        ActiveBrowser.Window.SetFocus();
        Find.ById<HtmlInputText>("sb_form_q").Text = "Telerik";
        Find.ById<HtmlInputSubmit>("sb_form_go").Click();
        ActiveBrowser.Close();
    }


    All the best,
    Anthony
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Pankaj
    Pankaj avatar
    11 posts
    Member since:
    Apr 2012

    Posted 13 Sep 2012 Link to this post

    Hi Anthony,

    Does telerik support the browser opened in new tab?
    I want to open a link in new tab (not in new window) and want to identify some controls in the new tabbed window in IE.

    Does it support?

    Thanks,
    Pankaj
  6. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 13 Sep 2012 Link to this post

    Hello Pankaj,

    Test Studio does not support tabbed browsing. You must Configure Internet Explorer to open popups in a new window instead of a new tab.

    All the best,
    Plamen
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  7. Pankaj
    Pankaj avatar
    11 posts
    Member since:
    Apr 2012

    Posted 13 Sep 2012 Link to this post

    thanks Anthony


    Regards,
    Pankaj Kukkar
    Software Engineer
    Philips
  8. Pankaj
    Pankaj avatar
    11 posts
    Member since:
    Apr 2012

    Posted 26 Sep 2012 Link to this post

    Hi Anthony,

    Telerik framework is not able to recognize the new browser conenct after performing click action and handling the alert dialog.
    Below is the sample.
    manager.SetNewBrowserTracking(true);
    manager.DialogMonitor.Start();
    AlertDialog dlg = new AlertDialog(manager.ActiveBrowser, DialogButton.OK);
    manager.DialogMonitor.AddDialog(dlg);
    ONEEMSElements.GetInstance.ctrl_PortalLinkIncase.Click(true);

    manager.WaitForNewBrowserConnect("url", true, 120000);

    When i get the browser count, it always gives me 1 instead of 2 and i'm not able to get ahndle for new browser window by any other means
    Can you help me?
    Regards
    Sowjanya
  9. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 26 Sep 2012 Link to this post

    Hello Pankaj,

    This is a duplicate issue raised by your colleague Sowjanya in this forum post. We'll concentrate our efforts and address the issue there.

    Regards,
    Plamen
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  10. Pankaj
    Pankaj avatar
    11 posts
    Member since:
    Apr 2012

    Posted 27 Sep 2012 Link to this post

    Thanks Plamen :)

    Regards,
    Pankaj Kukkar
  11. Pankaj
    Pankaj avatar
    11 posts
    Member since:
    Apr 2012

    Posted 29 May 2013 Link to this post

    Hi,

    Do you have any certification program related to telerik testing framework or Test studio tool?

    PLease let me know if there is any.

    Thanks and Regards,
    Pankaj Kukkar
  12. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 30 May 2013 Link to this post

    Hello Pankaj,

    I am not sure what certification program you are referring to. Could please elaborate more on that? If you are getting certificate warnings when recording or executing a test, please refer to this article on how to register our certificate for HTTPS connections.

    Regards,
    Plamen
    Telerik
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  13. Tushar
    Tushar avatar
    4 posts
    Member since:
    Nov 2012

    Posted 27 Jan 2014 in reply to Anthony Link to this post

    Hi Anthony, 

    I have encountered a similar situation and on using the solution provided by you i am getting the below error.

    "ArtOfTest.WebAii.Core.Browser' does not contain a definition for 'Windows' and no extension method 'Windows' accepting a first argument of type 'ArtOfTest.WebAii.Core.Browser' could be found"

    I have even included Telerik.WebAii.Controls library. Can you tell me if i need to include another library?







  14. Tushar
    Tushar avatar
    4 posts
    Member since:
    Nov 2012

    Posted 27 Jan 2014 in reply to Tushar Link to this post

    My Bad. Its working :)

    However, on using the Manager.Browsers[0].NavigateTo("http://www.bing.com"); 
    Telerik is entering the URL on the same window (Page2)  instead of going to Page 1.

    Can you help?

    Thanks,
    Tushar
  15. Velin Koychev
    Admin
    Velin Koychev avatar
    88 posts

    Posted 30 Jan 2014 Link to this post

    Hi Tushar,

    Telerik is entering the URL on the same window (Page2)  instead of going to Page 1.

    I have to agree that this is quite strange issue. Unfortunately I was not able to reproduce it on my side - everything is working as . 

    What happens if you try the following line:
    Manager.Browsers[1].NavigateTo("http://www.bing.com"); 

    Please provide us with a copy of your test and if it is possible grant us access to your application so we can reproduce the issue on our end and give you a solution.

    Regards,
    Velin Koychev
    Telerik
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  16. Andy
    Andy avatar
    2 posts
    Member since:
    Mar 2012

    Posted 29 Jul 2014 Link to this post

    Hi Plamen,

    i have quite a similar problem and i dont know to to fix it.
    I'm using webAii for test automation. In the following scenarion:
    1. Launch a browser on  page1
    2. From page1, click a button which open a pop up page2 in a new browser window (the new popup url is generic guid)
    3. Do some verification steps on page two

    The issue is when re-running this test it will fail on navigating to the pop-up window due to a different url.
    How would i go about solving this.

    cheers
  17. Andy
    Andy avatar
    2 posts
    Member since:
    Mar 2012

    Posted 29 Jul 2014 in reply to Andy Link to this post

    Hi Plamen this is ok now i have find a way.
    I changed the properties for the " connect pop up step" to connect even when for url is partial.

    Thanks
  18. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 01 Aug 2014 Link to this post

    Hi Tushar,

    I am happy to hear that.

    If you need further assistance, please do not hesitate to contact us again.

    Regards,
    Boyan Boev
    Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainingss
     
Back to Top