How do you capture an open dropdown box in WPF

1 Answer 81 Views
Coded Steps WPF Testing
Terry
Top achievements
Rank 1
Iron
Terry asked on 28 Mar 2022, 02:46 PM

In a coded step, I am trying to open a drop down box, and capture the window with the dropdown open.

I have tried this, and I end up with just the Window without the combo box open.

timeFormatCombo.User.Click()
timeFormatCombo.Wait.ForNoMotion(500);
var dropDownCapture =  ActiveApplication.MainWindow.Capture();

Any suggestions on what to do?

1 Answer, 1 is accepted

Sort by
0
Plamen Mitrev
Telerik team
answered on 29 Mar 2022, 12:06 PM

Hi Terry,

You are right that the Capture() on MainWindow does not get the expanded dropdown window and I reproduced it on my end. It is working this way, because the dropdown is considered a separate window and Test Studio captures the state of the main window only. I would consider this a bug and I logged it in our public feedback portal on your behalf. Please vote and follow it to get notifications for its progress in the future.

As a workaround you can use the built-in common step to capture the whole desktop during execution. That will show the state of the application under test, including the dropdown.

I have also prepared sample code that captures the desktop and cuts it to the size of the application main window. Please check the code below and run it on your end.

        [CodedStep(@"New Coded Step")]
        public void WPFTest_CodedStep()
        {            
            toggleDropdown.User.Click();
            toggleDropdown.Wait.ForNoMotion(500);
 
            CaptureWindowFromDesktop(ActiveApplication.MainWindow.Window.Rectangle, @"C:\tempFolder\test2.jpg");
        }
        
        public void CaptureWindowFromDesktop(System.Drawing.Rectangle rect, string file)
        {
            var captureBmp = new Bitmap(rect.Width, rect.Height);
            using (var captureGraphic = Graphics.FromImage(captureBmp))
            {
                captureGraphic.CopyFromScreen(rect.X, rect.Y, 0, 0, captureBmp.Size);
                captureBmp.Save(file, ImageFormat.Jpeg);
            }
        }

I hope the above suggestions will help you automate this test scenario.

Regards,
Plamen Mitrev
Progress Telerik

Does UI testing really fit into CI/CD?

If you want to find out how to take advantage of continuous delivery pipelines, join our Test Studio webinar on Wednesday, April 6 at 11 am EST | 5 pm CET.

Terry
Top achievements
Rank 1
Iron
commented on 01 Apr 2022, 05:21 PM

Thankyou for your help.  I have used this method and it works beautifully!
Plamen Mitrev
Telerik team
commented on 04 Apr 2022, 09:01 AM

I am happy to hear that the workaround works for you. Thank you for trying it and sharing your feedback!
Tags
Coded Steps WPF Testing
Asked by
Terry
Top achievements
Rank 1
Iron
Answers by
Plamen Mitrev
Telerik team
Share this question
or