This is a migrated thread and some comments may be shown as answers.

How to set the active browser

17 Answers 734 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Flavia
Top achievements
Rank 1
Flavia asked on 05 Dec 2011, 08:25 PM
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

17 Answers, 1 is accepted

Sort by
0
Anthony
Telerik team
answered on 07 Dec 2011, 11:40 PM
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.
0
Flavia
Top achievements
Rank 1
answered on 09 Dec 2011, 07:23 PM
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
0
Anthony
Telerik team
answered on 09 Dec 2011, 11:49 PM
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.
0
Pankaj
Top achievements
Rank 2
answered on 13 Sep 2012, 05:29 AM
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
0
Plamen
Telerik team
answered on 13 Sep 2012, 07:30 AM
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
0
Pankaj
Top achievements
Rank 2
answered on 13 Sep 2012, 09:01 AM
thanks Anthony


Regards,
Pankaj Kukkar
Software Engineer
Philips
0
Pankaj
Top achievements
Rank 2
answered on 26 Sep 2012, 06:42 AM
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
0
Plamen
Telerik team
answered on 26 Sep 2012, 10:22 AM
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
0
Pankaj
Top achievements
Rank 2
answered on 27 Sep 2012, 05:50 AM
Thanks Plamen :)

Regards,
Pankaj Kukkar
0
Pankaj
Top achievements
Rank 2
answered on 29 May 2013, 09:51 AM
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
0
Plamen
Telerik team
answered on 30 May 2013, 08:32 AM
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
0
Tushar
Top achievements
Rank 1
answered on 27 Jan 2014, 09:49 AM
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?







0
Tushar
Top achievements
Rank 1
answered on 27 Jan 2014, 10:55 AM
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
0
Velin Koychev
Telerik team
answered on 30 Jan 2014, 12:34 PM
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
0
Andy
Top achievements
Rank 1
answered on 29 Jul 2014, 03:02 PM
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
0
Andy
Top achievements
Rank 1
answered on 29 Jul 2014, 04:16 PM
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
0
Boyan Boev
Telerik team
answered on 01 Aug 2014, 07:49 AM
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
 
Tags
General Discussions
Asked by
Flavia
Top achievements
Rank 1
Answers by
Anthony
Telerik team
Flavia
Top achievements
Rank 1
Pankaj
Top achievements
Rank 2
Plamen
Telerik team
Tushar
Top achievements
Rank 1
Velin Koychev
Telerik team
Andy
Top achievements
Rank 1
Boyan Boev
Telerik team
Share this question
or