Example #1
0
        public async void RunJobAsync()
        {
            var screenshotsAPI = new ScreenshotsApi();
            var browsers       = await screenshotsAPI.GetBrowsersAsync();

            var job = await screenshotsAPI.StartJobAsync("http://www.google.com", new Job.JobInfo(), false,
                                                         browsers.First(x => x.OS == "Windows" && x.OSVersion == "10" && x.BrowserName == "firefox" && x.BrowserVersion == "45.0"));

            while (!job.IsComplete)
            {
                Thread.Sleep(1000);
                job = screenshotsAPI.GetJobInfoAsync(job.Id).Result;
            }

            if (job.State == Job.States.Done)
            {
                var screenshot = job.Screenshots.FirstOrDefault(x => x.State == Screenshot.States.Done);
                Assert.IsNotNull(screenshot);
                if (screenshot != null)
                {
                    if (!System.IO.Directory.Exists("Screenshots"))
                    {
                        System.IO.Directory.CreateDirectory("Screenshots");
                    }
                    await screenshotsAPI.SaveScreenshotToFileAsync(screenshot, "Screenshots", "screenshot", true);

                    Process.Start(System.IO.Path.GetFullPath("Screenshots/screenshot.png"));
                }
            }
        }
Example #2
0
        public void RunJob()
        {
            var screenshotsAPI = new ScreenshotsApi(); // Config based Authentication

            //var screenshotsAPI = new ScreenshotsApi(Username, Password); // Alternative

            Assert.IsNotNull(screenshotsAPI);

            var browsers = screenshotsAPI.GetBrowsers();

            Assert.IsNotNull(browsers);

            var job = screenshotsAPI.StartJob("http://www.google.com", new Job.JobInfo()
            {
                Orientation = Job.Orientations.Landscape, Quality = Job.Qualities.Compressed, WaitTime = 10, WinResolution = Job.WinResolutions.R_1280x1024
            }, false,
                                              browsers.First(x => x.OS == "Windows" && x.OSVersion == "10" && x.BrowserName == "chrome" && x.BrowserVersion == "49.0"));

            while (!job.IsComplete)
            {
                Thread.Sleep(1000);

                job = screenshotsAPI.GetJobInfo(job.Id);
                Assert.IsNotNull(job);
            }

            Assert.IsTrue(job.IsComplete);
            Assert.IsTrue(job.State == Job.States.Done);

            if (job.State == Job.States.Done)
            {
                var screenshot = job.Screenshots.FirstOrDefault(x => x.State == Screenshot.States.Done);
                Assert.IsNotNull(screenshot);
                if (screenshot != null)
                {
                    if (!System.IO.Directory.Exists("Screenshots"))
                    {
                        System.IO.Directory.CreateDirectory("Screenshots");
                    }
                    screenshotsAPI.SaveScreenshotToFile(screenshot, "Screenshots", "screenshot", true);
                    screenshotsAPI.SaveThumbnailToFile(screenshot, "Screenshots", "screenshot-thumbnail", true);
                    Process.Start(System.IO.Path.GetFullPath("Screenshots/screenshot.png"));
                }
            }
        }
Example #3
0
        public void RunBatch()
        {
            var screenshotsAPI = new ScreenshotsApi();

            var browsers = screenshotsAPI.GetBrowsers();

            Assert.IsNotNull(browsers);

            var batchCaptureJobForWindows = new BatchCaptureJobInfo(
                url: "http://www.google.com",
                filenameTemplate: "google",
                jobInfo: new Job.JobInfo()
            {
                WinResolution = Job.WinResolutions.R_1280x1024
            },
                browsers: browsers.Where(x => x.OS == "Windows" && x.OSVersion == "10" && x.BrowserName == "firefox" && x.BrowserVersion == "45.0").ToArray());

            var batchCaptureJobForDevices = new BatchCaptureJobInfo(
                url: "http://www.bing.com",
                filenameTemplate: "bing",
                jobInfo: new Job.JobInfo()
            {
                Orientation = Job.Orientations.Portrait
            },
                browsers: browsers.Where(x => x.Device == "HTC One M8").ToArray());

            var capturer = new BatchScreenshotsCapture(1, false);

            if (System.IO.Directory.Exists("Screenshots"))
            {
                System.IO.Directory.Delete("Screenshots", true);
            }
            System.IO.Directory.CreateDirectory("Screenshots");

            capturer.ExecuteBatch("Screenshots-" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss", CultureInfo.InvariantCulture), false, batchCaptureJobForWindows, batchCaptureJobForDevices);
            Process.Start(System.IO.Path.GetFullPath("Screenshots"));
        }