diff --git a/BrowserStack.API.Screenshots.sln b/BrowserStack.API.Screenshots.sln
index b7d218f..13a43b6 100644
--- a/BrowserStack.API.Screenshots.sln
+++ b/BrowserStack.API.Screenshots.sln
@@ -1,10 +1,12 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2013
-VisualStudioVersion = 12.0.21005.1
+# Visual Studio 14
+VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BrowserStack.API.Screenshots", "BrowserStack.API.Screenshots\BrowserStack.API.Screenshots.csproj", "{1025B377-7530-49D0-9C26-4B12B673C331}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BrowserStack.API.ScreenshotsTests", "BrowserStack.API.ScreenshotsTests\BrowserStack.API.ScreenshotsTests.csproj", "{F3F1F761-0502-40FA-9B66-974088EAF310}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
{1025B377-7530-49D0-9C26-4B12B673C331}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1025B377-7530-49D0-9C26-4B12B673C331}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1025B377-7530-49D0-9C26-4B12B673C331}.Release|Any CPU.Build.0 = Release|Any CPU
+ {F3F1F761-0502-40FA-9B66-974088EAF310}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {F3F1F761-0502-40FA-9B66-974088EAF310}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {F3F1F761-0502-40FA-9B66-974088EAF310}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {F3F1F761-0502-40FA-9B66-974088EAF310}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/BrowserStack.API.Screenshots/BatchScreenshotsCapture.cs b/BrowserStack.API.Screenshots/BatchScreenshotsCapture.cs
index 9bed2ba..c73e574 100644
--- a/BrowserStack.API.Screenshots/BatchScreenshotsCapture.cs
+++ b/BrowserStack.API.Screenshots/BatchScreenshotsCapture.cs
@@ -84,7 +84,7 @@ internal BatchScreenshotsCapture(IScreenshotsApi screenshotsApi)
/// if set to true then the batch job will also save the thumbnails when saving the screenshots.
/// The username.
/// The password.
- public BatchScreenshotsCapture(int sessionLimit, bool captureThumbnails, string username, string password):
+ public BatchScreenshotsCapture(int sessionLimit, bool captureThumbnails, string username = null, string password = null):
this(string.IsNullOrEmpty(username) && string.IsNullOrEmpty(password) ? new ScreenshotsApi() : new ScreenshotsApi(username, password))
{
this.sessionLimit = sessionLimit;
@@ -312,6 +312,12 @@ await Task.WhenAll(
}));
}
+ public void ExecuteBatch(string rootPath, bool usingTunnel, params BatchCaptureJobInfo[] batchCaptureJobs)
+ {
+ var executeBatchAsync = ExecuteBatchAsync(rootPath, usingTunnel, batchCaptureJobs);
+ executeBatchAsync.GetAwaiter().GetResult(); //To properly re-throw an exception: http://stackoverflow.com/questions/20170527/how-to-correctly-rethrow-an-exception-of-task-already-in-faulted-state
+ }
+
#endregion
#region Methods
diff --git a/BrowserStack.API.Screenshots/BrowserStack.API.Screenshots.csproj b/BrowserStack.API.Screenshots/BrowserStack.API.Screenshots.csproj
index b6d9f2e..bdd6c93 100644
--- a/BrowserStack.API.Screenshots/BrowserStack.API.Screenshots.csproj
+++ b/BrowserStack.API.Screenshots/BrowserStack.API.Screenshots.csproj
@@ -12,6 +12,8 @@
v4.5
512
true
+
+
true
@@ -31,19 +33,21 @@
4
-
- False
- ..\packages\Newtonsoft.Json.5.0.8\lib\net45\Newtonsoft.Json.dll
+
+ ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll
+ True
-
- ..\packages\Microsoft.Net.Http.2.2.18\lib\net45\System.Net.Http.Extensions.dll
+
+ ..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll
+ True
-
- ..\packages\Microsoft.Net.Http.2.2.18\lib\net45\System.Net.Http.Primitives.dll
+
+ ..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll
+ True
@@ -74,9 +78,18 @@
-
+
+ Designer
+
+
+
+
+ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
+
+
+
+
\ No newline at end of file
diff --git a/BrowserStack.API.ScreenshotsTests/Properties/AssemblyInfo.cs b/BrowserStack.API.ScreenshotsTests/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..3f8d124
--- /dev/null
+++ b/BrowserStack.API.ScreenshotsTests/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("BrowserStack.API.ScreenshotsTests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("BrowserStack.API.ScreenshotsTests")]
+[assembly: AssemblyCopyright("Copyright © 2016")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("f3f1f761-0502-40fa-9b66-974088eaf310")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/BrowserStack.API.ScreenshotsTests/ScreenshotsApiTests.cs b/BrowserStack.API.ScreenshotsTests/ScreenshotsApiTests.cs
new file mode 100644
index 0000000..c9bb67c
--- /dev/null
+++ b/BrowserStack.API.ScreenshotsTests/ScreenshotsApiTests.cs
@@ -0,0 +1,171 @@
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using BrowserStack.API.Screenshots;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Globalization;
+using System.Linq;
+using System.Security.Policy;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using BrowserStack.API.Screenshots.Configuration;
+using System.Configuration;
+
+namespace BrowserStack.API.Screenshots.Tests
+{
+ [TestClass()]
+ public class ScreenshotsApiTests
+ {
+ [TestMethod()]
+ public void HelloWorld()
+ {
+ Assert.IsTrue( true );
+ }
+
+ /// MSTest and ReSharper responds with "Inconclusive: Test not run" on all async testmethods due to unknown factors>
+ [TestMethod()]
+ public async void HelloWorldAsync()
+ {
+ bool doodle = await Task.Run(()=> true);
+ Assert.IsTrue(doodle);
+ }
+
+ [TestMethod()]
+ public void CustomConfigurationSectionIsPresent()
+ {
+ var section = (BrowserStackAPIScreenshotsSection)ConfigurationManager.GetSection("BrowserStackAPIScreenshotsSection");
+ Assert.IsNotNull(section, "App.Config missing Configuration section BrowserStackAPIScreenshots");
+ Assert.IsNotNull(section.Authentication, "App.Config missing Authentication Element in section BrowserStackAPIScreenshots");
+ Assert.IsFalse(string.IsNullOrWhiteSpace(section.Authentication.Username), "Missing Username in App.Config BrowserStackAPIScreenshots Authentication");
+ Assert.IsFalse(string.IsNullOrWhiteSpace(section.Authentication.Password), "Missing Password in App.Config BrowserStackAPIScreenshots Authentication");
+
+ }
+
+ [TestMethod()]
+ 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"));
+ }
+ }
+ }
+
+ [TestMethod()]
+ 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"));
+ }
+ }
+ }
+
+ [TestMethod()]
+ 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"));
+ }
+
+ [TestMethod()]
+ public async void RunBatchAsync()
+ {
+ var screenshotsAPI = new ScreenshotsApi();
+
+ var browsers = await screenshotsAPI.GetBrowsersAsync();
+
+ 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");
+
+ await capturer.ExecuteBatchAsync("Screenshots-" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss", CultureInfo.InvariantCulture), false, batchCaptureJobForWindows, batchCaptureJobForDevices);
+ Process.Start(System.IO.Path.GetFullPath("Screenshots"));
+ }
+
+
+ }
+}
\ No newline at end of file