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

JavaScript dialog cannot be handled after handled FileUpload dialog

15 Answers 188 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jeffery
Top achievements
Rank 1
Jeffery asked on 19 Mar 2012, 04:02 AM
Hi Telerik team,

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

Sort by
0
Jeffery
Top achievements
Rank 1
answered on 20 Mar 2012, 02:46 AM
Anyone can help?
0
Anthony
Telerik team
answered on 22 Mar 2012, 08:02 PM
Hello Jeffery,

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?

Greetings,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Ganga
Top achievements
Rank 1
answered on 26 Mar 2012, 11:26 PM

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


0
Jeffery
Top achievements
Rank 1
answered on 27 Mar 2012, 07:01 AM
Hi Anthony,

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



0
Asta
Top achievements
Rank 1
answered on 27 Mar 2012, 08:55 AM
After last framework update all test related to dialogs stopped working. It's good that i don't need now use fiddler to make tests work, but for tests i need a lot of maintaining now..
0
Accepted
Anthony
Telerik team
answered on 27 Mar 2012, 04:00 PM
Hello 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
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Jeffery
Top achievements
Rank 1
answered on 28 Mar 2012, 10:12 AM
Hi Anthony,

Thanks for your reply. It's working.

Regards,
Jeffery
0
Asta
Top achievements
Rank 1
answered on 29 Mar 2012, 11:54 AM
This is for upload

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".




0
Anthony
Telerik team
answered on 29 Mar 2012, 03:55 PM
Hello Asta,

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();
 
    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
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Asta
Top achievements
Rank 1
answered on 30 Mar 2012, 07:06 AM
My project is big and i don't want to share it here. I had error "Timed out waiting '33000' msec. for any dialog to be handled '1'". Those tests run on silverlight, not simple page whose have UI made with HTML.

My dialogs tests stopped working by downloading 2011.2.1413.0 version of testing framework
0
Anthony
Telerik team
answered on 30 Mar 2012, 05:47 PM
Hello Asta,

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?

Kind regards,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Asta
Top achievements
Rank 1
answered on 10 May 2012, 12:05 PM
I have tried everything that i found on internet... Nothing helps
0
Anthony
Telerik team
answered on 10 May 2012, 11:37 PM
Hello Asta,

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.

All the best,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Greg Schnider
Top achievements
Rank 1
answered on 17 May 2012, 12:15 AM
Is there a reason why "Manager and Dialog Monitor are both started and stopped in Main method:"?

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
0
Anthony
Telerik team
answered on 17 May 2012, 04:57 PM
Hello 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.

All the best,
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
Jeffery
Top achievements
Rank 1
Answers by
Jeffery
Top achievements
Rank 1
Anthony
Telerik team
Ganga
Top achievements
Rank 1
Asta
Top achievements
Rank 1
Greg Schnider
Top achievements
Rank 1
Share this question
or