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

[Solved] Problems with file upload handling in Sharepoint 2007

4 Answers 32 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Raul Ribeiro
Top achievements
Rank 1
Raul Ribeiro asked on 21 Oct 2009, 01:01 PM
Greetings!

We are having a few problems using the file upload handling dialogs in Sharepoint 2007.

At a certain point in our tests, we need to upload a file into a document library. To do this, we have recorded the necessary steps
to press the "Upload" and "Browse" buttons and we have also added a file upload handling dialog.

The file upload handling dialog is configured to always insert a file path similar to this: "C:\DocTeste\Documento1.docx".

Unfortunately, these actions do not always work. Instead of inserting the configured file path, the file upload handling dialog seems
to "stutter" and insert only a fraction of the full path, or it duplicates the full path.

We have gathered a few screenshots detailing the sort of erratic behaviour that we are getting. It does not seem to be a problem with the
actual code, since it does work *sometimes* !

Below you will also find a sample of the file upload handling code (we have converted it into a NUnit test).

        public void uploadfile() 
        { 
            // Launch an instance of the browser 
            //Manager.LaunchNewBrowser(); 
            //Manager.Elements.ReturnElementProxyWhenNotFound = true; 
 
            // Handle 'FileUpload' dialog. 
            FileUploadDialog fileDialog = new FileUploadDialog(ActiveBrowser, 
 "C:\\DocTeste\\Documento1.docx",  
DialogButton.OPEN); 
            Manager.DialogMonitor.AddDialog(fileDialog); 
 
 
            // Start Dialog Monitoring 
            Manager.DialogMonitor.Start(); 
 
 
            // Click 'a_Zz19_UploadMenu' 
            HtmlAnchor a_Zz19_UploadMenu = Pages.OriginList.a_Zz19_UploadMenu; 
            a_Zz19_UploadMenu.Wait.ForExists(100000); 
            a_Zz19_UploadMenu.Click(false); 
 
 
            // Click 'input_File_Plac__InputFile' 
            HtmlInputFile input_File_Plac__InputFile = Pages.Upload_Document.input_File_Plac__InputFile; 
            input_File_Plac__InputFile.Wait.ForExists(100000); 
            if ((ActiveBrowser.BrowserType == BrowserType.FireFox)) 
            { 
                ActiveBrowser.Window.SetFocus(); 
                input_File_Plac__InputFile.ScrollToVisible(ScrollToVisibleType.ElementTopAtWindowTop); 
                input_File_Plac__InputFile.MouseClick(); 
            } 
            else 
            { 
                input_File_Plac__InputFile.Click(false); 
            } 
 
            // Wait Until Dialog is Handled. 
            fileDialog.WaitUntilHandled(5000); 
 
            //Remove dialog handler as mentioned by telerik 
            Manager.DialogMonitor.RemoveDialog(fileDialog);  
 
            // Click 'input_Button_Pl__BtnOK' 
            HtmlInputButton input_Button_Pl__BtnOK = Pages.Upload_Document.input_Button_Pl__BtnOK; 
            input_Button_Pl__BtnOK.Wait.ForExists(100000); 
            input_Button_Pl__BtnOK.Click(false); 
 
        } 


What is causing this erratic behaviour? Is it a framework problem?
What can we do to work around this problem? Since the file uploads sometimes fail, the whole tests fail...

Thank you very much for your attention,
André Silva.





4 Answers, 1 is accepted

Sort by
0
Missing User
answered on 21 Oct 2009, 10:09 PM
Hi André,

There maybe a timing issue involved with the typing of the path. You can try some customization for the text typing with a custom dialog handler that would look similar to this for the NUnit test:

public void uploadfile()
  
// Launch a browser instance        
Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
GenericDialog g = new GenericDialog(ActiveBrowser, "", false);
g.HandlerDelegate = this.HandleDialog;
if(ActiveBrowser.BrowserType == BrowserType.InternetExplorer)
g.Title = "Choose File";
else
g.Title = "File Upload";
Manager.DialogMonitor.AddDialog(g);
// Start Dialog Monitoring  
Manager.DialogMonitor.Start();
  
// Click 'a_Zz19_UploadMenu'  
HtmlAnchor a_Zz19_UploadMenu = Pages.OriginList.a_Zz19_UploadMenu;
a_Zz19_UploadMenu.Wait.ForExists(100000);
a_Zz19_UploadMenu.Click(false);
  
  
// Click 'input_File_Plac__InputFile'  
HtmlInputFile input_File_Plac__InputFile = Pages.Upload_Document.input_File_Plac__InputFile;
input_File_Plac__InputFile.Wait.ForExists(100000);
if ((ActiveBrowser.BrowserType == BrowserType.FireFox))
{
ActiveBrowser.Window.SetFocus();
input_File_Plac__InputFile.ScrollToVisible(ScrollToVisibleType.ElementTopAtWindowTop);
input_File_Plac__InputFile.MouseClick();
}
else
{
input_File_Plac__InputFile.Click(false);
}
  
// Click 'input_Button_Pl__BtnOK'  
HtmlInputButton input_Button_Pl__BtnOK = Pages.Upload_Document.input_Button_Pl__BtnOK;
input_Button_Pl__BtnOK.Wait.ForExists(100000);
input_Button_Pl__BtnOK.Click(false);
  
}
  
public void HandleDialog(IDialog dialog)
{
System.Threading.Thread.Sleep(1000);
Manager.Desktop.KeyBoard.SendString("MyDownloadPath");
System.Threading.Thread.Sleep(1000);
Manager.Desktop.KeyBoard.SendString("{ENTER}");
System.Threading.Thread.Sleep(1000);
Manager.DialogMonitor.RemoveDialog(dialog);
Manager.DialogMonitor.Stop();
}

The HandleDialog(IDialog dialog) method is where you would enter your download path and the Sleep(1000) is where you can customize and add pauses to slow down the test executuion. If you have further dialog handlers running after your upload, please adjust where the Manager.DialogMonitor.Stop(); line to run after they have all completed.

In your WebAii test, you can add a Custom Step to run before your navigation step that would look somthing similar to this:

[CodedStep("MyCustom Step Description")]
public void MyCustomStep()
{
GenericDialog g = new GenericDialog(ActiveBrowser, "", false);
g.HandlerDelegate = this.HandleDialog;
if (ActiveBrowser.BrowserType == BrowserType.InternetExplorer)
g.Title = "Choose File";
else
g.Title = "File Upload";
Manager.DialogMonitor.AddDialog(g);
Manager.DialogMonitor.Start();  
}
  
public void HandleDialog(IDialog dialog)
{
System.Threading.Thread.Sleep(1000);
Manager.Desktop.KeyBoard.SendString("MyDownloadPath");
System.Threading.Thread.Sleep(1000);
Manager.Desktop.KeyBoard.SendString("{ENTER}");
System.Threading.Thread.Sleep(1000);
Manager.DialogMonitor.RemoveDialog(dialog);
Manager.DialogMonitor.Stop();
}

Hope this helps and please let us know if you have any quesitons or problems with the code for you pages.

Kind regards,
Nelson Sin
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Missing User
answered on 23 Oct 2009, 12:06 AM
Hello again André,

After looking at the code I posted, I made a mistake in the first code block for the NUnit code in that I left the File Dialog Handler there when I merged my suggested solution with the Nunit code you posted. Sorry about the confusion there and it's been corrected in the code block.

Also, if the NUnit test runs to quickly after launching the Upload Dialog and fails, please add a g.WaitUntilHandled(); From the code it looks like it might be needed like this:

// Click 'input_File_Plac__InputFile'   
HtmlInputFile input_File_Plac__InputFile = Pages.Upload_Document.input_File_Plac__InputFile; 
input_File_Plac__InputFile.Wait.ForExists(100000); 
if ((ActiveBrowser.BrowserType == BrowserType.FireFox)) 
ActiveBrowser.Window.SetFocus(); 
input_File_Plac__InputFile.ScrollToVisible(ScrollToVisibleType.ElementTopAtWindowTop); 
input_File_Plac__InputFile.MouseClick(); 
else
input_File_Plac__InputFile.Click(false); 
  
g.WaitUntilHandled();

But since I am not able to verifiy on this end, please try moving that line to where it would be appropriate in your order of operations.

And we are looking to maybe add further tweaks to the dialog handlers to allow correction for timing issues on the user end for their particular machines and setups.

All the best,
Nelson
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Raul Ribeiro
Top achievements
Rank 1
answered on 28 Oct 2009, 04:03 PM

Greetings!

We have implemented your suggestions and the tests seem to be working :)
The file upload handling has been running without major problems.

Thank you for your attention,
André Silva.

0
Missing User
answered on 28 Oct 2009, 05:49 PM
Hello again Andre,

I'm glad to hear that this worked for you. Please let us know if you have any other questions or issues with this or anything else in WebUI.

Greetings,
Nelson
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
General Discussions
Asked by
Raul Ribeiro
Top achievements
Rank 1
Answers by
Missing User
Raul Ribeiro
Top achievements
Rank 1
Share this question
or