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

FileUploadDialog doesn't always work

12 Answers 141 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 21 Feb 2012, 09:00 AM
Hi

The following code seems to work roughly 50% of the time. If I run this code 10 times it stops after the file upload dialog opens, it just hangs and doesn't do anything else.

I run this on an open screen
I don't touch the mouse or anything else that could interfere.

Any ideas??

            //Saves tmp image
            Bitmap image = currentTest.ActiveBrowser.Window.GetBitmap();
            image.Save(imagePath);

            currentTest.ActiveBrowser.Manager.DialogMonitor.Start();

            for (int i = 0; i < count; i++)
            {
                FileUploadDialog fileUp = new FileUploadDialog(currentTest.ActiveBrowser, imagePath, DialogButton.OPEN);
                currentTest.ActiveBrowser.Manager.DialogMonitor.AddDialog(fileUp);
                currentTest.ActiveBrowser.Find.ByExpression<HtmlInputFile>(attachFileInput).Click();
                fileUp.WaitUntilHandled(SharedValues.DefaultTimeout);
                currentTest.ActiveBrowser.Manager.DialogMonitor.RemoveDialog(fileUp);
            }

            currentTest.ActiveBrowser.Manager.DialogMonitor.Stop();

12 Answers, 1 is accepted

Sort by
0
Martin
Top achievements
Rank 1
answered on 21 Feb 2012, 09:33 AM
Additional info:

I'm running MSTEST and i just did an experiment.

Running this test alone or running it as the first test it fails about 50% of the time
Running it as the second test or just not the first one it seems to work every time.

Ideas?
0
Cody
Telerik team
answered on 21 Feb 2012, 05:30 PM
Hi Martin,

Instead of creating and destroying a new FileUploadDialog, try creating and resetting just one FileUploadDialog object like this:

//Saves tmp image
Bitmap image = currentTest.ActiveBrowser.Window.GetBitmap();
image.Save(imagePath);
 
currentTest.ActiveBrowser.Manager.DialogMonitor.Start();
FileUploadDialog fileUp = new FileUploadDialog(currentTest.ActiveBrowser, imagePath, DialogButton.OPEN);
currentTest.ActiveBrowser.Manager.DialogMonitor.AddDialog(fileUp);
 
for (int i = 0; i < count; i++)
{
    currentTest.ActiveBrowser.Find.ByExpression<HtmlInputFile>(attachFileInput).Click();
    fileUp.WaitUntilHandled(SharedValues.DefaultTimeout);
    fileUp.CurrentState = DialogCurrentState.NotActive;
    //currentTest.ActiveBrowser.Manager.DialogMonitor.RemoveDialog(fileUp);
}
 
currentTest.ActiveBrowser.Manager.DialogMonitor.Stop();

Regards,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Martin
Top achievements
Rank 1
answered on 22 Feb 2012, 08:12 AM
Hi

I tried what you suggested and it doesn't make a difference, here is some more info:

- Running the test as part of other tests where it's not the first seems to work
- Running in debug mode works every time
- When it fails it never throws an exception it just hangs and stops all other tests

So I'm still having exactly the same problem.
0
Cody
Telerik team
answered on 28 Feb 2012, 05:26 AM
Hi Martin,

Sorry for the delay getting back to you. I admit this should be easier, and I've filed a bug on this here, I did get this code working for me very reliably using IE9:

FileUploadDialog upDlg = new FileUploadDialog(ActiveBrowser, @"E:\Temp\configuration.php", DialogButton.OPEN);
Manager.DialogMonitor.AddDialog(upDlg);
HtmlInputFile fileUpload = ActiveBrowser.Find.ByName("upfile").As<HtmlInputFile>();
 
for (int i = 0; i < 10; i++)
{
    fileUpload.Click();
    upDlg.WaitUntilHandled(10000);
    Manager.DialogMonitor.RemoveDialog(upDlg);
    upDlg = new FileUploadDialog(ActiveBrowser, @"E:\Temp\configuration.php", DialogButton.OPEN);
    Manager.DialogMonitor.AddDialog(upDlg);
    System.Threading.Thread.Sleep(100);
}
Regards,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Martin
Top achievements
Rank 1
answered on 28 Feb 2012, 07:45 AM
Hi

It doesn't make a difference, it's still very unstable. Also we're seeing the same behavior on the other dialog handlers as well.

Our workaround right now is, don't run a test that uses a dialog as the first test then it seems to work.

Below is another code snippet that shows the same behavior:

_manager.DialogMonitor.AddDialog(ConfirmDialog.CreateConfirmDialog(currentTest.ActiveBrowser, confirm ? DialogButton.OK : DialogButton.CANCEL));
 
_manager.DialogMonitor.Start();
 
HtmlInputSubmit btnSendToApprove = currentTest.Find.ByExpression<HtmlInputSubmit>("tagname=input", "id=~btnSendtoApproval");
 
btnSendToApprove.Click();


Exactly the same happens:
Running first - Fails
Running alone - Fails
Running in Debug - Works
Running as second test - Works


NOTE:
We are running IE8 currently.
0
Cody
Telerik team
answered on 28 Feb 2012, 04:21 PM
Hello Martin,

I have tried to reproduce your exact symptom with no success so far. Can you send me a complete test project I can run on my machine to reproduce these symptoms you describe:
Running first - Fails
Running alone - Fails
Running in Debug - Works
Running as second test - Works 

All the best,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Martin
Top achievements
Rank 1
answered on 01 Mar 2012, 08:53 AM
Hi Cody

I can't send you the full project but I have created a new project and managed to reproduce the same behavior.

And I have narrowed it down a bit, it seems to be related to code coverage. Our test project is in the same solution as a unit test project which uses code coverage and it seems when I turn off code coverage Teleriks works fine but when it's on, dialog issues appear.

But how do i send you a private message?
0
Cody
Telerik team
answered on 01 Mar 2012, 03:52 PM
Hi Martin,

Is the file under 10MB? You can send it as an email attachment to support@telerik.com. Please reference ticket 514290 in the email so that it will be correctly directed to me.

Greetings,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Martin
Top achievements
Rank 1
answered on 05 Mar 2012, 03:20 PM
Hi Cody

Did you get the project? I sent it but wasn't sure if it got through the company firewall.
0
Cody
Telerik team
answered on 05 Mar 2012, 04:04 PM
Hi Martin,

Yes I just received it. Thank you! I haven't had any time yet to try it (since I just got into the office). I'll be working on it soon today.

Greetings,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Accepted
Cody
Telerik team
answered on 07 Mar 2012, 12:15 AM
Hi Martin,

Thanks for the project. I was able to reproduce the problem. I tried to figure out what is causing it with no success. I filed a bug on this here. Hopefully our developers can figure something out about this.

Regards,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Martin
Top achievements
Rank 1
answered on 07 Mar 2012, 07:14 AM
Thanks jep, it seems really strange and if you turn off code coverage it works which makes no sense to me :)

Ill monitor the bug process
Tags
General Discussions
Asked by
Martin
Top achievements
Rank 1
Answers by
Martin
Top achievements
Rank 1
Cody
Telerik team
Share this question
or