Automatin file upload function using HtmlInputFile.Upload

11 posts, 0 answers
  1. Limu
    Limu avatar
    14 posts
    Member since:
    Oct 2010

    Posted 19 Oct 2010 Link to this post

    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

     

     

     

     

     

  2. Limu
    Limu avatar
    14 posts
    Member since:
    Oct 2010

    Posted 21 Oct 2010 Link to this post

    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

  3. Helen
    Admin
    Helen avatar
    1052 posts

    Posted 22 Oct 2010 Link to this post

    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
  4. Limu
    Limu avatar
    14 posts
    Member since:
    Oct 2010

    Posted 22 Oct 2010 Link to this post

    Hi Helen,

    I am using Internet Explorer 8.

    Thanks
    Shwetha
  5. Helen
    Admin
    Helen avatar
    1052 posts

    Posted 22 Oct 2010 Link to this post

    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
  6. Limu
    Limu avatar
    14 posts
    Member since:
    Oct 2010

    Posted 22 Oct 2010 Link to this post

    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
  7. Limu
    Limu avatar
    14 posts
    Member since:
    Oct 2010

    Posted 22 Oct 2010 Link to this post

     

     

    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

     

  8. Helen
    Admin
    Helen avatar
    1052 posts

    Posted 26 Oct 2010 Link to this post

    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
  9. liu
    liu avatar
    4 posts
    Member since:
    Oct 2010

    Posted 04 Nov 2010 Link to this post

    I have tried the code upstair, and it's work, thanks very much!
  10. Jing
    Jing avatar
    1 posts
    Member since:
    Jan 2014

    Posted 03 Apr 2014 in reply to Helen Link to this post

    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.
  11. Ivaylo
    Admin
    Ivaylo avatar
    750 posts

    Posted 08 Apr 2014 Link to this post

    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
     
Back to Top