Hello Admin,
I am testing a Silverlight application with .NET 4.0 Framework, We have a functionality like AttachSignature, Which Invokes windows open dialogue to attach the jpeg signature. This testing need to be automated using Telirk webaii Framework, I do not have any methods to test for this test case. Can you please help me with anything ….
7 Answers, 1 is accepted
It sounds like you want to do a File Upload. Please see this page under the "Handling FileUpload" section for a description and sample code to accomplish this.
Kind regards,
Anthony
the Telerik team
Have you looked at the new Online User Guide for Telerik Test Studio?

I have tried the option provided by you to capture the File Upload Test case using the following test code...but unfortunately the windows file upload dialogue is not recognised..I tried my level best to automate this test case...but i am missing some thing can you please help me to identify the error in the below code..if you could chat with me skype or go to meeting would be appriciated..
Find the code below::
public void FileUploadHandler()
{
//public Desktop _desktopObject;
try
{
// Add a FileUpload dialog to be monitored.
Manager.DialogMonitor.AddDialog(new FileUploadDialog(ActiveBrowser, @"C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg", DialogButton.OPEN));
// Given that there were no dialog attribute set, the manager will not start the monitoring.
// You need to invoke the monitoring
Manager.DialogMonitor.Start();
// just click it
Actions.Click(Find.ByName("Open"));
}
catch
{
}
}
Thanks,
Abi
Your code looks good; I think you are just missing the step to wait for the dialog to be handled. Check out my sample code:
Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
ActiveBrowser.NavigateTo(
"http://encodable.com/uploaddemo/"
);
var x =
new
FileUploadDialog(ActiveBrowser, @
"C:\test.txt"
, DialogButton.OPEN);
Manager.DialogMonitor.AddDialog(x);
Manager.DialogMonitor.Start();
Element e2 = Find.ById(
"uploadname1"
);
ActiveBrowser.Actions.Click(e2);
Element e3 = Find.ById(
"uploadbutton"
);
ActiveBrowser.Actions.Click(e3);
ActiveBrowser.WaitUntilReady();
Notice that after I click the button to actually upload the file, the "ActiveBrowser.WaitUntilReady(); line will not let the test continue until the upload completes. Without that line your test may attempt to continue (or close the browser if it's at the end of the test) and your dialog will not be properly handled.
Kind regards,
Anthony
the Telerik team

Antony,
First of all, I really thank you for giving tips on Windows Open Dialog handling Automation...I took time on this because i want to try different possibilities. But i have tried hard to nail down the solution. But for some reason the pop-up was not at all recognized by the desktop handler.
I have tried n number of possibilities, but I would not pate all of those, but I would paste the key sequence of my test case. Please ignore coding standards for now…I have just depicted it in example…let me know if you could help me fix this issue with this automation. …This testing is really critical to my QA process… Please Help…..
Code:
//ABI
[TestMethod]
public void SilverlightApplicationFileUploadExample1()
{
var settings = GetSettings();
settings.EnableSilverlight = true;
Initialize(settings, Console.WriteLine);
Manager.Settings.ExecutionDelay = 10;
Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
ActiveBrowser.NavigateTo("http://localhost/Web/FieldClaims.aspx");
Thread.Sleep(5000);
_silverlightApp = ActiveBrowser.SilverlightApps()[0];
_initalized = true;
var grd = _silverlightApp.Find.ByName("ClaimsListViewGrid").As<RadGridView>();
grd.Rows[2].Cells[1].User.Click();
var tabbtn = _silverlightApp.Find.ByName("AppraisalsTab").As<RadTabItem>();
tabbtn.User.Click(MouseClickType.LeftClick);
tabbtn.User.Click();
grd = _silverlightApp.Find.ByName("AppraisalListViewLayoutRoot").As<RadGridView>();
grd.Rows[0].Cells[10].User.Click();
var radbtn = _silverlightApp.Find.ByName("EditAppraisalViewAttachSignature").As<RadButton>();
radbtn.User.Click(MouseClickType.LeftClick);
radbtn.User.Click();
var btn = _silverlightApp.Find.ByName("AttachSignatureOKButton").As<Button>();
radbtn.User.Click(MouseClickType.LeftClick);
radbtn.User.Click();
var x = new FileUploadDialog(Manager.ActiveBrowser, @"C:\test.txt", DialogButton.OPEN);
Manager.DialogMonitor.AddDialog(x);
Manager.DialogMonitor.Start();
Manager.ActiveBrowser.Actions.Click(Find.ByName("Open")); //Code fails here not able to handle the dialogue
x.WaitUntilHandled(5000);
}
//ABI
Note:
I tried initiating “Element e” by “using ArtOfTest.Webaii;” assembly, but it is erroring for me, I am using ArtOfTest.Webaii 2010.3.1421 Version. that is the reason i have used other method to click on "Open" also note that my open dialog have the name just "Open" as the name of the Window insted of "Choose any file to upload" as the usual upload Name
for that reason i have tried the below option as well...
//ABI
[TestMethod]
public void SilverlightApplicationFileUploadExample3()
{
GenericDialog fileUploadDialog;
var settings = GetSettings();
settings.EnableSilverlight = true;
Initialize(settings, Console.WriteLine);
Manager.Settings.ExecutionDelay = 10;
Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
ActiveBrowser.NavigateTo("http://localhost/Web/FieldClaims.aspx");
Thread.Sleep(5000);
_silverlightApp = ActiveBrowser.SilverlightApps()[0];
_initalized = true;
var grd = _silverlightApp.Find.ByName("ClaimsListViewGrid").As<RadGridView>();
grd.Rows[2].Cells[1].User.Click();
var tabbtn = _silverlightApp.Find.ByName("AppraisalsTab").As<RadTabItem>();
tabbtn.User.Click(MouseClickType.LeftClick);
tabbtn.User.Click();
grd = _silverlightApp.Find.ByName("AppraisalListViewLayoutRoot").As<RadGridView>();
grd.Rows[0].Cells[10].User.Click();
var radbtn = _silverlightApp.Find.ByName("EditAppraisalViewAttachSignature").As<RadButton>();
radbtn.User.Click(MouseClickType.LeftClick);
radbtn.User.Click();
//File upload handler dialogue opens with "Open" tag not "Chose file to upload"
fileUploadDialog = new GenericDialog(ActiveBrowser, "Open", false);
fileUploadDialog.HandlerDelegate = new DialogHandlerDelegate(CustomAlertHandler);
Manager.DialogMonitor.AddDialog(fileUploadDialog);
Manager.DialogMonitor.Start();
// When This Button is clicked the Open Windows Dialogue Opens
var btn = _silverlightApp.Find.ByName("AttachSignatureOKButton").As<Button>();
radbtn.User.Click(MouseClickType.LeftClick);
radbtn.User.Click();
ActiveBrowser.WaitUntilReady();
fileUploadDialog.WaitUntilHandled(5000); //Code fails here not able to handle the dialogue
}
//ABI
//ABI
/// <summary>
/// Handle alert dialog by saving the dialog text and clicking the desired button.
/// </summary>
/// <param name="dialog">The dialog being monitored.</param>
private void CustomAlertHandler(IDialog dialog)
{
try
{
// Store the dialog title in the AlertDialogText property.
AlertDialogText = dialog.Window.GetText();
// Find the button to click.
GenericDialog genericDialog = dialog as GenericDialog;
Window buttonToClick = null;
if (genericDialog != null)
{
buttonToClick = WindowManager.FindWindowRecursively(genericDialog.Window.Handle,
"Open", false, 0);
}
// Click the button. If not found, then just close the dialog.
if (buttonToClick != null)
{
Manager.Desktop.Mouse.Click(MouseClickType.LeftClick, buttonToClick.Rectangle);
}
else
{
dialog.Window.Close();
}
// Wait for the dialog to disappear.
dialog.Window.WaitForVisibility(false, 1000);
}
catch
{
AlertDialogText = string.Empty;
}
}
//ABI
Let's use your first example as it most closely matches the sample code I provided you. You add and start the DialogMonitor after you click the link to start the upload. Those lines must be before that the upload link is clicked or the dialog will not be properly handled, which is exactly the issue you are experiencing.
Take a look at my sample again. I navigate to the page, start the upload dialog monitor, click the link to bring up the upload dialog, and then wait until the browser is in a ready (the upload is finished). You can actually copy and test my code directly as it was written against a public site (as long as "C:\test.txt" exists).
Greetings,
Anthony
the Telerik team
I just realized you are uploading in Silverlight and I provided you an HTML example. Please see below for sample code that handles an upload dialog (with a title of "Open") in a public Telerik Silverlight demo page.
Settings.Current.Web.EnableSilverlight =
true
;
Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
ActiveBrowser.NavigateTo(
"http://demos.telerik.com/silverlight/#Upload/FirstLook"
);
SilverlightApp slapp = ActiveBrowser.SilverlightApps()[0];
var y =
new
FileUploadDialog(ActiveBrowser, @
"c:\test.txt"
, DialogButton.OPEN,
"Open"
);
Manager.DialogMonitor.AddDialog(y);
Manager.DialogMonitor.Start();
slapp.FindName<Button>(
"BrowseButton"
).User.Click();
ActiveBrowser.WaitUntilReady();
slapp.FindName<Button>(
"UploadButton"
).User.Click();
Notice I still add and start my dialog monitoring before I click the "Browse" button. Once the file path is entered and the dialog is handled, the Framework waits until the browser is in the "Ready" state before clicking the "Upload" button on the page itself.
Regards,
Anthony
the Telerik team

Hi Antony,
I am now able to automate my File Upload Test Case…Thanks for your help…I paste my working code for others…so that someone can make use of the sequence if they happen to encounter the same issue… thanks one again…
//ABI
[TestMethod]
public void SilverlightApplicationFileUploadExample1()
{
var settings = GetSettings();
settings.EnableSilverlight = true;
Initialize(settings, Console.WriteLine);
Manager.Settings.ExecutionDelay = 10;
Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
ActiveBrowser.NavigateTo("http://localhost/Web/FieldClaims.aspx");
Thread.Sleep(5000);
_silverlightApp = ActiveBrowser.SilverlightApps()[0];
_initalized = true;
var grd = _silverlightApp.Find.ByName("ClaimsListViewGrid").As<RadGridView>();
grd.Rows[2].Cells[1].User.Click();
var tabbtn = _silverlightApp.Find.ByName("AppraisalsTab").As<RadTabItem>();
tabbtn.User.Click(MouseClickType.LeftClick);
tabbtn.User.Click();
grd = _silverlightApp.Find.ByName("AppraisalListViewLayoutRoot").As<RadGridView>();
grd.Rows[0].Cells[10].User.Click();
var radbtn = _silverlightApp.Find.ByName("EditAppraisalViewAttachSignature").As<RadButton>();
radbtn.User.Click(MouseClickType.LeftClick);
radbtn.User.Click();
var x = new FileUploadDialog(Manager.ActiveBrowser, @"C:\test.txt", DialogButton.OPEN,"Open");
Manager.DialogMonitor.AddDialog(x);
Manager.DialogMonitor.Start();
var btn = _silverlightApp.Find.ByName("AttachSignatureOKButton").As<Button>();
btn.User.Click(MouseClickType.LeftClick);
btn.User.Click();
Manager.ActiveBrowser.WaitUntilReady();
}
//ABI