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

File Upload Dialog Box coding Issue.

6 Answers 249 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
tapan
Top achievements
Rank 1
tapan asked on 24 Aug 2011, 04:29 PM
Hi Team,

We are creating generic functions for Upload dialog box which is displayed to the user when he clicks the button e.g. Browse
  There are two problems which we are facing.

1. The button is of HTMLinputfile type and we are unable to click it, using below code.
     // myManager.ActiveBrowser.Frames[0].Find.ById<HtmlInputFile>(objID).Click();

2. Once the browse button is clicked manually the windows open dialog box is displayed.
We have kept the code in Debug mode (visual studio  c#) and Telerik app closes closes the dialog box automatically.
Again if we click the browse button the windows open dialog box is displayed, and once we start our debugging we are able to upload files successfully using the below code.
=============
            try
            {
                FileUploadDialog fileDialog = new FileUploadDialog(Manager.Current.ActiveBrowser, InputFile, DialogButton.OPEN, objID);
                Manager.Current.DialogMonitor.AddDialog(fileDialog);
                Manager.Current.DialogMonitor.Start();

                // Wait Until Dialog is Handled.
                fileDialog.WaitUntilHandled(50000);
                Manager.Current.DialogMonitor.Stop();
.............................................

Inputfile="test.jpg",
objid = Object ID or the windows dialog box header

FYI: This works fine with record and playback.

Regards
Tapan

6 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 25 Aug 2011, 01:51 PM
Hello Tapan,

For the first problem, I'll need some more info in order to properly diagnose the issue. What exactly happens when you execute the code? Is there an error displayed or it passes without error and without clicking the button?

As for the second problem, I you add and start the DialogMonitor after you click the button to start the upload. those lines must be before that the upload button is clicked or the dialog will not be properly handled, which is exactly the issue you are experiencing. Here is a working sample:
Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
ActiveBrowser.NavigateTo("http://encodable.com/uploaddemo/");
var x = new FileUploadDialog(ActiveBrowser, @"C:\source.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();

Please also check out this documentation article on "Handling FileUpload Dialogs" . 

Hope to here from you soon!  

Regards,
Plamen
the Telerik team
Vote for Telerik Test Studio at the Annual Automation Honors Voting!
0
Plamen
Telerik team
answered on 25 Aug 2011, 05:17 PM
Hi Tapan,

I apologize, the last line of the code posted below should be:
x.WaitUntilHandled(10000);

  
Regards,
Plamen
the Telerik team
Vote for Telerik Test Studio at the Annual Automation Honors Voting!
0
tapan
Top achievements
Rank 1
answered on 26 Aug 2011, 03:53 PM
Hi Plamem,

Thanks for your reply.
As per your suggestions we invoked the handler before the browser button (click operation), but we are still facing same issue.
We are still working on it and will give you an update on Monday 29th.

Hopefully it works, else I would be giving you more details screenshots, code etc for your insight.

Regards
Tapan
0
John
Top achievements
Rank 1
answered on 23 Apr 2014, 07:49 PM
I've also run into the same Issue. I copied the code provided into a new project. The result of that test is that a OpenFileDialog appears. It is not handled by the DialogMonitor, and will hang and timeout. I'm running on Microsoft Visual Studio 2012, Windows 7, .Net Framework 4.5, 64-bit Operating System

[TestMethod]
public void FileUploadDialog()
{
    Init();
    _manager.Settings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;
    //_manager.LaunchNewBrowser(BrowserType.FireFox);
    _manager.LaunchNewBrowser(BrowserType.InternetExplorer);
    Window brw = _manager.ActiveBrowser.Window;
    //brw.Maximize();
    _manager.ActiveBrowser.NavigateTo("http://encodable.com/uploaddemo/");
    _manager.ActiveBrowser.WaitUntilReady();
 
    var x = new ArtOfTest.WebAii.Win32.Dialogs.FileUploadDialog(_manager.ActiveBrowser, @"C:\dev\test.txt", DialogButton.OPEN);
 
    _manager.DialogMonitor.Start();
    _manager.DialogMonitor.AddDialog(x);
 
    HtmlInputFile choose = _manager.ActiveBrowser.Find.ById<HtmlInputFile>("uploadname1");
    choose.MouseClick(MouseClickType.LeftDoubleClick);
 
 
    x.WaitUntilHandled(10000);
}
0
John
Top achievements
Rank 1
answered on 23 Apr 2014, 07:52 PM
[TestMethod]
public void FileUploadDialog()
{
    Init();
    _manager.Settings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;
    _manager.LaunchNewBrowser(BrowserType.InternetExplorer);
    Window brw = _manager.ActiveBrowser.Window;
    _manager.ActiveBrowser.NavigateTo("http://encodable.com/uploaddemo/");
    _manager.ActiveBrowser.WaitUntilReady();
    var x = new ArtOfTest.WebAii.Win32.Dialogs.FileUploadDialog(_manager.ActiveBrowser, @"C:\dev\test.txt", DialogButton.OPEN);
    _manager.DialogMonitor.Start();
    _manager.DialogMonitor.AddDialog(x);
    HtmlInputFile choose = _manager.ActiveBrowser.Find.ById<HtmlInputFile>("uploadname1");
    choose.MouseClick(MouseClickType.LeftDoubleClick);
    x.WaitUntilHandled(10000);
}
0
Cody
Telerik team
answered on 28 Apr 2014, 07:35 PM
Hi John,

Your code looks about right, though I don't see your initialization or clean up code. I've attached a complete working project for you to follow as an example.

Regards,
Cody
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
Tags
General Discussions
Asked by
tapan
Top achievements
Rank 1
Answers by
Plamen
Telerik team
tapan
Top achievements
Rank 1
John
Top achievements
Rank 1
Cody
Telerik team
Share this question
or