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

Automatin file upload function using HtmlInputFile.Upload

10 Answers 304 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Limu
Top achievements
Rank 1
Limu asked on 19 Oct 2010, 03:58 PM

Hi, I am trying to automate file upload function in our application. The application handles both silverlight drag drop upload and also normal file select dialog upload. I am trying to automate without using silverlight. The code is below.

HtmlInputFile fileUpload = ActiveBrowser.Find.ByName<HtmlInputFile>("documentFileInput");

 

 

Assert.IsTrue(fileUpload != null);

 

fileUpload.Upload("C:\\folder1\\folder2\\worddoc.docx, 6000");

 


When this code is executed, I see the upload dialog box appears but the file path is not typed in the text box on the dialog, and it closes itself and I get a timeout error at the last line.

Is there any other code that needs to be written here to handle the dialog box and write complete file path in there and to click open button?
Thanks

 

 

 

 

 

10 Answers, 1 is accepted

Sort by
0
Limu
Top achievements
Rank 1
answered on 21 Oct 2010, 03:23 PM
Hi Telierik
I am still working on the upload dialog handling. I am trying to use other code provided by a user. I am not finding ArtOfTest.WebAii. Win32.Window assembly in webAii framework version 2010.2.830.0 which I installed.
Also from the online help http://www.artoftest.com/support/webaii/topicsindex.aspx if I click on ArtOfTest.WebAii. Win32.Window it says "The resource you are looking for might have been moved or the name must be changed".
What is the assembly that need to be used to handle window and buttons?

This is the code I am trying to use

Window w = WindowManager.FindWindowRecursively(

 

IntPtr.Zero, "Upload", true, 1000);

 

 

w.SetFocus();

w.SetActive();

app.Desktop.KeyBoard.SendString(

 

 

"MyFilePath");

 

ArtOfTest.WebAii.Win32.

 

 

Button openButton = new ArtOfTest.WebAii.Win32.Button(w.Handle, "Open", true);

 

openButton.Click();


The error I get is: The type or namespace name 'Window' could not be found are you missing an assembly reference?

I am not able to use the assembly in version 2010.2.830.0

using

 

 

ArtOfTest.WebAii.Win32.Window;

Thanks

0
Helen
Telerik team
answered on 22 Oct 2010, 02:52 PM
Hello,

Which is the exact browser you are running the test against?

Regards,
Helen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Limu
Top achievements
Rank 1
answered on 22 Oct 2010, 02:57 PM
Hi Helen,

I am using Internet Explorer 8.

Thanks
Shwetha
0
Helen
Telerik team
answered on 22 Oct 2010, 03:14 PM
Hello,

Could you please send us a live url of the site using the Upload to examine it locally?

Regards,
Helen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Limu
Top achievements
Rank 1
answered on 22 Oct 2010, 03:51 PM
Helen,
The site is docs.com. You need to sign in through a facebook account. And you get the upload dialog when you click Add a doc-> Upload a doc.
I am testing on beta version of the site where only developers will have access to. But docs.com should be fine it has the same features. Also it works with both silverlight and non-silverlight. Right now I have the silverlight installed.

Thanks
Shwetha
0
Limu
Top achievements
Rank 1
answered on 22 Oct 2010, 04:19 PM

 

 

I also tried the below code. This time, it types the file name I am passing here. But it wont click the open button. After typing the file path and file name, the dialog closes itself without clicking OPEN.

FileUploadDialog
fDialog= new FileUploadDialog(Manager.Current.ActiveBrowser, "C:\\FilePath\\FileName.docx", DialogButton.OPEN);

 

 

 

Manager.Current.DialogMonitor.AddDialog(fDialog);

 

 

 

Manager.Current.DialogMonitor.Start();

 

 

 

 

 

 

HtmlInputFile fUpload= ActiveBrowser.Find.ByName<HtmlInputFile>("inputfile");

 

fUpload.Click();

fDialog.WaitUntilHandled();

 

 

Manager.Current.DialogMonitor.Stop();

Thanks
Shwetha

 

0
Helen
Telerik team
answered on 26 Oct 2010, 08:50 AM
Hi Shwetha,

Please try the following code:

Manager.DialogMonitor.AddDialog(new FileUploadDialog(ActiveBrowser, @"YOUR_PATH_TO_THE_DOCUMENT", DialogButton.OPEN, "Choose file to upload"));
Manager.DialogMonitor.Start();
Pages.SignInDocsForFacebook.DocumentFileInputFile.MouseClick();
ActiveBrowser.WaitUntilReady();

Note that the file upload dialog title may vary. In the above code it is "Choose file to upload".
Change it in your test if necessary.

Regards,
Helen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
liu
Top achievements
Rank 1
answered on 04 Nov 2010, 07:21 AM
I have tried the code upstair, and it's work, thanks very much!
0
Jing
Top achievements
Rank 1
answered on 03 Apr 2014, 02:14 PM
Hi, I wonder if this code also works when I test against Chrome? I had the same question when I tried to upload a file in the automation test.
0
Ivaylo
Telerik team
answered on 08 Apr 2014, 01:23 PM
Hello Jing,

Yes this should work in Chrome as well.

Regards,
Ivaylo
Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
Tags
General Discussions
Asked by
Limu
Top achievements
Rank 1
Answers by
Limu
Top achievements
Rank 1
Helen
Telerik team
liu
Top achievements
Rank 1
Jing
Top achievements
Rank 1
Ivaylo
Telerik team
Share this question
or