Exemplo n.º 1
0
        private void LaunchAlternateEngageActivity(DOMActivatorElement activityToEngage)
        {
            Logger.Info("Launching Activity: {0}", activityToEngage.Key);
            activityToEngage.OpeningItem(Driver, Logger);
            Delay();
            Context.LogAction(ActionType.ClickLink, activityToEngage.Key);
            Delay();

            // Notes:
            //   Functional solution to recursively iterate on the back process a fixed (2) number of times until the expected element is present, instead of the traditional Delay guessing mechanism.
            System.Func<System.Func<bool>, bool> _goBack = (gb) => 
            {
                var mailLink = Driver.FirstOrDefault(By.CssSelector(MailDOMElement.LocationCriteria));

                if (!Driver.HasPopupWindows())
                {
                    mailLink = Driver.FirstOrDefault(By.CssSelector(MailDOMElement.LocationCriteria));

                    if (mailLink == null || !mailLink.IsDisplayed())
                    {
                        Driver.Navigate().Back();
                    }
                    else
                    {
                        mailLink.Click();
                    }

                    Delay();
                }
                else
                {
                    Driver
                        .CloseAlerts(Logger)
                        .ClosePopupWindows(Logger);
                }

                mailLink = Driver.FirstOrDefault(By.CssSelector(MailDOMElement.LocationCriteria));
                return (mailLink != null && mailLink.IsDisplayed()) || gb();
            };

            if (!_goBack(() => _goBack(() => false)))
            {
                throw new InvalidOperationException(String.Format("Couldn't go back to the original page with marker DOM element: {0} / {1}", MailDOMElement.Key, MailDOMElement.LocationCriteria));
            }
        }
Exemplo n.º 2
0
        private void LaunchAlternateEngageActivity(DOMActivatorElement activityToEngage)
        {
            try
            {
                Logger.Info("Launching Activity: {0}", activityToEngage.Key);
                activityToEngage.OpeningItem(Driver, Logger);
                Delay();

                Context.LogAction(ActionType.ClickLink, activityToEngage.Key);
                Delay();

                activityToEngage.ClosingItem(Driver, Logger);
                Delay();

            }
            catch (Exception ex)
            {
                Logger.Error("Failed opening alternate activity window. Error message: {0}", ex.Message);
            }
            finally
            {
                Driver.SwitchTo().DefaultContent();
            }
        }