"Fossies" - the Fresh Open Source Software Archive

Member "selenium-selenium-4.8.1/dotnet/src/webdriver/IE/InternetExplorerOptions.cs" (17 Feb 2023, 21207 Bytes) of package /linux/www/selenium-selenium-4.8.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C# source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "InternetExplorerOptions.cs" see the Fossies "Dox" file reference documentation.

    1 // <copyright file="InternetExplorerOptions.cs" company="WebDriver Committers">
    2 // Licensed to the Software Freedom Conservancy (SFC) under one
    3 // or more contributor license agreements. See the NOTICE file
    4 // distributed with this work for additional information
    5 // regarding copyright ownership. The SFC licenses this file
    6 // to you under the Apache License, Version 2.0 (the "License");
    7 // you may not use this file except in compliance with the License.
    8 // You may obtain a copy of the License at
    9 //
   10 //     http://www.apache.org/licenses/LICENSE-2.0
   11 //
   12 // Unless required by applicable law or agreed to in writing, software
   13 // distributed under the License is distributed on an "AS IS" BASIS,
   14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   15 // See the License for the specific language governing permissions and
   16 // limitations under the License.
   17 // </copyright>
   18 
   19 using System;
   20 using System.Collections.Generic;
   21 using System.Globalization;
   22 using OpenQA.Selenium.Remote;
   23 
   24 namespace OpenQA.Selenium.IE
   25 {
   26     /// <summary>
   27     /// Specifies the scroll behavior of elements scrolled into view in the IE driver.
   28     /// </summary>
   29     public enum InternetExplorerElementScrollBehavior
   30     {
   31         /// <summary>
   32         /// Indicates the behavior is unspecified.
   33         /// </summary>
   34         Default,
   35 
   36         /// <summary>
   37         /// Scrolls elements to align with the top of the viewport.
   38         /// </summary>
   39         Top,
   40 
   41         /// <summary>
   42         /// Scrolls elements to align with the bottom of the viewport.
   43         /// </summary>
   44         Bottom
   45     }
   46 
   47     /// <summary>
   48     /// Class to manage options specific to <see cref="InternetExplorerDriver"/>
   49     /// </summary>
   50     /// <example>
   51     /// <code>
   52     /// InternetExplorerOptions options = new InternetExplorerOptions();
   53     /// options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
   54     /// </code>
   55     /// <para></para>
   56     /// <para>For use with InternetExplorerDriver:</para>
   57     /// <para></para>
   58     /// <code>
   59     /// InternetExplorerDriver driver = new InternetExplorerDriver(options);
   60     /// </code>
   61     /// <para></para>
   62     /// <para>For use with RemoteWebDriver:</para>
   63     /// <para></para>
   64     /// <code>
   65     /// RemoteWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), options.ToCapabilities());
   66     /// </code>
   67     /// </example>
   68     public class InternetExplorerOptions : DriverOptions
   69     {
   70         /// <summary>
   71         /// Gets the name of the capability used to store IE options in
   72         /// an <see cref="ICapabilities"/> object.
   73         /// </summary>
   74         public static readonly string Capability = "se:ieOptions";
   75 
   76         private const string BrowserNameValue = "internet explorer";
   77 
   78         private const string IgnoreProtectedModeSettingsCapability = "ignoreProtectedModeSettings";
   79         private const string IgnoreZoomSettingCapability = "ignoreZoomSetting";
   80         private const string InitialBrowserUrlCapability = "initialBrowserUrl";
   81         private const string EnablePersistentHoverCapability = "enablePersistentHover";
   82         private const string ElementScrollBehaviorCapability = "elementScrollBehavior";
   83         private const string RequireWindowFocusCapability = "requireWindowFocus";
   84         private const string BrowserAttachTimeoutCapability = "browserAttachTimeout";
   85         private const string BrowserCommandLineSwitchesCapability = "ie.browserCommandLineSwitches";
   86         private const string ForceCreateProcessApiCapability = "ie.forceCreateProcessApi";
   87         private const string UsePerProcessProxyCapability = "ie.usePerProcessProxy";
   88         private const string EnsureCleanSessionCapability = "ie.ensureCleanSession";
   89         private const string ForceShellWindowsApiCapability = "ie.forceShellWindowsApi";
   90         private const string FileUploadDialogTimeoutCapability = "ie.fileUploadDialogTimeout";
   91         private const string EnableFullPageScreenshotCapability = "ie.enableFullPageScreenshot";
   92         private const string EdgeExecutablePathCapability = "ie.edgepath";
   93         private const string LegacyFileUploadDialogHandlingCapability = "ie.useLegacyFileUploadDialogHandling";
   94         private const string AttachToEdgeChromeCapability = "ie.edgechromium";
   95 
   96         private bool ignoreProtectedModeSettings;
   97         private bool ignoreZoomLevel;
   98         private bool enableNativeEvents = true;
   99         private bool requireWindowFocus;
  100         private bool enablePersistentHover = true;
  101         private bool forceCreateProcessApi;
  102         private bool forceShellWindowsApi;
  103         private bool usePerProcessProxy;
  104         private bool ensureCleanSession;
  105         private bool enableFullPageScreenshot = true;
  106         private bool legacyFileUploadDialogHandling;
  107         private bool attachToEdgeChrome;
  108         private TimeSpan browserAttachTimeout = TimeSpan.MinValue;
  109         private TimeSpan fileUploadDialogTimeout = TimeSpan.MinValue;
  110         private string initialBrowserUrl = string.Empty;
  111         private string browserCommandLineArguments = string.Empty;
  112         private string edgeExecutablePath = string.Empty;
  113         private InternetExplorerElementScrollBehavior elementScrollBehavior = InternetExplorerElementScrollBehavior.Default;
  114         private Dictionary<string, object> additionalInternetExplorerOptions = new Dictionary<string, object>();
  115 
  116         /// <summary>
  117         /// Initializes a new instance of the <see cref="InternetExplorerOptions"/> class.
  118         /// </summary>
  119         public InternetExplorerOptions() : base()
  120         {
  121             this.BrowserName = BrowserNameValue;
  122             this.PlatformName = "windows";
  123             this.AddKnownCapabilityName(Capability, "current InterentExplorerOptions class instance");
  124             this.AddKnownCapabilityName(IgnoreProtectedModeSettingsCapability, "IntroduceInstabilityByIgnoringProtectedModeSettings property");
  125             this.AddKnownCapabilityName(IgnoreZoomSettingCapability, "IgnoreZoomLevel property");
  126             this.AddKnownCapabilityName(CapabilityType.HasNativeEvents, "EnableNativeEvents property");
  127             this.AddKnownCapabilityName(InitialBrowserUrlCapability, "InitialBrowserUrl property");
  128             this.AddKnownCapabilityName(ElementScrollBehaviorCapability, "ElementScrollBehavior property");
  129             this.AddKnownCapabilityName(CapabilityType.UnexpectedAlertBehavior, "UnhandledPromptBehavior property");
  130             this.AddKnownCapabilityName(EnablePersistentHoverCapability, "EnablePersistentHover property");
  131             this.AddKnownCapabilityName(RequireWindowFocusCapability, "RequireWindowFocus property");
  132             this.AddKnownCapabilityName(BrowserAttachTimeoutCapability, "BrowserAttachTimeout property");
  133             this.AddKnownCapabilityName(ForceCreateProcessApiCapability, "ForceCreateProcessApi property");
  134             this.AddKnownCapabilityName(ForceShellWindowsApiCapability, "ForceShellWindowsApi property");
  135             this.AddKnownCapabilityName(BrowserCommandLineSwitchesCapability, "BrowserComaandLineArguments property");
  136             this.AddKnownCapabilityName(UsePerProcessProxyCapability, "UsePerProcessProxy property");
  137             this.AddKnownCapabilityName(EnsureCleanSessionCapability, "EnsureCleanSession property");
  138             this.AddKnownCapabilityName(FileUploadDialogTimeoutCapability, "FileUploadDialogTimeout property");
  139             this.AddKnownCapabilityName(EnableFullPageScreenshotCapability, "EnableFullPageScreenshot property");
  140             this.AddKnownCapabilityName(LegacyFileUploadDialogHandlingCapability, "LegacyFileUploadDialogHanlding property");
  141             this.AddKnownCapabilityName(AttachToEdgeChromeCapability, "AttachToEdgeChrome property");
  142             this.AddKnownCapabilityName(EdgeExecutablePathCapability, "EdgeExecutablePath property");
  143         }
  144 
  145         /// <summary>
  146         /// Gets or sets a value indicating whether to ignore the settings of the Internet Explorer Protected Mode.
  147         /// </summary>
  148         public bool IntroduceInstabilityByIgnoringProtectedModeSettings
  149         {
  150             get { return this.ignoreProtectedModeSettings; }
  151             set { this.ignoreProtectedModeSettings = value; }
  152         }
  153 
  154         /// <summary>
  155         /// Gets or sets a value indicating whether to ignore the zoom level of Internet Explorer .
  156         /// </summary>
  157         public bool IgnoreZoomLevel
  158         {
  159             get { return this.ignoreZoomLevel; }
  160             set { this.ignoreZoomLevel = value; }
  161         }
  162 
  163         /// <summary>
  164         /// Gets or sets a value indicating whether to use native events in interacting with elements.
  165         /// </summary>
  166         public bool EnableNativeEvents
  167         {
  168             get { return this.enableNativeEvents; }
  169             set { this.enableNativeEvents = value; }
  170         }
  171 
  172         /// <summary>
  173         /// Gets or sets a value indicating whether to require the browser window to have focus before interacting with elements.
  174         /// </summary>
  175         public bool RequireWindowFocus
  176         {
  177             get { return this.requireWindowFocus; }
  178             set { this.requireWindowFocus = value; }
  179         }
  180 
  181         /// <summary>
  182         /// Gets or sets the initial URL displayed when IE is launched. If not set, the browser launches
  183         /// with the internal startup page for the WebDriver server.
  184         /// </summary>
  185         /// <remarks>
  186         /// By setting the  <see cref="IntroduceInstabilityByIgnoringProtectedModeSettings"/> to <see langword="true"/>
  187         /// and this property to a correct URL, you can launch IE in the Internet Protected Mode zone. This can be helpful
  188         /// to avoid the flakiness introduced by ignoring the Protected Mode settings. Nevertheless, setting Protected Mode
  189         /// zone settings to the same value in the IE configuration is the preferred method.
  190         /// </remarks>
  191         public string InitialBrowserUrl
  192         {
  193             get { return this.initialBrowserUrl; }
  194             set { this.initialBrowserUrl = value; }
  195         }
  196 
  197         /// <summary>
  198         /// Gets or sets the value for describing how elements are scrolled into view in the IE driver. Defaults
  199         /// to scrolling the element to the top of the viewport.
  200         /// </summary>
  201         public InternetExplorerElementScrollBehavior ElementScrollBehavior
  202         {
  203             get { return this.elementScrollBehavior; }
  204             set { this.elementScrollBehavior = value; }
  205         }
  206 
  207         /// <summary>
  208         /// Gets or sets a value indicating whether to enable persistently sending WM_MOUSEMOVE messages
  209         /// to the IE window during a mouse hover.
  210         /// </summary>
  211         public bool EnablePersistentHover
  212         {
  213             get { return this.enablePersistentHover; }
  214             set { this.enablePersistentHover = value; }
  215         }
  216 
  217         /// <summary>
  218         /// Gets or sets the amount of time the driver will attempt to look for a newly launched instance
  219         /// of Internet Explorer.
  220         /// </summary>
  221         public TimeSpan BrowserAttachTimeout
  222         {
  223             get { return this.browserAttachTimeout; }
  224             set { this.browserAttachTimeout = value; }
  225         }
  226 
  227         /// <summary>
  228         /// Gets or sets the amount of time the driver will attempt to look for the file selection
  229         /// dialog when attempting to upload a file.
  230         /// </summary>
  231         public TimeSpan FileUploadDialogTimeout
  232         {
  233             get { return this.fileUploadDialogTimeout; }
  234             set { this.fileUploadDialogTimeout = value; }
  235         }
  236 
  237         /// <summary>
  238         /// Gets or sets a value indicating whether to force the use of the Windows CreateProcess API
  239         /// when launching Internet Explorer. The default value is <see langword="false"/>.
  240         /// </summary>
  241         public bool ForceCreateProcessApi
  242         {
  243             get { return this.forceCreateProcessApi; }
  244             set { this.forceCreateProcessApi = value; }
  245         }
  246 
  247         /// <summary>
  248         /// Gets or sets a value indicating whether to force the use of the Windows ShellWindows API
  249         /// when attaching to Internet Explorer. The default value is <see langword="false"/>.
  250         /// </summary>
  251         public bool ForceShellWindowsApi
  252         {
  253             get { return this.forceShellWindowsApi; }
  254             set { this.forceShellWindowsApi = value; }
  255         }
  256 
  257         /// <summary>
  258         /// Gets or sets the command line arguments used in launching Internet Explorer when the
  259         /// Windows CreateProcess API is used. This property only has an effect when the
  260         /// <see cref="ForceCreateProcessApi"/> is <see langword="true"/>.
  261         /// </summary>
  262         public string BrowserCommandLineArguments
  263         {
  264             get { return this.browserCommandLineArguments; }
  265             set { this.browserCommandLineArguments = value; }
  266         }
  267 
  268         /// <summary>
  269         /// Gets or sets a value indicating whether to use the supplied <see cref="Proxy"/>
  270         /// settings on a per-process basis, not updating the system installed proxy setting.
  271         /// This property is only valid when setting a <see cref="Proxy"/>, where the
  272         /// <see cref="OpenQA.Selenium.Proxy.Kind"/> property is either <see cref="ProxyKind.Direct"/>,
  273         /// <see cref="ProxyKind.System"/>, or <see cref="ProxyKind.Manual"/>, and is
  274         /// otherwise ignored. Defaults to <see langword="false"/>.
  275         /// </summary>
  276         public bool UsePerProcessProxy
  277         {
  278             get { return this.usePerProcessProxy; }
  279             set { this.usePerProcessProxy = value; }
  280         }
  281 
  282         /// <summary>
  283         /// Gets or sets a value indicating whether to clear the Internet Explorer cache
  284         /// before launching the browser. When set to <see langword="true"/>, clears the
  285         /// system cache for all instances of Internet Explorer, even those already running
  286         /// when the driven instance is launched. Defaults to <see langword="false"/>.
  287         /// </summary>
  288         public bool EnsureCleanSession
  289         {
  290             get { return this.ensureCleanSession; }
  291             set { this.ensureCleanSession = value; }
  292         }
  293 
  294         /// <summary>
  295         /// Gets or sets a value indicating whether to use the legacy handling for file upload dialogs.
  296         /// </summary>
  297         public bool LegacyFileUploadDialogHanlding
  298         {
  299             get { return this.legacyFileUploadDialogHandling; }
  300             set { this.legacyFileUploadDialogHandling = value; }
  301         }
  302 
  303         /// <summary>
  304         /// Gets or sets a value indicating whether to attach to Edge Chrome browser.
  305         /// </summary>
  306         public bool AttachToEdgeChrome
  307         {
  308             get { return this.attachToEdgeChrome; }
  309             set { this.attachToEdgeChrome = value; }
  310         }
  311 
  312         /// <summary>
  313         /// Gets or sets the path to the Edge Browser Executable.
  314         /// </summary>
  315         public string EdgeExecutablePath
  316         {
  317             get { return this.edgeExecutablePath; }
  318             set { this.edgeExecutablePath = value; }
  319         }
  320 
  321         /// <summary>
  322         /// Provides a means to add additional capabilities not yet added as type safe options
  323         /// for the Internet Explorer driver.
  324         /// </summary>
  325         /// <param name="optionName">The name of the capability to add.</param>
  326         /// <param name="optionValue">The value of the capability to add.</param>
  327         /// <exception cref="ArgumentException">
  328         /// thrown when attempting to add a capability for which there is already a type safe option, or
  329         /// when <paramref name="optionName"/> is <see langword="null"/> or the empty string.
  330         /// </exception>
  331         /// <remarks>Calling <see cref="AddAdditionalInternetExplorerOption(string, object)"/>
  332         /// where <paramref name="optionName"/> has already been added will overwrite the
  333         /// existing value with the new value in <paramref name="optionValue"/>.
  334         /// Calling this method adds capabilities to the IE-specific options object passed to
  335         /// IEDriverServer.exe (property name 'se:ieOptions').</remarks>
  336         public void AddAdditionalInternetExplorerOption(string optionName, object optionValue)
  337         {
  338             this.ValidateCapabilityName(optionName);
  339             this.additionalInternetExplorerOptions[optionName] = optionValue;
  340         }
  341 
  342         /// <summary>
  343         /// Returns DesiredCapabilities for IE with these options included as
  344         /// capabilities. This copies the options. Further changes will not be
  345         /// reflected in the returned capabilities.
  346         /// </summary>
  347         /// <returns>The DesiredCapabilities for IE with these options.</returns>
  348         public override ICapabilities ToCapabilities()
  349         {
  350             IWritableCapabilities capabilities = this.GenerateDesiredCapabilities(true);
  351 
  352             Dictionary<string, object> internetExplorerOptions = this.BuildInternetExplorerOptionsDictionary();
  353             capabilities.SetCapability(InternetExplorerOptions.Capability, internetExplorerOptions);
  354 
  355             return capabilities.AsReadOnly();
  356         }
  357 
  358         private Dictionary<string, object> BuildInternetExplorerOptionsDictionary()
  359         {
  360             Dictionary<string, object> internetExplorerOptionsDictionary = new Dictionary<string, object>();
  361             internetExplorerOptionsDictionary[CapabilityType.HasNativeEvents] = this.enableNativeEvents;
  362             internetExplorerOptionsDictionary[EnablePersistentHoverCapability] = this.enablePersistentHover;
  363 
  364             if (this.requireWindowFocus)
  365             {
  366                 internetExplorerOptionsDictionary[RequireWindowFocusCapability] = true;
  367             }
  368 
  369             if (this.ignoreProtectedModeSettings)
  370             {
  371                 internetExplorerOptionsDictionary[IgnoreProtectedModeSettingsCapability] = true;
  372             }
  373 
  374             if (this.ignoreZoomLevel)
  375             {
  376                 internetExplorerOptionsDictionary[IgnoreZoomSettingCapability] = true;
  377             }
  378 
  379             if (!string.IsNullOrEmpty(this.initialBrowserUrl))
  380             {
  381                 internetExplorerOptionsDictionary[InitialBrowserUrlCapability] = this.initialBrowserUrl;
  382             }
  383 
  384             if (this.elementScrollBehavior != InternetExplorerElementScrollBehavior.Default)
  385             {
  386                 if (this.elementScrollBehavior == InternetExplorerElementScrollBehavior.Bottom)
  387                 {
  388                     internetExplorerOptionsDictionary[ElementScrollBehaviorCapability] = 1;
  389                 }
  390                 else
  391                 {
  392                     internetExplorerOptionsDictionary[ElementScrollBehaviorCapability] = 0;
  393                 }
  394             }
  395 
  396             if (this.browserAttachTimeout != TimeSpan.MinValue)
  397             {
  398                 internetExplorerOptionsDictionary[BrowserAttachTimeoutCapability] = Convert.ToInt32(this.browserAttachTimeout.TotalMilliseconds);
  399             }
  400 
  401             if (this.fileUploadDialogTimeout != TimeSpan.MinValue)
  402             {
  403                 internetExplorerOptionsDictionary[FileUploadDialogTimeoutCapability] = Convert.ToInt32(this.fileUploadDialogTimeout.TotalMilliseconds);
  404             }
  405 
  406             if (this.forceCreateProcessApi)
  407             {
  408                 internetExplorerOptionsDictionary[ForceCreateProcessApiCapability] = true;
  409                 if (!string.IsNullOrEmpty(this.browserCommandLineArguments))
  410                 {
  411                     internetExplorerOptionsDictionary[BrowserCommandLineSwitchesCapability] = this.browserCommandLineArguments;
  412                 }
  413             }
  414 
  415             if (this.forceShellWindowsApi)
  416             {
  417                 internetExplorerOptionsDictionary[ForceShellWindowsApiCapability] = true;
  418             }
  419 
  420             if (this.Proxy != null)
  421             {
  422                 internetExplorerOptionsDictionary[UsePerProcessProxyCapability] = this.usePerProcessProxy;
  423             }
  424 
  425             if (this.ensureCleanSession)
  426             {
  427                 internetExplorerOptionsDictionary[EnsureCleanSessionCapability] = true;
  428             }
  429 
  430             if (!this.enableFullPageScreenshot)
  431             {
  432                 internetExplorerOptionsDictionary[EnableFullPageScreenshotCapability] = false;
  433             }
  434 
  435             if (this.legacyFileUploadDialogHandling)
  436             {
  437                 internetExplorerOptionsDictionary[LegacyFileUploadDialogHandlingCapability] = true;
  438             }
  439 
  440             if (this.attachToEdgeChrome)
  441             {
  442                 internetExplorerOptionsDictionary[AttachToEdgeChromeCapability] = true;
  443             }
  444 
  445             if (!string.IsNullOrEmpty(this.edgeExecutablePath))
  446             {
  447                 internetExplorerOptionsDictionary[EdgeExecutablePathCapability] = this.edgeExecutablePath;
  448             }
  449 
  450             foreach (KeyValuePair<string, object> pair in this.additionalInternetExplorerOptions)
  451             {
  452                 internetExplorerOptionsDictionary[pair.Key] = pair.Value;
  453             }
  454 
  455             return internetExplorerOptionsDictionary;
  456         }
  457     }
  458 }