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

FileUploadDialog error

5 Answers 155 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Garry
Top achievements
Rank 1
Garry asked on 02 Mar 2011, 10:49 PM
I get the following errors when I try to use the below code. I am trying to Upload a file where the file name is Data Driven and the file path from the project. I have the recorded step still, but disabled in the test. If I can use the "fullPath" variable in the recorded step, that would work for me also.

c:\Documents and Settings\gpittman\My Documents\WebUI Test Studio Projects\PLA\Helper\Submissions\Edit_Upload_Document.aii.cs: Line 95: (CS0246) The type or namespace name 'FileUploadDialog' could not be found (are you missing a using directive or an assembly reference?)
c:\Documents and Settings\gpittman\My Documents\WebUI Test Studio Projects\PLA\Helper\Submissions\Edit_Upload_Document.aii.cs: Line 95: (CS0246) The type or namespace name 'FileUploadDialog' could not be found (are you missing a using directive or an assembly reference?)
c:\Documents and Settings\gpittman\My Documents\WebUI Test Studio Projects\PLA\Helper\Submissions\Edit_Upload_Document.aii.cs: Line 95: (CS0103) The name 'DialogButton' does not exist in the current context


using Telerik.WebAii.Controls.Html;
using Telerik.WebAii.Controls.Xaml;
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
 
using ArtOfTest.Common.UnitTesting;
using ArtOfTest.WebAii.Core;
using ArtOfTest.WebAii.Controls.HtmlControls;
using ArtOfTest.WebAii.Controls.HtmlControls.HtmlAsserts;
using ArtOfTest.WebAii.Design;
using ArtOfTest.WebAii.Design.Execution;
using ArtOfTest.WebAii.ObjectModel;
using ArtOfTest.WebAii.Silverlight;
using ArtOfTest.WebAii.Silverlight.UI;
 
namespace PLA2
{
 
    //
    // You can add custom execution steps by simply
    // adding a void function and decorating it with the [CodedStep]
    // attribute to the test method.
    // Those steps will automatically show up in the test steps on save.
    //
    // The BaseWebAiiTest exposes all key objects that you can use
    // to access the current testcase context. [i.e. ActiveBrowser, Find ..etc]
    //
    // Data driven tests can use the Data[columnIndex] or Data["columnName"]
    // to access data for a specific data iteration.
    //
    // Example:
    //
    // [CodedStep("MyCustom Step Description")]
    // public void MyCustomStep()
    // {
    //        // Custom code goes here
    //      ActiveBrowser.NavigateTo("http://www.google.com");
    //
    //        // Or
    //        ActiveBrowser.NavigateTo(Data["url"]);
    // }
    //
         
 
    public class Edit_Upload_Document : BaseWebAiiTest
    {
        #region [ Dynamic Pages Reference ]
 
        private Pages _pages;
 
        /// <summary>
        /// Gets the Pages object that has references
        /// to all the elements, frames or regions
        /// in this project.
        /// </summary>
        public Pages Pages
        {
            get
            {
                if (_pages == null)
                {
                    _pages = new Pages(Manager.Current);
                }
                return _pages;
            }
        }
 
        #endregion
         
        public static string Document {get; set;}
         
         
        // Add your test methods here...
     
        //[CodedStep(@"Submission_Document")]
        //public void Edit_Upload_Document_CodedStep()
        {
        //    string DocumentName = String.Concat("Submission_Documents\\", Data["SubmissionDocument"]);
        //    string fullPath = System.IO.Path.Combine(this.ExecutionContext.DeploymentDirectory, DocumentName);
             
        //    Log.WriteLine("fullPath: '" + fullPath + "'");
             
        //}
     
        [CodedStep(@"File Upload")]
        public void Edit_Upload_Document_FileUpload()
        {
            string DocumentName = String.Concat("Submission_Documents\\", Data["SubmissionDocument"]);
            string fullPath = System.IO.Path.Combine(this.ExecutionContext.DeploymentDirectory, DocumentName);
             
            Log.WriteLine("fullPath: '" + fullPath + "'");
             
            FileUploadDialog fDialog = new FileUploadDialog(ActiveBrowser, fullPath, 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();
             
        }
    
    }
}

5 Answers, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 02 Mar 2011, 11:33 PM
Hello Garry,

You are missing

using ArtOfTest.WebAii.Win32.Dialogs;


Greetings,
Cody
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Garry
Top achievements
Rank 1
answered on 03 Mar 2011, 02:14 AM
That worked. Most of the examples that I have found in the Forum are not working for the FileUploadDialog. It almost seems like Telerik does not see the Dialog window appear.

The recorded "Handle 'FileUpload' dialog works without any issues, I just need to make it Data Driven from a Coded step.
0
Konstantin Petkov
Telerik team
answered on 03 Mar 2011, 09:33 AM
Hi Garry,

I'm glad that worked for you. Please let us know if you need further assistance.

All the best,
Konstantin Petkov
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Garry
Top achievements
Rank 1
answered on 03 Mar 2011, 07:51 PM
I am still having some issues with the FileUploadDialog. It does not see the Dialog at first, but if I close the window and re-open it, Telerik will now see the window and work correctly. I have a Manual step right after this step so I am able to do this.

Additional info, this only happens on the first Iteration of the Dataset.

Another issue that I have noticed, the file path typed is not the data that should be there. I have confirmed this by writing to the logs the Path, then verifying the data which was uploaded.

string DocumentName = String.Concat("Submission_Documents\\", Data["SubmissionDocument"]);
string fullPath = System.IO.Path.Combine(this.ExecutionContext.DeploymentDirectory, DocumentName);
 
Log.WriteLine("fullPath: '" + fullPath + "'");
 
FileUploadDialog fileDialog = new FileUploadDialog(ActiveBrowser, fullPath, DialogButton.OPEN, "Choose File to Upload");
 
Manager.DialogMonitor.AddDialog(fileDialog);
 
Manager.DialogMonitor.Start();

I had the following lines before, but I have an issue with the Find.ByName throwing an exception. So I commented them out.

//HtmlInputFile fileUpload = ActiveBrowser.Find.ByName<HtmlInputFile>("fileinput");
//fileUpload.Click();

Thanks,
Garry
0
Cody
Telerik team
answered on 03 Mar 2011, 08:56 PM
Hi Garry,

With the coded changes you have made (commenting out the button click and probably the WaitUntilHandled step as well) I am imagining this could be a C# garbage collection issue. The haard I see with a coded step like this:

Copy Code
[CodedStep(@"File Upload")]
public void Edit_Upload_Document_FileUpload()
{
    string DocumentName = String.Concat("Submission_Documents\\", Data["SubmissionDocument"]);
    string fullPath = System.IO.Path.Combine(this.ExecutionContext.DeploymentDirectory, DocumentName);
 
    Log.WriteLine("fullPath: '" + fullPath + "'");
 
    FileUploadDialog fDialog = new FileUploadDialog(ActiveBrowser, fullPath, DialogButton.OPEN);
    Manager.Current.DialogMonitor.AddDialog(fDialog);
    Manager.Current.DialogMonitor.Start();
}

As soon as the coded step is complete, your fDialog variable goes out of context and becomes a candidate for automatic garbage collection by C#. If it does get reclaimed that naturally it won't work. If this is the construct you're trying to take, put your fDialog into a global/class variable outside of any method.

Other than that, it appears your approach should work reliably. Can you send us a test that repro's this behavior? Can we run it to study this issue and try to determine what is causing this problem? I have implemented upload dialogs in code before and have had great success getting them to run reliably fully automated.

 

All the best,
Cody
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
General Discussions
Asked by
Garry
Top achievements
Rank 1
Answers by
Cody
Telerik team
Garry
Top achievements
Rank 1
Konstantin Petkov
Telerik team
Share this question
or