Skip to content

Instantly share code, notes, and snippets.

@jimevans
Created September 9, 2019 21:07
Show Gist options
  • Save jimevans/690886641d383cad201c9b6873b39754 to your computer and use it in GitHub Desktop.
Save jimevans/690886641d383cad201c9b6873b39754 to your computer and use it in GitHub Desktop.
BrowserStack type-safe options creator for .NET
using System.Collections.Generic;
namespace BrowserStack
{
/// <summary>
/// This class defines the Chrome-specific options that can be set for a BrowserStack session.
/// </summary>
public class BrowserStackChromeOptions
{
private static readonly string DriverVersionOptionName = "driver";
/// <summary>
/// Gets or sets the version of the ChromeDriver executable to use.
/// </summary>
public string DriverVersion { get; set; }
/// <summary>
/// Converts this <see cref="BrowserStackChromeOptions"/> instance to a dictionary to be added
/// to a set of options for creating a Chrome session on BrowserStack.
/// </summary>
/// <returns>
/// A <see cref="Dictionary{String, Object}"/> containing the BrowserStack-specific
/// Chrome settings for a session.
/// </returns>
public Dictionary<string, object> ToDictionary()
{
Dictionary<string, object> chromeSpecificOptions = new Dictionary<string, object>();
if (!string.IsNullOrEmpty(this.DriverVersion))
{
chromeSpecificOptions[DriverVersionOptionName] = this.DriverVersion;
}
return chromeSpecificOptions;
}
}
}
namespace BrowserStack
{
/// <summary>
/// Represents the levels of browser console logs captured during the session.
/// </summary>
public enum BrowserStackConsoleLogLevel
{
/// <summary>
/// Console log level is unspecified, and returns error level output from the browser console.
/// </summary>
Default,
/// <summary>
/// Console logs are not captured.
/// </summary>
Disable,
/// <summary>
/// Retrieves only error output from the browser console.
/// </summary>
Errors,
/// <summary>
/// Retrieves warning and error output from the browser console.
/// </summary>
Warnings,
/// <summary>
/// Retrieves informational message, warning, and error output from the browser console.
/// </summary>
Info,
/// <summary>
/// Retrieves all output from the browser console.
/// </summary>
Verbose,
}
}
namespace BrowserStack
{
/// <summary>
/// Describes the available device orientations for executing against a mobile device.
/// </summary>
public enum BrowserStackDeviceOrientation
{
/// <summary>
/// The orientation is unset, and uses the default orientation of the device.
/// </summary>
Default,
/// <summary>
/// The device is in portrait orientation.
/// </summary>
Portrait,
/// <summary>
/// The device is in landscape orientation.
/// </summary>
Landscape
}
}
using System.Collections.Generic;
namespace BrowserStack
{
/// <summary>
/// This class defines the Microsoft Edge-specific options that can be set for a BrowserStack session.
/// </summary>
public class BrowserStackEdgeOptions
{
private static readonly string EnablePopupsOptionName = "enablePopups";
/// <summary>
/// Gets or sets a value indicating whether popups are enabled.
/// </summary>
public bool ArePopupsEnabled { get; set; }
/// <summary>
/// Converts this <see cref="BrowserStackEdgeOptions"/> instance to a dictionary to be added
/// to a set of options for creating a Microsoft Edge session on BrowserStack.
/// </summary>
/// <returns>
/// A <see cref="Dictionary{String, Object}"/> containing the BrowserStack-specific
/// IE settings for a session.
/// </returns>
public Dictionary<string, object> ToDictionary()
{
Dictionary<string, object> edgeSpecificOptions = new Dictionary<string, object>();
if (this.ArePopupsEnabled)
{
edgeSpecificOptions[EnablePopupsOptionName] = true;
}
return edgeSpecificOptions;
}
}
}
using System.Collections.Generic;
namespace BrowserStack
{
/// <summary>
/// This class defines the Firefox-specific options that can be set for a BrowserStack session.
/// </summary>
public class BrowserStackFirefoxOptions
{
private static readonly string DriverVersionOptionName = "driver";
private static readonly string GeckoDriverOptionName = "gecko";
/// <summary>
/// Gets or sets the version of the ChromeDriver executable to use.
/// </summary>
public string DriverVersion { get; set; }
/// <summary>
/// Converts this <see cref="BrowserStackFirefoxOptions"/> instance to a dictionary to be added
/// to a set of options for creating a Chrome session on BrowserStack.
/// </summary>
/// <returns>
/// A <see cref="Dictionary{String, Object}"/> containing the BrowserStack-specific
/// Chrome settings for a session.
/// </returns>
public Dictionary<string, object> ToDictionary()
{
Dictionary<string, object> firefoxSpecificOptions = new Dictionary<string, object>();
if (!string.IsNullOrEmpty(this.DriverVersion))
{
Dictionary<string, object> geckoDriverOptions = new Dictionary<string, object>();
geckoDriverOptions[DriverVersionOptionName] = this.DriverVersion;
firefoxSpecificOptions[GeckoDriverOptionName] = geckoDriverOptions;
}
return firefoxSpecificOptions;
}
}
}
using System.Collections.Generic;
namespace BrowserStack
{
public enum BrowserStackInternetExplorerArchitecture
{
Default,
x32,
x64
}
/// <summary>
/// This class defines the Internet Explorer-specific options that can be set for a BrowserStack session.
/// </summary>
public class BrowserStackInternetExplorerOptions
{
private static readonly string DriverVersionOptionName = "driver";
private static readonly string IsFlashDisabledOptionName = "noFlash";
private static readonly string ArchitectureOptionName = "arch";
private static readonly string CompatibilityOptionName = "compatibility";
private static readonly string EnablePopupsOptionName = "enablePopups";
private BrowserStackInternetExplorerArchitecture architecture = BrowserStackInternetExplorerArchitecture.Default;
/// <summary>
/// Gets or sets the version of the IEDriverServer executable to use.
/// </summary>
public string DriverVersion { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the Adobe Flash player is disabled.
/// </summary>
public bool IsFlashDisabled { get; set; }
/// <summary>
/// Gets or sets the processer architecture of the browser.
/// </summary>
public BrowserStackInternetExplorerArchitecture Architecture
{
get { return this.architecture; }
set { this.architecture = value; }
}
/// <summary>
/// Gets or sets a value indicating the compatibility level of the browser instance.
/// </summary>
public string Compatibility { get; set; }
/// <summary>
/// Gets or sets a value indicating whether popups are enabled.
/// </summary>
public bool ArePopupsEnabled { get; set; }
/// <summary>
/// Converts this <see cref="BrowserStackInternetExplorerOptions"/> instance to a dictionary to be added
/// to a set of options for creating an IE session on BrowserStack.
/// </summary>
/// <returns>
/// A <see cref="Dictionary{String, Object}"/> containing the BrowserStack-specific
/// IE settings for a session.
/// </returns>
public Dictionary<string, object> ToDictionary()
{
Dictionary<string, object> ieSpecificOptions = new Dictionary<string, object>();
if (!string.IsNullOrEmpty(this.DriverVersion))
{
ieSpecificOptions[DriverVersionOptionName] = this.DriverVersion;
}
if (this.IsFlashDisabled)
{
ieSpecificOptions[IsFlashDisabledOptionName] = true;
}
if (this.architecture != BrowserStackInternetExplorerArchitecture.Default)
{
ieSpecificOptions[ArchitectureOptionName] = this.architecture.ToString().ToLowerInvariant();
}
if (!string.IsNullOrEmpty(this.Compatibility))
{
ieSpecificOptions[CompatibilityOptionName] = this.Compatibility;
}
if (this.ArePopupsEnabled)
{
ieSpecificOptions[EnablePopupsOptionName] = true;
}
return ieSpecificOptions;
}
}
}
using System.Collections.Generic;
namespace BrowserStack
{
/// <summary>
/// This class defines the options that can be set for a BrowserStack session for mobile applications.
/// </summary>
public class BrowserStackMobileSessionOptions : BrowserStackSessionOptions
{
private static readonly string AppiumVersionOptionName = "appiumVersion";
private static readonly string DeviceNameOptionName = "deviceName";
private static readonly string RealMobileOptionName = "realMobile";
private static readonly string DeviceOrientationOptionName = "deviceOrientation";
/// <summary>
/// Gets or sets the version of Appium to be used during the session.
/// </summary>
public string AppiumVersion { get; set; }
/// <summary>
/// Gets or sets a value representing a particular mobile device for the test environment.
/// </summary>
public string DeviceName { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to execute using a physical mobile device.
/// </summary>
public bool IsUsingRealDevice { get; set; }
/// <summary>
/// Gets or sets a value indicating the orientation of the device.
/// </summary>
public BrowserStackDeviceOrientation DeviceOrientation { get; set; }
public override Dictionary<string, object> ToDictionary()
{
Dictionary<string, object> options = base.ToDictionary();
if (!string.IsNullOrEmpty(this.AppiumVersion))
{
options[AppiumVersionOptionName] = this.AppiumVersion;
}
if (!string.IsNullOrEmpty(this.DeviceName))
{
options[DeviceNameOptionName] = this.DeviceName;
}
if (this.IsUsingRealDevice)
{
options[RealMobileOptionName] = true;
}
if (this.DeviceOrientation != BrowserStackDeviceOrientation.Default)
{
options[DeviceOrientationOptionName] = this.DeviceOrientation.ToString().ToLowerInvariant();
}
return options;
}
}
}
using System;
using System.Globalization;
namespace BrowserStack
{
/// <summary>
/// Represents a network profile for use with BrowserStack.
/// </summary>
public class BrowserStackNetworkProfile
{
public static readonly string TwoGGprsGood = "2g-gprs-good";
public static readonly string TwoGGprsLossy = "2g-gprs-lossy";
public static readonly string EdgeGood = "edge-good";
public static readonly string EdgeLossy = "edge-lossy";
public static readonly string ThreeGUmtsGood = "3g-umts-good";
public static readonly string ThreeGUmtsLossy = "3g-umts-lossy";
public static readonly string ThreePointFiveGHspaGood = "3.5g-hspa-good";
public static readonly string ThreePointFiveGHspaLossy = "3.5g-hspa-lossy";
public static readonly string ThreePointFiveGHspaPlusGood = "3.5g-hspa-plus-good";
public static readonly string ThreePointFiveGHspaPlusLossy = "3.5g-hspa-plus-lossy";
public static readonly string FourGLteGood = "4g-lte-good";
public static readonly string FourGLteHighLatency = "4g-lte-high-latency";
public static readonly string FourGLteLossy = "4g-lte-lossy";
public static readonly string FourGLteAdvancedGood = "4g-lte-advanced-good";
public static readonly string FourGLteAdvancedLossy = "4g-lte-advanced-lossy";
public static readonly string NoNetwork = "no-network";
public static readonly string AirplaneMode = "airplane-mode";
private int downloadSpeed;
private int uploadSpeed;
private int latency;
private int packetLossPercent;
/// <summary>
/// Initializes a new instance of the <see cref="BrowserStackNetworkProfile"/> class.
/// </summary>
public BrowserStackNetworkProfile()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="BrowserStackNetworkProfile"/> class with the specified values.
/// </summary>
/// <param name="downloadSpeed">The network download speed in kbps.</param>
/// <param name="uploadSpeed">The network upload speed in kbps</param>
/// <param name="latency">The network latency in milliseconds (ms).</param>
/// <param name="packetLossPercent">The percentage of packet loss.</param>
public BrowserStackNetworkProfile(int downloadSpeed, int uploadSpeed, int latency, int packetLossPercent)
{
this.DownloadSpeed = downloadSpeed;
this.UploadSpeed = uploadSpeed;
this.Latency = latency;
this.PacketLossPercent = packetLossPercent;
}
/// <summary>
/// Gets or sets the network download speed in kbps.
/// </summary>
public int DownloadSpeed
{
get
{
return this.downloadSpeed;
}
set
{
if (value < 0)
{
throw new ArgumentException("Download speed must be greater than or equal to zero.");
}
this.downloadSpeed = value;
}
}
/// <summary>
/// Gets or sets the network upload speed in kbps.
/// </summary>
public int UploadSpeed
{
get
{
return this.uploadSpeed;
}
set
{
if (value < 0)
{
throw new ArgumentException("Upload speed must be greater than or equal to zero.");
}
this.uploadSpeed = value;
}
}
/// <summary>
/// Gets or sets the network latency in milliseconds (ms).
/// </summary>
public int Latency
{
get
{
return this.latency;
}
set
{
if (value < 0)
{
throw new ArgumentException("Latency must be greater than or equal to zero.");
}
this.latency = value;
}
}
/// <summary>
/// Gets or sets the percentage of packet loss.
/// </summary>
public int PacketLossPercent
{
get
{
return this.packetLossPercent;
}
set
{
if (value < 0)
{
throw new ArgumentException("Packet loss percent must be greater than or equal to zero.");
}
this.packetLossPercent = value;
}
}
public override string ToString()
{
return string.Format(CultureInfo.InvariantCulture, "{0},{1},{2},{3}", this.downloadSpeed, this.uploadSpeed, this.latency, this.packetLossPercent);
}
}
}
using System.Collections.Generic;
namespace BrowserStack
{
/// <summary>
/// This class defines the Safari-specific options that can be set for a BrowserStack session.
/// </summary>
public class BrowserStackSafariOptions
{
private static readonly string DriverVersionOptionName = "driver";
private static readonly string EnablePopupsOptionName = "enablePopups";
private static readonly string AllowAllCookiesOptionName = "allowAllCookies";
/// <summary>
/// Gets or sets the version of the SafariDriver executable to use.
/// </summary>
public string DriverVersion { get; set; }
/// <summary>
/// Gets or sets a value indicating whether popups are enabled.
/// </summary>
public bool ArePopupsEnabled { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to allow all cookies.
/// </summary>
public bool AreAllCookiesAllowed { get; set; }
/// <summary>
/// Converts this <see cref="BrowserStackSafariOptions"/> instance to a dictionary to be added
/// to a set of options for creating an IE session on BrowserStack.
/// </summary>
/// <returns>
/// A <see cref="Dictionary{String, Object}"/> containing the BrowserStack-specific
/// IE settings for a session.
/// </returns>
public Dictionary<string, object> ToDictionary()
{
Dictionary<string, object> safariSpecificOptions = new Dictionary<string, object>();
if (!string.IsNullOrEmpty(this.DriverVersion))
{
safariSpecificOptions[DriverVersionOptionName] = this.DriverVersion;
}
if (this.ArePopupsEnabled)
{
safariSpecificOptions[EnablePopupsOptionName] = true;
}
if (this.AreAllCookiesAllowed)
{
safariSpecificOptions[AllowAllCookiesOptionName] = true;
}
return safariSpecificOptions;
}
}
}
using System.Collections.Generic;
namespace BrowserStack
{
/// <summary>
/// This class defines the options that can be set for a BrowserStack session.
/// </summary>
public class BrowserStackSessionOptions
{
/// <summary>
/// The option name to be used in setting the BrowserStack options when creating a new session.
/// </summary>
public static readonly string BrowserStackOptionsOptionName = "bstack:options";
private static readonly string UserNameOptionName = "userName";
private static readonly string AccessKeyOptionName = "accessKey";
private static readonly string OperatingSystemOptionName = "os";
private static readonly string OperatingSystemVersionOptionName = "osVersion";
private static readonly string ProjectNameOptionName = "projectName";
private static readonly string BuildNameOptionName = "buildName";
private static readonly string SessionNameOptionName = "sessionName";
private static readonly string IsLocalExecutionOptionName = "local";
private static readonly string IsDebuggingEnabledOptionName = "debug";
private static readonly string ConsoleLogLevelOptionName = "consoleLogs";
private static readonly string IsNetworkLoggingEnabledOptionName = "networkLogs";
private static readonly string IsAppiumLoggingEnabledOptionName = "appiumLogs";
private static readonly string IsSeleniumLoggingEnabledOptionName = "seleniumLogs";
private static readonly string IsVideoEnabledOptionName = "video";
private static readonly string GeoLocationOptionName = "geoLocation";
private static readonly string NetworkProfileOptionName = "networkProfile";
private static readonly string CustomNetworkOptionName = "customNetwork";
private static readonly string TimeZoneOptionName = "timezone";
private static readonly string ResolutionOptionName = "resolution";
private static readonly string SeleniumVersionOptionName = "seleniumVersion";
private static readonly string MaskCommandsOptionName = "maskCommands";
private static readonly string ChromeSpecificSettingsOptionName = "chrome";
private static readonly string FirefoxSpecificSettingsOptionName = "firefox";
private static readonly string InternetExplorerSpecificSettingsOptionName = "ie";
private static readonly string EdgeSpecificSettingsOptionName = "edge";
private static readonly string SafariSpecificSettingsOptionName = "safari";
private bool enableVideoRecording = true;
private bool enableAppiumLogs = true;
private bool enableSeleniumLogs = true;
/// <summary>
/// Gets or sets the BrowserStack user name used to create the session.
/// </summary>
public string UserName { get; set; }
/// <summary>
/// Gets or sets the BrowserStack access key used to create the session.
/// </summary>
public string AccessKey { get; set; }
/// <summary>
/// Gets or sets the operating system on which the browser or application will be run.
/// </summary>
public string OperatingSystem { get; set; }
/// <summary>
/// Gets or sets the operating system version on which the browser or application will be run.
/// </summary>
public string OperatingSystemVersion { get; set; }
/// <summary>
/// Gets or sets a user-defined name for the project.
/// </summary>
public string ProjectName { get; set; }
/// <summary>
/// Gets or sets a user-defined name for the build against which the session is executed.
/// </summary>
public string BuildName { get; set; }
/// <summary>
/// Gets or sets a user-defined name for the session.
/// </summary>
public string SessionName { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the execution of the session
/// is created using local or internal servers.
/// </summary>
public bool IsLocalExecution { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to record screenshots at various
/// steps during the session.
/// </summary>
public bool IsDebugEnabled { get; set; }
/// <summary>
/// Gets or sets a value indicating the level of logging captured from the browser console.
/// </summary>
public BrowserStackConsoleLogLevel BrowserConsoleLogLevel { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to record network logs during the session.
/// </summary>
public bool IsNetworkLoggingEnabled { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to record Appium logs during the session.
/// </summary>
public bool IsAppiumLoggingEnabled
{
get { return this.enableAppiumLogs; }
set { this.enableAppiumLogs = value; }
}
/// <summary>
/// Gets or sets a value indicating whether to record video during the session.
/// </summary>
public bool IsVideoRecordingEnabled
{
get { return this.enableVideoRecording; }
set { this.enableVideoRecording = value; }
}
/// <summary>
/// Gets or sets a value indicating whether to record Selenium logs during the session.
/// </summary>
public bool IsSeleniumLoggingEnabled
{
get { return this.enableSeleniumLogs; }
set { this.enableSeleniumLogs = value; }
}
/// <summary>
/// Gets or sets the geolocation to set in the BrowserStack virtual machine during the session.
/// </summary>
public string GeoLocation { get; set; }
/// <summary>
/// Gets or sets a named profile for simulation of network conditions.
/// Named profiles can be found as static properties of the
/// <see cref="BrowserStackNetworkProfile"/> object.
/// </summary>
public string NamedNetworkProfile { get; set; }
/// <summary>
/// Gets or sets a custom profile for simulation of network conditions.
/// </summary>
public BrowserStackNetworkProfile CustomNetworkProfile { get; set; }
/// <summary>
/// Gets or sets the time zone to set in the BrowserStack virtual machine during the session.
/// </summary>
public string TimeZone { get; set; }
/// <summary>
/// Gets or sets the screen resolution to be used during the session.
/// </summary>
public string ScreenResolution { get; set; }
/// <summary>
/// Gets or sets the version of Selenium to be used during the session.
/// </summary>
public string SeleniumVersion { get; set; }
/// <summary>
/// Gets or sets a value indicating whether text sent via SendKeys should be redacted in logs.
/// </summary>
public bool IsMaskingSetValueData { get; set; }
/// <summary>
/// Gets or sets a value indicating whether text sent via the IWebElement object's
/// Text property should be redacted in logs.
/// </summary>
public bool IsMaskingGetValueData { get; set; }
/// <summary>
/// Gets or sets a value indicating whether text sent via the SetCookie command should be redacted in logs.
/// </summary>
public bool IsMaskingSetCookieData { get; set; }
/// <summary>
/// Gets or sets a value indicating whether text sent via the GetCookie or GetNamedCookie commands
/// should be redacted in logs.
/// </summary>
public bool IsMaskingGetCookieData { get; set; }
/// <summary>
/// Gets or sets the Chrome-specific options for a BrowserStack session.
/// </summary>
public BrowserStackChromeOptions ChromeSpecificOptions { get; set; }
/// <summary>
/// Gets or sets the Firefox-specific options for a BrowserStack session.
/// </summary>
public BrowserStackFirefoxOptions FirefoxSpecificOptions { get; set; }
/// <summary>
/// Gets or sets the Internet Explorer-specific options for a BrowserStack session.
/// </summary>
public BrowserStackInternetExplorerOptions InternetExplorerSpecificOptions { get; set; }
/// <summary>
/// Gets or sets the Microsoft Edge-specific options for a BrowserStack session.
/// </summary>
public BrowserStackEdgeOptions EdgeSpecificOptions { get; set; }
/// <summary>
/// Gets or sets the Safari-specific options for a BrowserStack session.
/// </summary>
public BrowserStackSafariOptions SafariSpecificOptions { get; set; }
/// <summary>
/// Converts this <see cref="BrowserStackSessionOptions"/> instance to a dictionary to be added
/// to a set of options for creating a session on BrowserStack.
/// </summary>
/// <returns>
/// A <see cref="Dictionary{String, Object}"/> containing the BrowserStack-specific
/// settings for a session.
/// </returns>
public virtual Dictionary<string, object> ToDictionary()
{
Dictionary<string, object> options = new Dictionary<string, object>();
if (!string.IsNullOrEmpty(this.UserName))
{
options[UserNameOptionName] = this.UserName;
}
if (!string.IsNullOrEmpty(this.AccessKey))
{
options[AccessKeyOptionName] = this.AccessKey;
}
if (!string.IsNullOrEmpty(this.OperatingSystem))
{
options[OperatingSystemOptionName] = this.OperatingSystem;
}
if (!string.IsNullOrEmpty(this.OperatingSystemVersion))
{
options[OperatingSystemVersionOptionName] = this.OperatingSystemVersion;
}
if (!string.IsNullOrEmpty(this.ProjectName))
{
options[ProjectNameOptionName] = this.ProjectName;
}
if (!string.IsNullOrEmpty(this.BuildName))
{
options[BuildNameOptionName] = this.BuildName;
}
if (!string.IsNullOrEmpty(this.SessionName))
{
options[SessionNameOptionName] = this.SessionName;
}
if (this.IsLocalExecution)
{
options[IsLocalExecutionOptionName] = true;
}
if (this.IsDebugEnabled)
{
options[IsDebuggingEnabledOptionName] = true;
}
if (this.BrowserConsoleLogLevel != BrowserStackConsoleLogLevel.Default)
{
options[ConsoleLogLevelOptionName] = this.BrowserConsoleLogLevel.ToString().ToLowerInvariant();
}
if (this.IsNetworkLoggingEnabled)
{
options[IsNetworkLoggingEnabledOptionName] = true;
}
if (!this.enableAppiumLogs)
{
options[IsAppiumLoggingEnabledOptionName] = false;
}
if (!this.enableVideoRecording)
{
options[IsVideoEnabledOptionName] = false;
}
if (!this.enableSeleniumLogs)
{
options[IsSeleniumLoggingEnabledOptionName] = false;
}
if (!string.IsNullOrEmpty(this.GeoLocation))
{
options[GeoLocationOptionName] = this.GeoLocation;
}
if (!string.IsNullOrEmpty(this.NamedNetworkProfile))
{
options[NetworkProfileOptionName] = this.NamedNetworkProfile;
}
if (this.CustomNetworkProfile != null)
{
options[CustomNetworkOptionName] = this.CustomNetworkProfile.ToString();
}
if (!string.IsNullOrEmpty(this.TimeZone))
{
options[TimeZoneOptionName] = this.TimeZone;
}
if (!string.IsNullOrEmpty(this.ScreenResolution))
{
options[ResolutionOptionName] = this.ScreenResolution;
}
if (!string.IsNullOrEmpty(this.SeleniumVersion))
{
options[SeleniumVersionOptionName] = this.SeleniumVersion;
}
List<object> maskCommandData = new List<object>();
if (this.IsMaskingGetValueData)
{
maskCommandData.Add("getValues");
}
if (this.IsMaskingSetValueData)
{
maskCommandData.Add("setValues");
}
if (this.IsMaskingGetCookieData)
{
maskCommandData.Add("getCookies");
}
if (this.IsMaskingSetCookieData)
{
maskCommandData.Add("setCookies");
}
if (maskCommandData.Count > 0)
{
options[MaskCommandsOptionName] = maskCommandData.ToArray();
}
if (this.ChromeSpecificOptions != null)
{
options[ChromeSpecificSettingsOptionName] = this.ChromeSpecificOptions.ToDictionary();
}
if (this.FirefoxSpecificOptions != null)
{
options[FirefoxSpecificSettingsOptionName] = this.FirefoxSpecificOptions.ToDictionary();
}
if (this.InternetExplorerSpecificOptions != null)
{
options[InternetExplorerSpecificSettingsOptionName] = this.InternetExplorerSpecificOptions.ToDictionary();
}
if (this.EdgeSpecificOptions != null)
{
options[EdgeSpecificSettingsOptionName] = this.EdgeSpecificOptions.ToDictionary();
}
if (this.SafariSpecificOptions != null)
{
options[SafariSpecificSettingsOptionName] = this.SafariSpecificOptions.ToDictionary();
}
return options;
}
}
}
BrowserStackSessionOptions browserStackOptions = new BrowserStackSessionOptions();
browserStackOptions.UserName = "userName";
browserStackOptions.AccessKey = "accessKey";
browserStackOptions.OperatingSystem = "Windows";
browserStackOptions.OperatingSystemVersion = "10";
browserStackOptions.ScreenResolution = "1024x768";
browserStackOptions.SessionName = "BrowserStack C-Sharp Sample Test";
ChromeOptions options = new ChromeOptions();
options.BrowserVersion = "70.0";
options.AddAdditionalOption(BrowserStackSessionOptions.BrowserStackOptionsOptionName, browserStackOptions.ToDictionary());
IWebDriver driver = new RemoteWebDriver(new Uri("http://hub-cloud.browserstack.com/wd/hub/"), options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment