GetBitmap sometimes gets a blank content

4 posts, 0 answers
  1. aplicaciones
    aplicaciones avatar
    34 posts
    Member since:
    Apr 2017

    Posted 10 Apr Link to this post

    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

  2. Ivaylo
    Admin
    Ivaylo avatar
    778 posts

    Posted 13 Apr Link to this post

    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
     
  3. aplicaciones
    aplicaciones avatar
    34 posts
    Member since:
    Apr 2017

    Posted 13 Apr in reply to Ivaylo Link to this post

    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) using .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

  4. Ivaylo
    Admin
    Ivaylo avatar
    778 posts

    Posted 13 Apr Link to this post

    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
     
Back to Top