public void Initialize(string cssSelector, string markerClass)
        {
            _cssSelector = cssSelector;
            _markerClass = markerClass;

            ActualConstraint = new MarkerConstraint(markerClass);
        }
 /// <summary>
 /// Gets previously saved constraint-specific data from the context.
 /// </summary>
 /// <param name="constraint">The constraint that wishes to retrieve its state</param>
 /// <returns>The saved data, or null if none saved</returns>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="constraint"/> is null</exception>
 public object GetData(Constraint constraint)
 {
     object value;
     if (data != null && data.TryGetValue(constraint, out value))
         return value;
     return null;
 }
Example #3
0
        /// <summary>
        /// Creates a new NOT constraint.
        /// </summary>
        /// <param name="inner">The inner constraint</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="inner"/> is null</exception>
        public NotConstraint(Constraint inner) 
		{
            if (inner == null)
                throw new ArgumentNullException("inner");

            this.inner = inner;
		}
        /// <summary>
        /// Creates a new finder filtered by an additional constraint.
        /// </summary>
        /// <param name="constraint">The additional constraint</param>
        /// <returns>The filtered element finder</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="constraint"/> is null</exception>
        public ElementFinder Filter(Constraint constraint)
        {
            if (constraint == null)
                throw new ArgumentNullException("constraint");

            return FilterImpl(constraint);
        }
        public IE TryFindIe(Constraint findBy, SimpleTimer timer)
        {
            var action = new TryFuncUntilTimeOut(timer)
            {
                SleepTime = TimeSpan.FromMilliseconds(500)
            };

            return action.Try(() => FindIEPartiallyInitialized(findBy));
        }
        /// <summary>
        /// Creates a new OR constraint.
        /// </summary>
        /// <param name="first">The first constraint</param>
        /// <param name="second">The second constraint</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="first"/> or <paramref name="second"/> is null</exception>
        public OrConstraint(Constraint first, Constraint second) 
		{
            if (first == null)
                throw new ArgumentNullException("first");
            if (second == null)
                throw new ArgumentNullException("second");

            this.first = first;
            this.second = second;
        }
        /// <summary>
        /// Creates an element finder.
        /// </summary>
        /// <param name="domContainer">The DOM container</param>
        /// <param name="factory">The factory to get the element(s) to search in</param>
        /// <param name="elementTags">The element tags considered by the finder, or null if all tags considered</param>
        /// <param name="constraint">The constraint used by the finder to filter elements, or null if no additional constraint</param>
        public NativeElementFinder(NativeElementCollectionFactory factory, DomContainer domContainer, IList<ElementTag> elementTags, Constraint constraint)
            : base(elementTags, constraint)
        {
            if (factory == null)
                throw new ArgumentNullException("factory");
            if (domContainer == null)
                throw new ArgumentNullException("domContainer");

            this.factory = factory;
            this.domContainer = domContainer;
        }
        /// <summary>
        /// Gets the id hint. Only returns an Id if <paramref name="constraint"/> is an <see cref="AttributeConstraint"/> on an exact Id or
        /// if the <paramref name="constraint"/> is an <see cref="AndConstraint"/> with an <see cref="AttributeConstraint"/> on an exact Id 
        /// and an <see cref="AnyConstraint"/>.
        /// </summary>
        /// <param name="constraint">The constraint to get the id Hint from.</param>
        /// <returns></returns>
        public static string GetIdHint(Constraint constraint)
        {
            var andConstraint = constraint as AndConstraint;
            if (andConstraint != null)
            {
                var left = new IdHinter(andConstraint.First);
                var right = new IdHinter(andConstraint.Second);

                return left.GetIdHint(right);
            }

            return new IdHinter(constraint).GetIdHint();
        }
        public IE FindIEPartiallyInitialized(Constraint findBy)
        {
            var allBrowsers = new ShellWindows2();

            var context = new ConstraintContext();
            foreach (IWebBrowser2 browser in allBrowsers)
            {
                var ie = CreateBrowserInstance(new IEBrowser(browser));
                if (ie.Matches(findBy, context))
                    return ie;
            }

            return null;
        }
 /// <summary>
 /// Saves constraint-specific data in the context.
 /// </summary>
 /// <param name="constraint">The constraint that wishes to store its state</param>
 /// <param name="value">The value to be stored, or null if none</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="constraint"/> is null</exception>
 public void SetData(Constraint constraint, object value)
 {
     if (value == null)
     {
         if (data != null)
             data.Remove(constraint);
     }
     else
     {
         if (data == null)
             data = new Dictionary<Constraint, object>();
         data[constraint] = value;
     }
 }
        public Browser Find(Constraint findBy, int timeout, bool waitForComplete)
        {
        	Logger.LogAction((LogFunction log) => { log("Busy finding Internet Explorer matching constraint {0}", findBy); });

            var timer = new SimpleTimer(TimeSpan.FromSeconds(timeout));

            var ie = TryFindIe(findBy, timer);
            
            if (ie != null)
            {
                return FinishInitializationAndWaitForComplete(ie, timer, waitForComplete);
            }

            throw new BrowserNotFoundException("IE", findBy.ToString(), timeout);
        }
Example #12
0
        private static void SelectByTextOrValueMultiple(this SelectList selectList, Constraint constraint)
        {
            // This is copied from SelectList.SelectMultiple
            var options = selectList.Options.Filter(constraint);
            if (options.Count == 0)
                throw new SelectListItemNotFoundException(constraint.ToString(), selectList);

            foreach (var option in options)
            {
                if (option.Selected) continue;
                option.SetAttributeValue("selected", "true");
            }

            selectList.FireEvent("onchange");
        }
Example #13
0
        public Browser Find(Constraint findBy, int timeout, bool waitForComplete)
        {
            Logger.LogAction("Busy finding FireFox matching constraint {0}", findBy);

            var action = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(timeout)) { SleepTime = TimeSpan.FromMilliseconds(500) };
            var fireFox = action.Try(() => FindFireFox(findBy));

            if (fireFox != null)
            {
                if (waitForComplete) fireFox.WaitForComplete();
                return fireFox;
            }

            throw new BrowserNotFoundException("FireFox", findBy.ToString(), timeout);
        }
Example #14
0
 public WatiNWindow (Constraint windowHandle)
 {
     this.windowHandle = windowHandle;
     try
     {
         if (!WatiN.Core.Browser.Exists<IE>(windowHandle))
             throw new MissingWindowException("No such window found: " + windowHandle);
         
         browser = WatiN.Core.Browser.AttachTo<IE>(windowHandle);
     }
     catch (WatiN.Core.Exceptions.BrowserNotFoundException)
     {
         throw new MissingWindowException("No such window found: " + windowHandle);
     }
 }
        public FireFox FindFireFox(Constraint findBy)
        {
            var clientPort = FireFox.GetClientPort();
            clientPort.ConnectToExisting();
            
            var ffBrowser = new FFBrowser(clientPort);
            var windowCount = ffBrowser.WindowCount;

            for (var i = 0; i < windowCount; i++)
            {
                ((FireFoxClientPort)ffBrowser.ClientPort).DefineDefaultJSVariablesForWindow(i);
                ffBrowser.ClientPort.InitializeDocument();
                var firefox = CreateBrowserInstance(ffBrowser);
                if (firefox.Matches(findBy)) 
                    return firefox;
            }

            clientPort.CloseConnection();

            return null;
        }
Example #16
0
		private HtmlDialog FindHtmlDialog(Constraint findBy, int timeout)
		{
			Logger.LogAction("Busy finding HTMLDialog matching criteria: {0}", findBy);

            var action = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(timeout))
            {
                SleepTime = TimeSpan.FromMilliseconds(500)
            };

            var result = action.Try(() => HtmlDialogs.First(findBy));
            
            if (result == null)
            {
                throw new HtmlDialogNotFoundException(findBy.ToString(), timeout);
            }
            
            return result;
		}
Example #17
0
		/// <summary>
		/// Find a HtmlDialog by an attribute within the given <paramref name="timeout" /> period.
		/// Currently Find.ByUrl and Find.ByTitle are supported.
		/// </summary>
		/// <param name="findBy">The url of the html page shown in the dialog</param>
		/// <param name="timeout">Number of seconds before the search times out.</param>
		public HtmlDialog HtmlDialog(Constraint findBy, int timeout)
		{
			return FindHtmlDialog(findBy, timeout);
		}
Example #18
0
		/// <summary>
		/// Find a HtmlDialog by an attribute. Currently 
		/// Find.ByUrl and Find.ByTitle are supported.
		/// </summary>
		/// <param name="findBy">The url of the html page shown in the dialog</param>
		public HtmlDialog HtmlDialog(Constraint findBy)
		{
			return FindHtmlDialog(findBy, Settings.AttachToBrowserTimeOut);
		}
 private IdHinter(Constraint constraint)
 {
     _constraint = constraint ?? Find.Any;
     AsAttributeConstraint = constraint as AttributeConstraint;
 }
 /// <summary>
 /// If the constraint can only match on element with a particular id, returns the id,
 /// otherwise returns null.
 /// </summary>
 /// <returns>The id or null if the constraint could match elements with no particular id</returns>
 protected virtual string GetElementIdHint(Constraint constraint)
 {
     return IdHinter.GetIdHint(constraint);
 }
Example #21
0
 protected override ElementFinder FilterImpl(Constraint findBy)
 {
     throw new NotImplementedException("Didn't expect filtering on static element");
 }
 /// <inheritdoc />
 protected override ElementFinder FilterImpl(Constraint findBy)
 {
     return new NativeElementFinder(factory, domContainer, ElementTags, Constraint & findBy);
 }
 /// <summary>
 /// Creates an element finder.
 /// </summary>
 /// <param name="elementTags">The element tags considered by the finder, or null if all tags considered</param>
 /// <param name="findBy">The constraint used by the finder to filter elements, or null if no additional constraint</param>
 public ElementFinder(IList<ElementTag> elementTags, Constraint findBy)
 {
     this.elementTags = new ReadOnlyCollection<ElementTag>(elementTags ?? new[] { ElementTag.Any });
     this.findBy = findBy ?? Find.Any;
 }
 /// <summary>
 /// Creates a new finder filtered by an additional constraint.
 /// </summary>
 /// <param name="findBy">The additional constraint, not null</param>
 /// <returns>The filtered element finder</returns>
 public abstract ElementFinder FilterImpl(Constraint findBy);
Example #25
0
 public static Chrome AttachToChrome(Constraint findBy)
 {
     throw new System.NotImplementedException();
 }
 public bool Exists(Constraint constraint)
 {
     return null != FindIEPartiallyInitialized(constraint);
 }
Example #27
0
		public ReEntryException(Constraint constraint) : base(CreateMessage(constraint)) {}
        /// <summary>
        /// Combines this constraint with another one to produce a new constraint that is satisfied only when
        /// either (or both) constraint is satisfied.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The operation is short-circuiting: if the first constraint is satisfied for
        /// a given value then the second constraint is not evaluated.
        /// </para>
        /// </remarks>
        /// <param name="constraint">The other constraint</param>
        /// <returns>The combined constraint</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="constraint"/> is null</exception>
        /// <seealso cref="And"/>
        public Constraint Or(Constraint constraint)
        {
            if (constraint == null)
                throw new ArgumentNullException("constraint");

            return new OrConstraint(this, constraint);
        }
Example #29
0
		private static string CreateMessage(Constraint constraint)
		{
			return string.Format(Resources.ReEntryException_MessageFormat, constraint.GetType(), constraint);
		}
 private static void Combine(ref Constraint constraint, Constraint otherConstraint)
 {
     if (otherConstraint != null)
     {
         constraint = constraint != null ? constraint & otherConstraint : otherConstraint;
     }
 }