Ejemplo n.º 1
0
        public void CaptureScreenshot_WhenBitmapIsNotNull_CapturesScreenshotIntoProvidedBitmap()
        {
            var parameters = new CaptureParameters()
            {
                Zoom = 0.25
            };

            using (var grabber = new ScreenGrabber(parameters))
            {
                using (Bitmap bitmap = new Bitmap(grabber.ScreenshotWidth, grabber.ScreenshotHeight))
                {
                    if (ScreenGrabber.CanCaptureScreenshot())
                    {
                        Bitmap returnedBitmap = grabber.CaptureScreenshot(bitmap);
                        TestLog.EmbedImage("Screenshot with 0.25x zoom", bitmap);

                        Assert.AreSame(bitmap, returnedBitmap);
                    }
                    else
                    {
                        Assert.Throws <ScreenshotNotAvailableException>(() => grabber.CaptureScreenshot(bitmap),
                                                                        "CanCaptureScreenshot returned false so expected an exception to be thrown.");
                    }
                }
            }
        }
 private void LogSourceImage()
 {
     if (locator.Contains("image"))
     {
         string nameOfImage = locator.Split(':')[1].Trim(' ').Trim(')').Trim('"').Replace("/", "\\");
         string pathToImage = Config.SuitePath + "\\Images\\" + nameOfImage;
         if (Directory.Exists(pathToImage))
         {
             TestLog.Failures.WriteLine("Below element collection was not found on device screen - refer to attached screenshot.");
             TestLog.Failures.WriteLine("Note: screenshot will not appear if error was within Teardown.");
             foreach (var file in Directory.GetFiles(pathToImage, "*.png"))
             {
                 TestLog.Failures.EmbedImage(null, Image.FromFile(file));
                 TestLog.EmbedImage(null, Image.FromFile(file));
             }
         }
         else
         {
             pathToImage += ".png";
             TestLog.Failures.WriteLine("Below element was not found on device screen - refer to attached screenshot.");
             TestLog.Failures.WriteLine("Note: screenshot will not appear if error was within Teardown.");
             TestLog.Failures.EmbedImage(null, Image.FromFile(pathToImage));
             TestLog.EmbedImage(null, Image.FromFile(pathToImage));
         }
     }
 }
Ejemplo n.º 3
0
        public void CaptureScreenshot_WhenBitmapIsNullAndZoomed_CapturesScaledScreenshotIntoNewBitmap()
        {
            var parameters = new CaptureParameters()
            {
                Zoom = 0.25
            };

            using (var grabber = new ScreenGrabber(parameters))
            {
                if (ScreenGrabber.CanCaptureScreenshot())
                {
                    using (Bitmap bitmap = grabber.CaptureScreenshot(null))
                    {
                        TestLog.EmbedImage("Screenshot with 0.25x zoom", bitmap);

                        Assert.Multiple(() =>
                        {
                            Assert.AreApproximatelyEqual(ScreenGrabber.GetScreenSize().Width / 2,
                                                         grabber.ScreenshotWidth, 1);
                            Assert.AreApproximatelyEqual(ScreenGrabber.GetScreenSize().Height / 2,
                                                         grabber.ScreenshotHeight, 1);
                            Assert.AreEqual(grabber.ScreenshotWidth, bitmap.Width);
                            Assert.AreEqual(grabber.ScreenshotHeight, bitmap.Height);
                        });
                    }
                }
                else
                {
                    Assert.Throws <ScreenshotNotAvailableException>(() => grabber.CaptureScreenshot(null),
                                                                    "CanCaptureScreenshot returned false so expected an exception to be thrown.");
                }
            }
        }
Ejemplo n.º 4
0
        public void EmbeddedResources()
        {
            TestLog.Write("Embedded image:");
            TestLog.EmbedImage("Image", Resources.MbUnitLogo);

            TestLog.Write("Embedded plain text:");
            TestLog.EmbedPlainText("Plain Text", "This is some plain text.\nLalalala...\n\tIndented with TAB.\nThis should all appear to be preformatted.");

            TestLog.Write("Embedded XML:");
            TestLog.EmbedXml("XML", "<life><universe><everything>42</everything></universe></life>");

            TestLog.Write("Embedded XHTML:");
            TestLog.EmbedXHtml("XHtml", "<p>Some <b>XHTML</b> markup.<br/>With a line break.</p>");

            TestLog.Write("Embedded HTML:");
            TestLog.EmbedHtml("Html", "<p>Some <b>HTML</b> markup.<br>With a line break.</p>");

            TestLog.Write("Embedded binary data:");
            TestLog.Embed(new BinaryAttachment("Binary", "application/octet-stream", new byte[] { 67, 65, 66, 66, 65, 71, 69 }));

            TestLog.Write("Embedded video:");
            TestLog.EmbedVideo("Video", video);

            TestLog.Write("The same embedded image as above:");
            TestLog.EmbedExisting("Image");
        }
Ejemplo n.º 5
0
        public void Screenshot_WithCaptureParametersIncludingZoomFactor_CapturesZoomedScreenshot(string caption)
        {
            Size screenSize = Capture.GetScreenSize();

            if (Capture.CanCaptureScreenshot())
            {
                if (caption != null)
                {
                    Capture.SetCaption(caption);
                }

                using (Bitmap bitmap = Capture.Screenshot(new CaptureParameters()
                {
                    Zoom = 0.25
                }))
                {
                    TestLog.EmbedImage("Screenshot with 0.25x zoom", bitmap);

                    Assert.Multiple(() =>
                    {
                        Assert.AreApproximatelyEqual(screenSize.Width / 2, bitmap.Width, 1);
                        Assert.AreApproximatelyEqual(screenSize.Height / 2, bitmap.Height, 1);
                    });
                }
            }
            else
            {
                Assert.Throws <ScreenshotNotAvailableException>(() => Capture.Screenshot(new CaptureParameters()
                {
                    Zoom = 0.25
                }),
                                                                "CanCaptureScreenshot returned false so expected an exception to be thrown.");
            }
        }
Ejemplo n.º 6
0
        public void Screenshot_CapturesScreenshot(string caption)
        {
            Size screenSize = Capture.GetScreenSize();

            if (Capture.CanCaptureScreenshot())
            {
                if (caption != null)
                {
                    Capture.SetCaption(caption);
                }

                using (Bitmap bitmap = Capture.Screenshot())
                {
                    TestLog.EmbedImage("Screenshot", bitmap);

                    Assert.Multiple(() =>
                    {
                        Assert.AreEqual(screenSize.Width, bitmap.Width);
                        Assert.AreEqual(screenSize.Height, bitmap.Height);
                    });
                }
            }
            else
            {
                Assert.Throws <ScreenshotNotAvailableException>(() => Capture.Screenshot(),
                                                                "CanCaptureScreenshot returned false so expected an exception to be thrown.");
            }
        }
Ejemplo n.º 7
0
 public static void Message(string message, Image image)
 {
     TestLog.BeginSection("");
     Log.Message(message);
     if (image != null)
     {
         TestLog.EmbedImage(null, image);
     }
     TestLog.End();
 }
        public void LogScreenshot()
        {
            string screenshotDir  = Directory.GetCurrentDirectory() + "\\Screenshots\\";
            string screenshotPath = screenshotDir + "Screenshot_" + DateTime.Now.ToString("yymmddhhmmssff") + ".png";
            var    screenshot     = GetScreenshot(screenshotPath);

            if (!Directory.Exists(screenshotDir))
            {
                Directory.CreateDirectory(screenshotDir);
            }
            if (screenshot == null)
            {
                TestLog.Warnings.WriteLine("Could not get screenshot.");
                return;
            }
            TestLog.EmbedImage(null, screenshot);
        }
Ejemplo n.º 9
0
        public void TakeScreenShot_WebDriver()
        {
            ITakesScreenshot webDriver  = (ITakesScreenshot)this._driver;
            Screenshot       ss         = webDriver.GetScreenshot();
            string           screenshot = ss.AsBase64EncodedString;

            byte[] imageBytes = Convert.FromBase64String(ss.AsBase64EncodedString);

            using (System.IO.MemoryStream ms = new System.IO.MemoryStream(imageBytes, 0, imageBytes.Length))
            {
                // Convert byte[] to Image
                ms.Write(imageBytes, 0, imageBytes.Length);
                System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true);

                // Embed the image to the log
                TestLog.EmbedImage(null, image);
            }
        }
Ejemplo n.º 10
0
        public void Sections()
        {
            TestLog.Write("Some text with no newline.");

            using (TestLog.BeginSection("A section."))
            {
                TestLog.WriteLine("Some text.");
                TestLog.WriteLine("More text.");

                TestLog.EmbedImage("An image", Resources.MbUnitLogo);

                using (TestLog.BeginSection("Another section."))
                {
                    TestLog.Write("Same image as above.");
                    TestLog.EmbedExisting("An image");
                }
            }
        }
Ejemplo n.º 11
0
        public void Paint()
        {
            var overlayManager = new OverlayManager();
            var overlay        = new CaptionOverlay()
            {
                Text = "This is some text.",
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Bottom
            };

            overlayManager.AddOverlay(overlay);

            using (Bitmap bitmap = CreateBitmapWithBackground())
            {
                overlayManager.PaintOverlaysOnImage(bitmap, 0, 0);

                TestLog.WriteLine("Image should contain 'This is some text.' centered at the bottom.");
                TestLog.EmbedImage("Image", bitmap);
            }
        }
Ejemplo n.º 12
0
 public static void LogImage(Image image)
 {
     TestLog.EmbedImage(null, image);
 }