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

GetBitmap sometimes gets a blank content

3 Answers 120 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
aplicaciones
Top achievements
Rank 1
aplicaciones asked on 10 Apr 2018, 08:05 AM

Hello,

I haven't found the same situation on the forum.

My scenario is the following one:

In a certain step of my web Automation Test, I need to capture what I am seeing on the web page. That's why I am using the GetBitmap() method.
Most of the times it works but sometimes, I don't know the reason, I get a blank content instead of what I am actually seeing. (Image attached)

Here is my code (is still a work in progress as I haven't made this work perfectly)

           System.Drawing.Bitmap browserImage = null;
            try
            {
                Manager.ActiveBrowser.RefreshDomTree();
                Manager.ActiveBrowser.WaitUntilReady();

                ActiveBrowser.Window.Show();
                Manager.ActiveBrowser.Window.WaitForVisibility(true, 5000);
                ActiveBrowser.Window.SetActive();
                ActiveBrowser.Window.SetFocus();

                //Operar sobre la Tabla para ver si con esto se fuerza que tenga el foco aquĆ­
                Pages.Atenea0.Table.Focus();
                Pages.Atenea0.Table.Click();

                ActiveBrowser.ContentWindow.Show();
                ActiveBrowser.ContentWindow.SetActive();
                ActiveBrowser.ContentWindow.SetFocus();


                browserImage = ActiveBrowser.ContentWindow.GetBitmap();

                if (browserImage == null)
                {
                    ActiveBrowser.Window.RefreshChildren();
                    ActiveBrowser.ContentWindow.Show();
                    ActiveBrowser.ContentWindow.SetActive();
                    ActiveBrowser.ContentWindow.SetFocus();
                    browserImage = ActiveBrowser.ContentWindow.GetBitmap();
                }
                if (browserImage == null)
                {

                   browserImage = ActiveBrowser.Capture();
                }

I am a little bit lost as I said most of the times works but it's not acceptable for my goal to have something that randomly fails.
I hope you can help me with this.

Regards,
Sebastian

3 Answers, 1 is accepted

Sort by
0
Ivaylo
Telerik team
answered on 13 Apr 2018, 08:32 AM
Hello Sebastian,

I was able to reproduce this behavior, however I am experiencing this only when executing in Internet Explorer, with other browsers such as Chrome or Firefox I am not getting this behavior. Could you please confirm this is working in Chrome and Firefox on your side as well?

I have logged this problem and you can follow the progress using this public link.

Thank you reporting this behavior.


Regards,
Ivaylo
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
0
aplicaciones
Top achievements
Rank 1
answered on 13 Apr 2018, 09:50 AM

Hello Ivaylo,

Unfortunately, I need to use IE. It's a constraint. So, even though it might work on other browsers it's not an option in my case.

On the other hand, I was able to sort this out (to capture an Image) Net Framework libraries.

Here I put some parts of my code that solve this:

//FoundElement is the element that I am intereted in  Capturing
 var foundElement = ActiveBrowser.WaitForElement(new HtmlFindExpression(findClauses), 4000, false);
                        if (foundElement != null)
                        {
                            foundElement.Focus();

                            captureBitmap = CapturarImagenDeElemento(foundElement);

                            if (captureBitmap != null)
                            {
                                IntegrarTasaEnSistema(sufijo, captureBitmap);
                            }
                        }
.....

//I use this piece of code instead of foundElement.Capture() or   ActiveBrowser.ContentWindow.GetBitmap();

 private static Bitmap CapturarImagenDeElemento(Element foundElement)
        {
            //Creating a Rectangle object which will  capture our Current Screen
            Rectangle captureRectangle = foundElement.GetRectangle();

            //Creating a new Bitmap object
            Bitmap captureBitmap = new Bitmap(captureRectangle.Width, captureRectangle.Height, PixelFormat.Format32bppArgb);

            //Creating a New Graphics Object
            Graphics captureGraphics = Graphics.FromImage(captureBitmap);

            // Copying Image from The Screen
            captureGraphics.CopyFromScreen(captureRectangle.Left, captureRectangle.Top, 0, 0, captureRectangle.Size);

            return captureBitmap;
        }


I hope that this could help you to solve the issue or at least to compare behaviors as the last method works fine.

Regards,
Sebastian

0
Ivaylo
Telerik team
answered on 13 Apr 2018, 02:34 PM
Hello Sebastian,

Thank you for your update. I am glad you figured it out. Furthermore your experience will help other customers, experiencing similar behavior.

Regards,
Ivaylo
Progress Telerik
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
Tags
General Discussions
Asked by
aplicaciones
Top achievements
Rank 1
Answers by
Ivaylo
Telerik team
aplicaciones
Top achievements
Rank 1
Share this question
or