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
}
}
}