public Bitmap GetImage()
        {
            byte[] screenshotBytes;
            Bitmap result;

            if (eyes_.CachedViewport.IsEmpty)
            {
                try
                {
                    string screenshot64 = (string)jsExecutor_.ExecuteScript("mobile: viewportScreenshot");
                    screenshotBytes = Convert.FromBase64String(screenshot64);
                }
                catch (Exception e)
                {
                    logger_.Log("Warning: " + e);
                    screenshotBytes = tsInstance_.GetScreenshot().AsByteArray;
                }
                result = BasicImageUtils.CreateBitmap(screenshotBytes);
            }
            else
            {
                screenshotBytes = tsInstance_.GetScreenshot().AsByteArray;
                Bitmap screenshotBitmap = BasicImageUtils.CreateBitmap(screenshotBytes);
                eyes_.DebugScreenshotProvider.Save(screenshotBitmap, "DEVICE_ORIGINAL");
                result = BasicImageUtils.Crop(screenshotBitmap, eyes_.CachedViewport);
            }
            result = BasicImageUtils.ScaleImage(result, eyes_.ScaleRatio);
            return(result);
        }
        //[Test]
        //[Ignore("fails if not set up correctly")]
        public void TestSetViewportSize()
        {
            ChromeOptions options = new ChromeOptions();

            options.AddArgument("disable-infobars");
            if (TestUtils.RUN_HEADLESS)
            {
                options.AddArgument("headless");
            }
            IWebDriver driver = new RemoteWebDriver(options);

            Size expectedSize = new Size(700, 499);

            try
            {
                driver.Url = "http://viewportsizes.com/mine/";

                SeleniumEyes.SetViewportSize(driver, expectedSize);

                Bitmap screenshot = BasicImageUtils.CreateBitmap(((ITakesScreenshot)driver).GetScreenshot().AsByteArray);
                screenshot.Save($@"{logsPath_}\TestSetViewportSize.png");

                Size actualSize = SeleniumEyes.GetViewportSize(driver);

                Assert.AreEqual(expectedSize, actualSize, "Sizes differ");
            }
            finally
            {
                driver.Quit();
            }
        }
示例#3
0
        public override Bitmap GetImage()
        {
            logger_.Verbose("Getting screenshot...");

            EyesWebDriver eyesWebDriver = eyes_.GetDriver();
            FrameChain    frameChain    = eyesWebDriver.GetFrameChain().Clone();

            logger_.Verbose("temporarilly switching to default content.");
            eyesWebDriver.SwitchTo().DefaultContent();

            Bitmap image = BasicImageUtils.CreateBitmap(tsInstance_.GetScreenshot().AsByteArray);

            eyes_.DebugScreenshotProvider.Save(image, "FIREFOX");

            logger_.Verbose("switching back to original frame.");
            ((EyesWebDriverTargetLocator)eyesWebDriver.SwitchTo()).Frames(frameChain);

            return(image);
        }
 public EyesLeanFTScreenshot(byte[] screenshotBytes) : base(BasicImageUtils.CreateBitmap(screenshotBytes))
 {
 }
示例#5
0
        public static SimpleImageProvider FromBytes(byte[] screenshotBytes)
        {
            Bitmap bmp = BasicImageUtils.CreateBitmap(screenshotBytes);

            return(new SimpleImageProvider(bmp));
        }
示例#6
0
 public virtual Bitmap GetImage()
 {
     return(BasicImageUtils.CreateBitmap(tsInstance_.GetScreenshot().AsByteArray));
 }