Пример #1
0
        /// <summary>
        /// Adds a <see cref="DriverOptions"/> object to the list of options containing values to be
        /// "first matched" by the remote end.
        /// </summary>
        /// <param name="options">The <see cref="DriverOptions"/> to add to the list of "first matched" options.</param>
        public void AddFirstMatchDriverOption(DriverOptions options)
        {
            if (mustMatchDriverOptions != null)
            {
                DriverOptionsMergeResult mergeResult = mustMatchDriverOptions.GetMergeResult(options);
                if (mergeResult.IsMergeConflict)
                {
                    string msg = string.Format(CultureInfo.InvariantCulture, "You cannot request the same capability in both must-match and first-match capabilities. You are attempting to add a first-match driver options object that defines a capability, '{0}', that is already defined in the must-match driver options.", mergeResult.MergeConflictOptionName);
                    throw new ArgumentException(msg, "options");
                }
            }

            firstMatchOptions.Add(options);
        }
Пример #2
0
        /// <summary>
        /// Compares this <see cref="DriverOptions"/> object with another to see if there
        /// are merge conflicts between them.
        /// </summary>
        /// <param name="other">The <see cref="DriverOptions"/> object to compare with.</param>
        /// <returns>A <see cref="DriverOptionsMergeResult"/> object containing the status of the attempted merge.</returns>
        public virtual DriverOptionsMergeResult GetMergeResult(DriverOptions other)
        {
            DriverOptionsMergeResult result = new DriverOptionsMergeResult();

            if (this.browserName != null && other.BrowserName != null)
            {
                result.IsMergeConflict         = true;
                result.MergeConflictOptionName = "BrowserName";
                return(result);
            }

            if (this.browserVersion != null && other.BrowserVersion != null)
            {
                result.IsMergeConflict         = true;
                result.MergeConflictOptionName = "BrowserVersion";
                return(result);
            }

            if (this.platformName != null && other.PlatformName != null)
            {
                result.IsMergeConflict         = true;
                result.MergeConflictOptionName = "PlatformName";
                return(result);
            }

            if (this.proxy != null && other.Proxy != null)
            {
                result.IsMergeConflict         = true;
                result.MergeConflictOptionName = "Proxy";
                return(result);
            }

            if (this.unhandledPromptBehavior != UnhandledPromptBehavior.Default && other.UnhandledPromptBehavior != UnhandledPromptBehavior.Default)
            {
                result.IsMergeConflict         = true;
                result.MergeConflictOptionName = "UnhandledPromptBehavior";
                return(result);
            }

            if (this.pageLoadStrategy != PageLoadStrategy.Default && other.PageLoadStrategy != PageLoadStrategy.Default)
            {
                result.IsMergeConflict         = true;
                result.MergeConflictOptionName = "PageLoadStrategy";
                return(result);
            }

            return(result);
        }
Пример #3
0
        /// <summary>
        /// Adds a <see cref="DriverOptions"/> object containing values that must be matched
        /// by the remote end to successfully create a session.
        /// </summary>
        /// <param name="options">The <see cref="DriverOptions"/> that must be matched by
        /// the remote end to successfully create a session.</param>
        public void SetMustMatchDriverOptions(DriverOptions options)
        {
            if (this.firstMatchOptions.Count > 0)
            {
                int driverOptionIndex = 0;
                foreach (DriverOptions firstMatchOption in this.firstMatchOptions)
                {
                    DriverOptionsMergeResult mergeResult = firstMatchOption.GetMergeResult(options);
                    if (mergeResult.IsMergeConflict)
                    {
                        string msg = string.Format(CultureInfo.InvariantCulture, "You cannot request the same capability in both must-match and first-match capabilities. You are attempting to add a must-match driver options object that defines a capability, '{0}', that is already defined in the first-match driver options with index {1}.", mergeResult.MergeConflictOptionName, driverOptionIndex);
                        throw new ArgumentException(msg, "options");
                    }

                    driverOptionIndex++;
                }
            }

            this.mustMatchDriverOptions = options;
        }