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

"SilverlightApp app = ActiveBrowser.SilverlightApps()[0];" statement throws Exception

1 Answer 63 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Saurabh
Top achievements
Rank 1
Saurabh asked on 02 May 2012, 02:13 PM
Hi,


I am new to telerik and trying to learn Automation Framework.  Recently i tried customizing code for my AUT through C# in Telerik Test Studio.

To my surpsrise the statement :" SilverlightApp app = ActiveBrowser.SilverlightApps()[0];" in my code threw Exception given below :-

"

Failure Information: ~~~~~~~~~~~~~~~Exception thrown executing coded step: '[writing_CodedStep] : Navigate to : 'http://pxsnydmsapp001v.dts.dadcdigital.com/''.InnerException:System.ArgumentException: Index '0' is invalid. List contains only '0' apps at ArtOfTest.WebAii.Silverlight.SilverlightAppsList.get_Item(Int32 index)

"

I am unable to understand the cause of this : My AUT first shows login page where i am successfully able to dynamically identify UI Elements and input the value. After Login AUT opens silverlight Application page. Its there where i am unable to identify App itself.

Here is my code :

using Telerik.WebAii.Controls.Html;
using Telerik.WebAii.Controls.Xaml;
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

using ArtOfTest.Common.UnitTesting;
using ArtOfTest.WebAii.Core;
using ArtOfTest.WebAii.Controls.HtmlControls;
using ArtOfTest.WebAii.Controls.HtmlControls.HtmlAsserts;
using ArtOfTest.WebAii.Design;
using ArtOfTest.WebAii.Design.Execution;
using ArtOfTest.WebAii.ObjectModel;
using ArtOfTest.WebAii.Silverlight;
using ArtOfTest.WebAii.Silverlight.UI;

namespace Project_Saurabh
{

    //
    // You can add custom execution steps by simply
    // adding a void function and decorating it with the [CodedStep]
    // attribute to the test method.
    // Those steps will automatically show up in the test steps on save.
    //
    // The BaseWebAiiTest exposes all key objects that you can use
    // to access the current testcase context. [i.e. ActiveBrowser, Find ..etc]
    //
    // Data driven tests can use the Data[columnIndex] or Data["columnName"]
    // to access data for a specific data iteration.
    //
    // Example:
    //
    // [CodedStep("MyCustom Step Description")]
    // public void MyCustomStep()
    // {
    //        // Custom code goes here
    //      ActiveBrowser.NavigateTo("http://www.google.com");
    //
    //        // Or
    //        ActiveBrowser.NavigateTo(Data["url"]);
    // }
    //
       

    public class writing : BaseWebAiiTest
    {
       
       
       
        #region [ Dynamic Pages Reference ]

        private Pages _pages;

        /// <summary>
        /// Gets the Pages object that has references
        /// to all the elements, frames or regions
        /// in this project.
        /// </summary>
        public Pages Pages
        {
            get
            {
                if (_pages == null)
                {
                    _pages = new Pages(Manager.Current);
                }
                return _pages;
            }
        }

        #endregion
       
        // Add your test methods here...
   
        [CodedStep(@"Navigate to : "AUT")]
        public void writing_CodedStep()
        {
            // Navigate to : '"AUT"'
            string landingpage;
            // Create my own Settings object and then modify the defaults
            Settings mySettings = new Settings();
            mySettings.EnableSilverlight = true;
                        
            mySettings.DefaultBrowser = BrowserType.InternetExplorer;
            mySettings.ClientReadyTimeout = 60000;
              Manager.LaunchNewBrowser();
           
            // Use my Settings object to construct my Manager object
            Manager myManager = new Manager(mySettings);
            System.Threading.Thread.Sleep(5000);
            myManager.Start();
            myManager.LaunchNewBrowser();
           
            myManager.ActiveBrowser.NavigateTo("AUT");
                                                      
            Element mybtn = myManager.ActiveBrowser.Find.ByName("Login1$UserName");
            System.Threading.Thread.Sleep(2000);
            myManager.ActiveBrowser.Actions.SetText(mybtn,"username");
            System.Threading.Thread.Sleep(2000);
            Element mybtn1 = myManager.ActiveBrowser.Find.ByName("Login1$Password");
            System.Threading.Thread.Sleep(2000);
            myManager.ActiveBrowser.Actions.SetText(mybtn1,"password");
            System.Threading.Thread.Sleep(2000);
           
            Element mybtn2 = myManager.ActiveBrowser.Find.ByName("Login1$LoginButton");
            System.Threading.Thread.Sleep(2000);
            myManager.ActiveBrowser.Actions.Click(mybtn2);
            System.Threading.Thread.Sleep(2000);
           
            System.Threading.Thread.Sleep(60000);
           
          
            ActiveBrowser.RefreshDomTree();
           
            SilverlightApp app = ActiveBrowser.SilverlightApps()[0];    // THE LINE WHICH THROWS ERROR/EXCEPTION
            
           
        }
    
                   }
}




1 Answer, 1 is accepted

Sort by
0
Anthony
Telerik team
answered on 07 May 2012, 04:55 PM
Hello Saurabh,

First, I'm confused by your code implementation. You filed this post in the Telerik Testing Framework forum, however your code sample appears to be written within the coded step of a Test Studio test. Is that the case? If so, you are using several Framework-specific commands which aren't appropriate (nor needed) for a Test Studio test. See here for more information on the Framework and here for how to record a Web Test (Silverlight Web apps included) through Test Studio with no code required. 

As far as your Exception error is concerned, the first thing that comes to mind is that the SL app might reside within a frame. If so, you'll need to locate the frame first, and then the SL app within the frame. This is just speculation and without more information I won't be able to definitively say what's wrong.

It appears your app is private, so if you continue to have difficulty please provide a copy of the DOM at that stage of your test so we can examine why the SL app isn't properly located.

Greetings,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Saurabh
Top achievements
Rank 1
Answers by
Anthony
Telerik team
Share this question
or