/// <summary> /// Allows the specification of Chrome Driver settings /// </summary> /// <param name="chromeSettings">The settings file to be used.</param> public ChromeDriverControl(ChromeSettings chromeSettings) { Options = new ChromeOptions(); if (chromeSettings != null) { Chrome.AndroidDebugBridgePort = chromeSettings.AndroidDebugBridgePort; Chrome.BinaryLocation = chromeSettings.BinaryLocation; Chrome.BufferUsageReportingInterval = chromeSettings.BufferUsageReportingInterval; Chrome.CapabilityList = chromeSettings.CapabilityList; Chrome.DebuggerAddress = chromeSettings.DebuggerAddress; Chrome.EnableTouchEvents = chromeSettings.EnableTouchEvents; Chrome.EnableVerboseLogging = chromeSettings.EnableVerboseLogging; Chrome.ExtensionsList = chromeSettings.ExtensionsList; Chrome.Height = chromeSettings.Height; Chrome.HideCommandPromptWindow = chromeSettings.HideCommandPromptWindow; Chrome.IsCollectingNetworkEvents = chromeSettings.IsCollectingNetworkEvents; Chrome.IsCollectingPageEvents = chromeSettings.IsCollectingPageEvents; Chrome.LeaveBrowserRunning = chromeSettings.LeaveBrowserRunning; Chrome.LocalStatePreferences = chromeSettings.LocalStatePreferences; Chrome.LogPath = chromeSettings.LogPath; Chrome.MinidumpPath = chromeSettings.MinidumpPath; Chrome.PixelRatio = chromeSettings.PixelRatio; Chrome.Port = chromeSettings.Port; Chrome.PortServerAddress = chromeSettings.PortServerAddress; Chrome.SuppressInitialDiagnosticInformation = chromeSettings.SuppressInitialDiagnosticInformation; Chrome.TracingCategories = chromeSettings.TracingCategories; Chrome.UserAgent = chromeSettings.UserAgent; Chrome.UserProfilePreferences = chromeSettings.UserProfilePreferences; Chrome.WhitelistedIPAddresses = chromeSettings.WhitelistedIPAddresses; Chrome.Width = chromeSettings.Width; } }
/// <summary> /// Creates a chrome driver instance in modile emulation mode /// </summary> /// <param name="height">The height of the screen</param> /// <param name="width">The width of the screen</param> /// <param name="userAgent">The user agent returned by the device</param> /// <param name="pixelRatio">The pixel ratio of the screen</param> /// <param name="touch">(Optional Parameter) Whether touch actions are enabled</param> /// <param name="driverSettings">Settings file for the Driver being instantiated.</param> /// <param name="performanceTimings">Whether to obtain performance timings for the browser.</param> public RatDriver(long height, long width, string userAgent, double pixelRatio, [Optional, DefaultParameterValue(false)] bool touch, [Optional, DefaultParameterValue(null)] ChromeSettings driverSettings, [Optional, DefaultParameterValue(false)] bool performanceTimings) { try { RecordPerformance = performanceTimings; if (performanceTimings) { InitialiseRatWatch(performanceTimings); } string driverType = typeof(TWebDriver).Name; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { GetProcesses(driverType, ProcessCollectionTime.InitialisationStart); } if (typeof(TWebDriver) == typeof(ChromeDriver)) { EstablishDriverSettings(driverType); if (!_runTests) { throw new LiberatorOSException(_browserError); } ChromeDriverControl controller = new ChromeDriverControl(driverSettings); Driver = (TWebDriver)controller.StartMobileDriver(height, width, userAgent, pixelRatio, touch); WindowHandles.Add(Driver.CurrentWindowHandle, Driver.Title); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { GetProcesses(driverType, ProcessCollectionTime.InitialisationEnd); } } else { Console.Out.WriteLine("{0} does not currently allow the loading of profiles.", driverType); Console.Out.WriteLine("Please switch to Chrome if mobile emulation is required"); } if (performanceTimings) { RatTimerCollection.StopTimer(EnumTiming.Instantiation); } } catch (Exception ex) { if (ex.GetType() != typeof(LiberatorOSException)) { Console.Out.WriteLine("An unexpected error has been detected."); } HandleErrors(ex); } }