Esempio n. 1
0
        protected internal override void Execute <TOwner>(TriggerContext <TOwner> context)
        {
            string message = BuildReportMessage(context) ?? DefaultReportMessage;
            string script  = BuildScript(context);

            context.Log.Start(message, LogLevel.Trace);

            bool isCompleted = context.Driver.Try(TimeSpan.FromSeconds(Timeout), TimeSpan.FromSeconds(RetryInterval)).Until(
                x => (bool)context.Driver.ExecuteScript(script));

            if (!isCompleted)
            {
                StringBuilder errorMessageBuilder = new StringBuilder("Timed out waiting for script.");

                if (message != DefaultReportMessage)
                {
                    errorMessageBuilder.Append(" ").Append(message);

                    if (!message.EndsWith("."))
                    {
                        errorMessageBuilder.Append(".");
                    }
                }

                throw new TimeoutException(errorMessageBuilder.ToString());
            }

            context.Log.EndSection();
        }
Esempio n. 2
0
        protected internal override void Execute <TOwner>(TriggerContext <TOwner> context)
        {
            context.Log.Start("Wait for AngularJS AJAX execution", LogLevel.Trace);

            bool isCompleted = context.Driver.Try().Until(
                x => (bool)context.Driver.ExecuteScript(@"
try {
    if (document.readyState !== 'complete') {
        return false;
    }
    if (window.angular) {
        var injector = window.angular.element('body').injector();
    
        var $rootScope = injector.get('$rootScope');
        var $http = injector.get('$http');

        if ($rootScope.$$phase === '$apply' || $rootScope.$$phase === '$digest' || $http.pendingRequests.length !== 0) {
            return false;
        }
    }
    return true;
} catch (err) {
  return false;
}"));

            context.Log.EndSection();

            if (!isCompleted)
            {
                throw new TimeoutException("Timed out waiting for AngularJS AJAX call to complete.");
            }
        }
Esempio n. 3
0
 protected internal override void Execute <TOwner>(TriggerContext <TOwner> context)
 {
     if (!string.IsNullOrEmpty(Keys))
     {
         context.Log.ExecuteSection(
             new PressKeysLogSection((UIComponent)context.Component, Keys),
             (Action)(() => context.Driver.Perform(x => x.SendKeys(Keys))));
     }
 }
Esempio n. 4
0
        protected internal override void Execute <TOwner>(TriggerContext <TOwner> context)
        {
            ScopeSource actualScopeSource = scopeSource ?? context.Component.ScopeSource;
            IWebElement scopeElement      = actualScopeSource.GetScopeElement(context.Component);

            WaitUnit[] waitUnits = GetWaitUnits(Until);

            Wait(scopeElement, waitUnits);
        }
Esempio n. 5
0
 protected internal override void Execute <TOwner>(TriggerContext <TOwner> context)
 {
     foreach (WaitUnit unit in Until.GetWaitUnits(WaitOptions))
     {
         context.Log.ExecuteSection(
             new WaitForElementLogSection((UIComponent)context.Component, WaitBy, Selector, unit),
             () => Wait(context.Component, unit));
     }
 }
Esempio n. 6
0
        protected internal override void Execute <TOwner>(TriggerContext <TOwner> context)
        {
            bool completed = context.Driver.Try().Until(
                x => (bool)context.Driver.ExecuteScript("return jQuery.active == 0"));

            if (!completed)
            {
                throw new TimeoutException("Timed out waiting for the jQuery AJAX call to complete.");
            }
        }
        protected internal override void Execute <TOwner>(TriggerContext <TOwner> context)
        {
            bool completed = context.Driver.Try().Until(
                x => (bool)context.Driver.ExecuteScript("return document.readyState === 'complete'"));

            if (!completed)
            {
                throw new TimeoutException("Timed out waiting for document to be loaded/ready.");
            }
        }
Esempio n. 8
0
        protected internal override void Execute <TOwner>(TriggerContext <TOwner> context)
        {
            if (triggers == null)
            {
                InitTriggers();
            }

            foreach (TriggerAttribute trigger in triggers)
            {
                trigger.Execute(context);
            }
        }
Esempio n. 9
0
        protected internal override void Execute <TOwner>(TriggerContext <TOwner> context)
        {
            var        methodOwner = IsDefinedAtComponentLevel ? context.Component : context.Component.Parent;
            MethodInfo method      = methodOwner.GetType().GetMethod(MethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);

            if (method == null)
            {
                throw new MissingMethodException(methodOwner.GetType().FullName, MethodName);
            }

            method.Invoke(method.IsStatic ? null : methodOwner, new object[0]);
        }
Esempio n. 10
0
 protected internal override void Execute <TOwner>(TriggerContext <TOwner> context)
 {
     if (context.Component is Control <TOwner> componentAsControl)
     {
         if (context.Event != TriggerEvents.BeforeFocus && context.Event != TriggerEvents.AfterFocus)
         {
             componentAsControl.Focus();
         }
     }
     else
     {
         throw new InvalidOperationException($"{nameof(FocusAttribute)} trigger can be executed only against control. But was: {context.Component.GetType().FullName}.");
     }
 }
        protected internal override sealed void Execute <TOwner>(TriggerContext <TOwner> context)
        {
            MethodInfo declaredMethod = GetType().GetMethod("Execute", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            if (declaredMethod != null)
            {
                Type ownerType = context.Component.Owner.GetType();

                MethodInfo actualMethod = declaredMethod.IsGenericMethodDefinition
                    ? declaredMethod.MakeGenericMethod(ownerType)
                    : declaredMethod;

                actualMethod.InvokeAsLambda(this, context);
            }
        }
Esempio n. 12
0
        protected internal override void Execute <TOwner>(TriggerContext <TOwner> context)
        {
            IAlert alert = context.Driver.SwitchTo().Alert();

            if (Accept)
            {
                alert.Accept();
            }
            else
            {
                alert.Dismiss();
            }

            context.Driver.SwitchTo().DefaultContent();
        }
Esempio n. 13
0
        internal void Execute(TriggerEvents on)
        {
            if (orderedTriggers == null || orderedTriggers.Length == 0 || on == TriggerEvents.None || currentDeniedTriggers.Contains(on))
            {
                return;
            }

            TriggerEvents[] denyTriggers;
            if (DenyTriggersMap.TryGetValue(on, out denyTriggers))
            {
                currentDeniedTriggers.AddRange(denyTriggers);
            }

            try
            {
                var triggers = orderedTriggers.Where(x => x.On.HasFlag(on));

                TriggerContext <TOwner> context = new TriggerContext <TOwner>
                {
                    Event     = on,
                    Driver    = component.Driver,
                    Log       = component.Log,
                    Component = component
                };

                foreach (var trigger in triggers)
                {
                    trigger.Execute(context);
                }
            }
            finally
            {
                if (denyTriggers != null)
                {
                    currentDeniedTriggers.RemoveAll(x => denyTriggers.Contains(x));
                }
            }

            if (on == TriggerEvents.Init || on == TriggerEvents.DeInit)
            {
                foreach (UIComponent <TOwner> child in component.Controls)
                {
                    child.Triggers.Execute(on);
                }
            }
        }
Esempio n. 14
0
        protected internal override void Execute <TOwner>(TriggerContext <TOwner> context)
        {
            bool isDefinedAtComponentLevel = context.Component.Metadata.ComponentAttributes.Contains(this);

            var        methodOwner = isDefinedAtComponentLevel ? context.Component : context.Component.Parent;
            MethodInfo method      = methodOwner.GetType().GetMethodWithThrowOnError(MethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);

            if (method == null)
            {
                throw new MissingMethodException(methodOwner.GetType().FullName, MethodName);
            }

            if (method.IsStatic)
            {
                method.InvokeStaticAsLambda();
            }
            else
            {
                method.InvokeAsLambda(methodOwner);
            }
        }
Esempio n. 15
0
        protected internal override void Execute <TOwner>(TriggerContext <TOwner> context)
        {
            string message = BuildReportMessage(context) ?? DefaultReportMessage;
            string script  = BuildScript(context);

            void OnExecute()
            {
                bool isCompleted = context.Driver
                                   .Try(TimeSpan.FromSeconds(Timeout), TimeSpan.FromSeconds(RetryInterval))
                                   .Until(_ => context.Component.Script.Execute <bool>(script).Value);

                if (!isCompleted)
                {
                    StringBuilder errorMessageBuilder = new StringBuilder("Timed out waiting for script.");

                    if (message != DefaultReportMessage)
                    {
                        errorMessageBuilder.Append(' ').Append(message);

                        if (!message.EndsWith("."))
                        {
                            errorMessageBuilder.Append('.');
                        }
                    }

                    throw new TimeoutException(errorMessageBuilder.ToString());
                }
            }

            if (message != DefaultReportMessage)
            {
                context.Log.ExecuteSection(
                    new LogSection(message),
                    OnExecute);
            }
            else
            {
                OnExecute();
            }
        }
        protected internal override void Execute <TOwner>(TriggerContext <TOwner> context)
        {
            string[] expectedValues = this.GetActualValues(context.Component.ComponentName);

            OnExecute(context, expectedValues);
        }
Esempio n. 17
0
 protected internal override void Execute <TOwner>(TriggerContext <TOwner> context)
 {
     ActionDelegate.Invoke();
 }
Esempio n. 18
0
 protected internal override void Execute <TOwner>(TriggerContext <TOwner> context)
 {
     Thread.Sleep((int)(Seconds * 1000));
 }
Esempio n. 19
0
 /// <summary>
 /// Builds the report message.
 /// The default message is <c>"Wait for script"</c>.
 /// </summary>
 /// <typeparam name="TOwner">The type of the owner page object.</typeparam>
 /// <param name="context">The trigger context.</param>
 /// <returns>The message or <see langword="null"/>.</returns>
 protected virtual string BuildReportMessage <TOwner>(TriggerContext <TOwner> context)
     where TOwner : PageObject <TOwner>, IPageObject <TOwner>
 {
     return(DefaultReportMessage);
 }
Esempio n. 20
0
 /// <summary>
 /// Builds the script to wait until it returns <c>true</c>.
 /// The script should return <see langword="true"/> or <see langword="false"/>.
 /// </summary>
 /// <typeparam name="TOwner">The type of the owner page object.</typeparam>
 /// <param name="context">The trigger context.</param>
 /// <returns>The script.</returns>
 protected abstract string BuildScript <TOwner>(TriggerContext <TOwner> context)
     where TOwner : PageObject <TOwner>, IPageObject <TOwner>;
Esempio n. 21
0
 protected internal override void Execute <TOwner>(TriggerContext <TOwner> context)
 {
     context.Component.Content.Should.WithRetry.MatchAny(Match, Values);
 }
Esempio n. 22
0
 protected override void OnExecute <TOwner>(TriggerContext <TOwner> context, string[] values)
 {
     context.Component.Owner.PageTitle.Should.WithRetry.MatchAny(Match, values);
 }
 protected abstract void OnExecute <TOwner>(TriggerContext <TOwner> context, string[] values)
     where TOwner : PageObject <TOwner>;
Esempio n. 24
0
 protected internal abstract void Execute <TOwner>(TriggerContext <TOwner> context)
     where TOwner : PageObject <TOwner>, IPageObject <TOwner>;
 protected override void OnExecute<TOwner>(TriggerContext<TOwner> context, string[] values) =>
     context.Component.Owner.PageTitle.Should.Within(Timeout, RetryInterval).MatchAny(Match, values);