I write the following test case to test file upload and javascript dialog.
The current issue is the JavaScript dialog cannot be handled after handled FileUpload dialog.
public
static
void
Test()
{
Settings settings =
new
Settings();
settings.Web.DefaultBrowser = ArtOfTest.WebAii.Core.BrowserType.InternetExplorer;
settings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;
Manager manager =
new
Manager(settings);
manager.Start();
manager.LaunchNewBrowser();
manager.ActiveBrowser.NavigateTo(
"http://localhost:60444/ConduitGenericWebSite/Default.aspx"
);
FileUploadDialog uploadDialog =
new
FileUploadDialog(manager.ActiveBrowser,
string
.Empty, DialogButton.OPEN);
manager.DialogMonitor.AddDialog(uploadDialog);
// Setup dialog monitoring
ConfirmDialog confirmDialog = ConfirmDialog.CreateConfirmDialog(manager.ActiveBrowser, DialogButton.OK);
manager.DialogMonitor.AddDialog(confirmDialog);
ConfirmDialog confirmDialog1 = ConfirmDialog.CreateConfirmDialog(manager.ActiveBrowser, DialogButton.OK);
manager.DialogMonitor.AddDialog(confirmDialog1);
manager.DialogMonitor.Start();
// File upload test.
Element fileUpload = manager.ActiveBrowser.Find.ById(
"FileUpload"
);
(
new
HtmlInputFile(fileUpload)).Upload(@
"D:\test.txt"
, 30000);
Element btnUpload = manager.ActiveBrowser.Find.ById(
"btnUpload"
);
(
new
HtmlControl(btnUpload)).Click();
// Click 'Button'
Element confButton = manager.ActiveBrowser.Find.ById(
"lnkShowConfirmAndAlert"
);
(
new
HtmlControl(confButton)).Click();
// Wait until dialog handled
confirmDialog.WaitUntilHandled(10000);
confirmDialog.CurrentState = DialogCurrentState.NotActive;
System.Threading.Thread.Sleep(1000);
}
But if I change the sequence to handle the javaScript dialog firstly, and then handle File upload dialog, that will be OK.
public
static
void
Test()
{
Settings settings =
new
Settings();
settings.Web.DefaultBrowser = ArtOfTest.WebAii.Core.BrowserType.InternetExplorer;
settings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;
Manager manager =
new
Manager(settings);
manager.Start();
manager.LaunchNewBrowser();
manager.ActiveBrowser.NavigateTo(
"http://localhost:60444/ConduitGenericWebSite/Default.aspx"
);
FileUploadDialog uploadDialog =
new
FileUploadDialog(manager.ActiveBrowser,
string
.Empty, DialogButton.OPEN);
manager.DialogMonitor.AddDialog(uploadDialog);
// Setup dialog monitoring
ConfirmDialog confirmDialog = ConfirmDialog.CreateConfirmDialog(manager.ActiveBrowser, DialogButton.OK);
manager.DialogMonitor.AddDialog(confirmDialog);
ConfirmDialog confirmDialog1 = ConfirmDialog.CreateConfirmDialog(manager.ActiveBrowser, DialogButton.OK);
manager.DialogMonitor.AddDialog(confirmDialog1);
manager.DialogMonitor.Start();
// Click 'Button'
Element confButton = manager.ActiveBrowser.Find.ById(
"lnkShowConfirmAndAlert"
);
(
new
HtmlControl(confButton)).Click();
// Wait until dialog handled
confirmDialog.WaitUntilHandled(10000);
confirmDialog.CurrentState = DialogCurrentState.NotActive;
// File upload test.
Element fileUpload = manager.ActiveBrowser.Find.ById(
"FileUpload"
);
(
new
HtmlInputFile(fileUpload)).Upload(@
"D:\test.txt"
, 30000);
Element btnUpload = manager.ActiveBrowser.Find.ById(
"btnUpload"
);
(
new
HtmlControl(btnUpload)).Click();
System.Threading.Thread.Sleep(1000);
}
I'm confused. Please help.
Thanks very much.
Regards,
Jeffery
15 Answers, 1 is accepted

What is the actual sequence of dialogs in the browser? A screen recording and/or a public site demonstrating that would be useful. It's tough to discern that from the code alone.
Is it an issue to use the second approach you provided since that is working?
Anthony
the Telerik team
Test Studio Trainings

Hi Anthony,
Thanks for quick response.
The First approach sequence is not working for any of the web browsers (IE or Firefox).
The sequence order is not working; if execute in this order.
1) Upload the file (working)
2) Invoke the button to handle the alert dialog (not working)
The sequence order is working; if execute in this order.
1) Invoke the button to handle the alert dialog (Working)
2) Upload the file (Working)
Please note that, I will follow up with Jeffery to provide more information.
Thanks
Ganga S

Sorry for late reply.
Attachment is an sample code with a public site demonstrating. Please take as reference.
In the sample code, the working sequence is:
DialogTest();
FileUploadTest();
But if you change the sequence as following:
FileUploadTest();
DialogTest();
The DialogTest is not working anymore.
Please let me know if you want more information.
Regards,
Jeffery

Thank you for the sample project; it was extremely helpful. Here are the changes I made so that both tests succeeded no matter the order:
Manager and Dialog Monitor are both started and stopped in Main method:
static
void
Main(
string
[] args)
{
settings =
new
Settings();
settings.Web.DefaultBrowser = ArtOfTest.WebAii.Core.BrowserType.InternetExplorer;
settings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;
manager =
new
Manager(settings);
manager.Start();
manager.LaunchNewBrowser();
manager.DialogMonitor.Start();
//DialogTest();
FileUploadTest();
DialogTest();
manager.DialogMonitor.Stop();
manager.Dispose();
}
It's better to specifically wait until the dialogs are handled versus a fixed delay. I also found button.Click() to be more reliable than button.MouseClick():
public
static
void
DialogTest()
{
ConfirmDialog confirmDialog = ConfirmDialog.CreateConfirmDialog(manager.ActiveBrowser, DialogButton.OK);
manager.DialogMonitor.AddDialog(confirmDialog);
AlertDialog alertDialog = AlertDialog.CreateAlertDialog(manager.ActiveBrowser, DialogButton.OK);
manager.DialogMonitor.AddDialog(alertDialog);
// Click 'Button'
manager.ActiveBrowser.NavigateTo(
"http://www.javascripter.net/faq/confirm.htm"
);
HtmlInputButton button = manager.ActiveBrowser.Find.ByAttributes<HtmlInputButton>(
new
string
[1] {
"value=Try it now"
});
if
(button !=
null
)
{
button.Click();
}
//System.Threading.Thread.Sleep(3000);
confirmDialog.WaitUntilHandled(3000);
alertDialog.WaitUntilHandled(3000);
manager.DialogMonitor.RemoveDialog(confirmDialog);
manager.DialogMonitor.RemoveDialog(alertDialog);
}
And the upload test:
public
static
void
FileUploadTest()
{
manager.ActiveBrowser.NavigateTo(
"http://cgi-lib.berkeley.edu/ex/fup.html"
);
FileUploadDialog x =
new
FileUploadDialog(manager.ActiveBrowser, @
"C:\test.txt"
, DialogButton.OPEN);
manager.DialogMonitor.AddDialog(x);
HtmlInputFile input = manager.ActiveBrowser.Find.ByName<HtmlInputFile>(
"upfile"
);
//input.Upload(@"C:\test.txt", 30000);
input.MouseClick(MouseClickType.LeftDoubleClick);
x.WaitUntilHandled(10000);
Element btnUpload = manager.ActiveBrowser.Find.ByAttributes(
new
string
[1] {
"value=Press"
});
if
(btnUpload !=
null
)
{
(
new
HtmlControl(btnUpload)).Click();
}
manager.DialogMonitor.RemoveDialog(x);
}
@Asta
I'll need more information to diagnose your issue. A sample demonstration project as Jeffery provided is ideal.
Greetings,
Anthony
the Telerik team
Test Studio Trainings

Thanks for your reply. It's working.
Regards,
Jeffery

string cwd = Directory.GetCurrentDirectory();
string testFilesFolderPath = System.IO.Path.Combine(cwd, "TestFiles");
string testFilePath = System.IO.Path.Combine(testFilesFolderPath, fileName);
Assert.IsTrue(File.Exists(testFilePath), String.Format("Test file '{0}' not found.", testFilePath));
FileSecurity fSecurity = File.GetAccessControl(testFilePath);
fSecurity.ResetAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Allow));
fSecurity.ResetAccessRule(new FileSystemAccessRule("Users", FileSystemRights.FullControl, AccessControlType.Allow));
File.SetAccessControl(testFilePath, fSecurity);
FileUploadDialog fileUploadDlg = new FileUploadDialog(ActiveBrowser,
testFilePath,
DialogButton.OPEN, "Open");
Manager.Current.DialogMonitor.AddDialog(fileUploadDlg);
Manager.Current.DialogMonitor.Start();
selectFileButton.User.ClickCheckbox();
fileUploadDlg.WaitUntilHandled(Timeout);
Manager.Current.DialogMonitor.Stop();
WaitProgressBar();
This is for Generic dialog confirmation:
protected void WindowsDeleteConfirmationPopUpOK(TextBlock deleteButton)
{
var genericDialog = new GenericDialog(ActiveBrowser, "Delete Confirmation", true) {ButtonId = 1};
ActiveBrowser.Manager.DialogMonitor.AddDialog(genericDialog);
ActiveBrowser.Manager.DialogMonitor.Start();
deleteButton.User.ClickCheckbox();
genericDialog.WaitUntilHandled(Timeout);
ActiveBrowser.Manager.DialogMonitor.Stop();
WaitProgressBar();
}
It worked with version "2011.2.1117.0".
I don't see any obvious issues with the code. How have your dialog tests "stopped working?" What error do you receive. Please provide full code samples against a public site that I can run directly in my environment and reproduce your issue.
Here are working examples from my project:
[TestMethod]
public
void
HtmlUpload2()
{
Manager.Settings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;
Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
ActiveBrowser.NavigateTo(
"http://encodable.com/uploaddemo/"
);
FileUploadDialog x =
new
FileUploadDialog(ActiveBrowser, @
"C:\test.txt"
, DialogButton.OPEN);
Manager.DialogMonitor.Start();
Manager.DialogMonitor.AddDialog(x);
HtmlInputFile choose = Find.ById<HtmlInputFile>(
"uploadname1"
);
choose.MouseClick(MouseClickType.LeftDoubleClick);
x.WaitUntilHandled(10000);
ActiveBrowser.RefreshDomTree();
HtmlInputButton button = Find.ById<HtmlInputButton>(
"uploadbutton"
);
button.Click();
System.Threading.Thread.Sleep(3000);
Manager.DialogMonitor.Stop();
Manager.DialogMonitor.RemoveDialog(x);
}
[TestMethod]
public
void
HtmlGeneric()
{
Manager.Settings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;
Manager.LaunchNewBrowser();
ActiveBrowser.NavigateTo(
"http://www.w3schools.com/js/tryit.asp?filename=tryjs_confirm"
);
GenericDialog gd =
new
GenericDialog(ActiveBrowser,
"Message from webpage"
,
true
) { ButtonId = 1 };
AlertDialog ad = AlertDialog.CreateAlertDialog(ActiveBrowser, DialogButton.OK);
Manager.DialogMonitor.AddDialog(gd);
Manager.DialogMonitor.AddDialog(ad);
Manager.DialogMonitor.Start();
ArtOfTest.WebAii.Core.Browser frSub = ActiveBrowser.Frames[
"view"
];
HtmlInputButton show = frSub.Find.ByExpression<HtmlInputButton>(
"value=Show a confirm box"
);
show.Click();
Manager.DialogMonitor.RemoveDialog(gd);
Manager.DialogMonitor.RemoveDialog(ad);
}
Kind regards,
Anthony
the Telerik team
Test Studio Trainings

My dialogs tests stopped working by downloading 2011.2.1413.0 version of testing framework
I understand your concern with sharing the project. Please consider creating a new, small sample project containing one test against a public site that demonstrates the issue. If the issue is with dialog handling, then it shouldn't matter whether the test is written against a Silverlight or HTML page. A local reproduction is the only way for me to continue troubleshooting.
Did you try the samples I provided? Do they work or do you receive an error?
Anthony
the Telerik team
Test Studio Trainings

I am sorry but without a local reproduction I cannot diagnose your issue. Please reconsider providing sample test code against a public site that demonstrates the behavior.
Anthony
the Telerik team
Test Studio Trainings

I am seeing issues where I start the Dialog Monitor upon creation of of a ConfirmDialog, and then stop it after the WaitUntilHandled() is successful. In this case, I get a timeout exception when the dialog appears. However if I start the Dialog Monitor just after launching the browser, and then leave it running then the dialog is handled properly.
Greg
The Dialog Monitor must be running for any portion of the test when you expect one or more dialogs to appear. The sole purpose of the tests from the example in this thread is to handle dialogs, so organizationally and functionally it made sense to start the monitor at the beginning and stop it at the end.
Anthony
the Telerik team
Test Studio Trainings