コード例 #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();
        }
コード例 #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.");
            }
        }
コード例 #3
0
ファイル: PressKeysAttribute.cs プロジェクト: rputch/atata
 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))));
     }
 }
コード例 #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);
        }
コード例 #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));
     }
 }
コード例 #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.");
            }
        }
コード例 #7
0
        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.");
            }
        }
コード例 #8
0
        protected internal override void Execute <TOwner>(TriggerContext <TOwner> context)
        {
            if (triggers == null)
            {
                InitTriggers();
            }

            foreach (TriggerAttribute trigger in triggers)
            {
                trigger.Execute(context);
            }
        }
コード例 #9
0
ファイル: InvokeMethodAttribute.cs プロジェクト: vik542/atata
        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]);
        }
コード例 #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}.");
     }
 }
コード例 #11
0
        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);
            }
        }
コード例 #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();
        }
コード例 #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);
                }
            }
        }
コード例 #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);
            }
        }
コード例 #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();
            }
        }
コード例 #16
0
        protected internal override void Execute <TOwner>(TriggerContext <TOwner> context)
        {
            string[] expectedValues = this.GetActualValues(context.Component.ComponentName);

            OnExecute(context, expectedValues);
        }
コード例 #17
0
 protected internal override void Execute <TOwner>(TriggerContext <TOwner> context)
 {
     ActionDelegate.Invoke();
 }
コード例 #18
0
 protected internal override void Execute <TOwner>(TriggerContext <TOwner> context)
 {
     Thread.Sleep((int)(Seconds * 1000));
 }
コード例 #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);
 }
コード例 #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>;
コード例 #21
0
 protected internal override void Execute <TOwner>(TriggerContext <TOwner> context)
 {
     context.Component.Content.Should.WithRetry.MatchAny(Match, Values);
 }
コード例 #22
0
 protected override void OnExecute <TOwner>(TriggerContext <TOwner> context, string[] values)
 {
     context.Component.Owner.PageTitle.Should.WithRetry.MatchAny(Match, values);
 }
コード例 #23
0
 protected abstract void OnExecute <TOwner>(TriggerContext <TOwner> context, string[] values)
     where TOwner : PageObject <TOwner>;
コード例 #24
0
ファイル: TriggerAttribute.cs プロジェクト: tablesmit/atata
 protected internal abstract void Execute <TOwner>(TriggerContext <TOwner> context)
     where TOwner : PageObject <TOwner>, IPageObject <TOwner>;
コード例 #25
0
 protected override void OnExecute<TOwner>(TriggerContext<TOwner> context, string[] values) =>
     context.Component.Owner.PageTitle.Should.Within(Timeout, RetryInterval).MatchAny(Match, values);