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

Can not test RadWindow-popup

3 Answers 156 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Erik Lindahl
Top achievements
Rank 1
Erik Lindahl asked on 17 Aug 2010, 06:33 PM

From Telerik demo-page (http://demos.telerik.com/aspnet-ajax/window/examples/radopen/defaultcs.aspx) I copied the following code (basically two buttons, one opening the browser´s popup, the other opening a RadWindow-popup):

<telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="true">
            <Windows>
                <telerik:RadWindow
                    id="RadWindow1"
                    runat="server"
                    showcontentduringload="false"
                    width="400px"
                    height="400px"
                    title="Telerik RadWindow"
                    behaviors="Default">
                </telerik:RadWindow>
            </Windows>
            </telerik:RadWindowManager>
            <table style="width: 100%;">
                <tr>
                    <td id="DecoratedControlsContainer">

                        <script type="text/javascript">
                        //<![CDATA[
                            function openRadWin() {
                                radopen("http://www.telerik.com", "RadWindow1");
                            }

                            function openPopUp() {
                                window.open("http://www.telerik.com", "WindowPopup", "width=400px, height=400px, resizable");
                            }
                       
                        //]]>                                                                       
                        </script>
                        <button style="width: 150px; margin-bottom: 3px;"
                            onclick="openRadWin(); return false;" id="openrad">open RadWindow</button><br style="clear:both" /><br style="clear:both" />
                     </td>
                    <td style="width: 50px;">
                        &nbsp;</td>
                    <td style="vertical-align: top; border-left: 1px solid #cccccc; padding-left: 40px;">
                        <button style="width: 170px; margin-bottom: 3px;"
                            onclick="openPopUp(); return false;" id="openpopup">open browser's popup</button><br style="clear:both" /><br style="clear:both" />
                     </td>
                </tr>
            </table>
   
Then i created two webaii-tests:

      [TestMethod]
        public void OpenPopup()
        {
            Manager.LaunchNewBrowser(BrowserType.InternetExplorer);

            ActiveBrowser.NavigateTo("http://localhost:38518");

            Manager.SetNewBrowserTracking(true);
            Find.ById<HtmlButton>("openpopup").Click();
            Manager.WaitForNewBrowserConnect("http://www.telerik.com", true, 10000);
            Manager.SetNewBrowserTracking(false);
            Assert.AreEqual(2, Manager.Browsers.Count);
        }

        [TestMethod]
        public void OpenRad()
        {
            Manager.LaunchNewBrowser(BrowserType.InternetExplorer);

            ActiveBrowser.NavigateTo("http://localhost:38518");

            Manager.SetNewBrowserTracking(true);
            Find.ById<HtmlButton>("openrad").Click();
            Manager.WaitForNewBrowserConnect("http://www.telerik.com", true, 10000);
            Manager.SetNewBrowserTracking(false);
            Assert.AreEqual(2, Manager.Browsers.Count);

        }
Only the test OpenPopup passes.
The test OpenRad throws exception due to WaitforNewBrowserConnect times out.

Grateful for any help because I really need to be able to test RadWindow-popups.

//Erik Lindahl

3 Answers, 1 is accepted

Sort by
0
Petio Petkov
Telerik team
answered on 19 Aug 2010, 12:14 PM
Hello Erik Lindahl,

The main difference between RadWindow and browser's popup is that just like any other DHTML element, RadWindow exists only in the context of the page in which it is created. RadWindow wraps an Iframe, and the content is loaded in that iframe.
Please take a look at the code below, which illustrates how to test the RadWindow control.
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Telerik.WebAii.Controls.Html;
using ArtOfTest.WebAii.Core;
using ArtOfTest.WebAii.Controls.HtmlControls;
using ArtOfTest.WebAii.TestTemplates;
  
namespace WebAiiTests.QSF.Window
{
    /// <summary>
    /// Summary description for IsActive
    /// </summary>
    [TestClass]
    public class WindowSimpleTest : BaseTest
    {
        public WindowSimpleTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        private TestContext testContextInstance;
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }
        // Use TestInitialize to run code before running each test 
        [TestInitialize()]
        public void MyTestInitialize()
        {
            #region WebAii Initialization
  
            Settings settings = GetSettings();
            settings.DefaultBrowser = BrowserType.InternetExplorer;
            settings.RecycleBrowser = true;
            settings.BaseUrl = "http://demos.telerik.com/aspnet-ajax";
            settings.ClientReadyTimeout = 60000;
            settings.ExecuteCommandTimeout = 60000;
            settings.AnnotateExecution = true;
            settings.AnnotationMode = AnnotationMode.All;
  
            // Now call Initialize again with your updated settings object
            Initialize(settings, new TestContextWriteLine(this.TestContext.WriteLine));
  
            // Set the current test method. This is needed for WebAii to discover 
            // its custom TestAttributes set on methods and classes.
            // This method should always exist in [TestInitialize()] method.
            SetTestMethod(this, (string)TestContext.Properties["TestName"]);
  
            #endregion
        
  
  
        //Use ClassCleanup to run code after all tests in a class have run.
        [ClassCleanup()]
        public static void WindowClassCleanup()
        {
            ShutDown();
        }
  
        [TestMethod]
        public void OpenPopup()
        {
            Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
  
            ActiveBrowser.NavigateTo("/window/examples/radopen/defaultcs.aspx");
  
            Manager.SetNewBrowserTracking(true);
            Find.ByAttributes<HtmlButton>("onclick=~openPopUp").Click();
            Manager.WaitForNewBrowserConnect("http://www.telerik.com", true, 10000);
            Manager.SetNewBrowserTracking(false);
            Assert.AreEqual(2, Manager.Browsers.Count);
        }
  
        [TestMethod]
        public void OpenRad()
        {
            Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
  
            ActiveBrowser.NavigateTo("/window/examples/radopen/defaultcs.aspx");
  
            Manager.SetNewBrowserTracking(true);
            Find.ByAttributes<HtmlButton>("onclick=~openRadWin").Click();
            //Get a Reference to the RadWindow control
            RadWindow radWindow1 = Find.ById<RadWindow>("RadWindowWrapper_RadWindow1");
            //Get a Reference to the RadWindow's Iframe
            ArtOfTest.WebAii.Core.Browser radWindow1InnerFrame = ActiveBrowser.Frames["RadWindow1"];
            radWindow1InnerFrame.WaitUntilReady();
  
            Assert.AreEqual(false, radWindow1.IsClosed);
            radWindow1InnerFrame.RefreshDomTree();
            Assert.AreEqual("http://www.telerik.com/",radWindow1InnerFrame.Url);
        }
  
  
    }
}
Let us know if you have any other questions.

Kind regards,
Petio Petkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Erik Lindahl
Top achievements
Rank 1
answered on 20 Aug 2010, 09:52 AM
Thanks, now I know how to do.
But I guess the line

Manager.SetNewBrowserTracking(true);


isn't necessary in your testmethod openRad() above?

//Erik
0
Petio Petkov
Telerik team
answered on 23 Aug 2010, 12:20 PM
Hi Erik Lindahl,

Indeed, I forgot to remove this line from the test. You're right that you don't need it. Please delete it.

Sincerely yours,
Petio Petkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Erik Lindahl
Top achievements
Rank 1
Answers by
Petio Petkov
Telerik team
Erik Lindahl
Top achievements
Rank 1
Share this question
or