Exemplo n.º 1
0
        private Dictionary <string, string> RecurseFrames_(List <string> missingFramesList)
        {
            logger_.Verbose("enter");
            Dictionary <string, string> framesData = new Dictionary <string, string>();
            EyesWebDriverTargetLocator  switchTo   = (EyesWebDriverTargetLocator)webDriver_.SwitchTo();

            FrameChain fc = webDriver_.GetFrameChain().Clone();

            foreach (string missingFrameLine in missingFramesList)
            {
                try
                {
                    logger_.Verbose("handling frame xpath: {0}", missingFrameLine);

                    string originLocation = (string)webDriver_.ExecuteScript("return document.location.href");

                    string[] missingFrameXpaths = missingFrameLine.Split(',');
                    foreach (string missingFrameXpath in missingFrameXpaths)
                    {
                        IWebElement frame = webDriver_.FindElement(By.XPath(missingFrameXpath));
                        switchTo.Frame(frame);
                    }
                    string locationAfterSwitch = (string)webDriver_.ExecuteScript("return document.location.href");
                    if (locationAfterSwitch.Equals(originLocation, StringComparison.OrdinalIgnoreCase))
                    {
                        logger_.Log("WARNING! Failed switching into frame. HREF: {0}", locationAfterSwitch);
                        framesData.Add(missingFrameLine, string.Empty);
                        continue;
                    }
                    string result = GetFrameDom_();
                    framesData.Add(missingFrameLine, result);
                }
                catch (Exception e)
                {
                    logger_.Log("Error: " + e);
                    framesData.Add(missingFrameLine, string.Empty);
                }
                finally
                {
                    switchTo.Frames(fc);
                }
            }

            logger_.Verbose("exit");
            return(framesData);
        }
Exemplo n.º 2
0
        private Dictionary <string, string> RecurseFrames_(List <string> missingFramesList, string[] testIds)
        {
            Dictionary <string, string> framesData = new Dictionary <string, string>();
            EyesWebDriverTargetLocator  switchTo   = (EyesWebDriverTargetLocator)webDriver_.SwitchTo();

            FrameChain fc = webDriver_.GetFrameChain().Clone();

            foreach (string missingFrameLine in missingFramesList)
            {
                try
                {
                    string originLocation = (string)webDriver_.ExecuteScript("return document.location.href");

                    string[] missingFrameXpaths = missingFrameLine.Split(',');
                    foreach (string missingFrameXpath in missingFrameXpaths)
                    {
                        IWebElement frame = webDriver_.FindElement(By.XPath(missingFrameXpath));
                        switchTo.Frame(frame);
                    }
                    string locationAfterSwitch = (string)webDriver_.ExecuteScript("return document.location.href");
                    if (locationAfterSwitch.Equals(originLocation, StringComparison.OrdinalIgnoreCase))
                    {
                        logger_.Log(TraceLevel.Warn, testIds, Stage.Check, StageType.DomScript,
                                    new { message = "Failed switching into frame.", locationAfterSwitch });
                        framesData.Add(missingFrameLine, string.Empty);
                        continue;
                    }
                    string result = GetFrameDom_(testIds);
                    framesData.Add(missingFrameLine, result);
                }
                catch (Exception e)
                {
                    CommonUtils.LogExceptionStackTrace(logger_, Stage.Check, e, testIds);
                    framesData.Add(missingFrameLine, string.Empty);
                }
                finally
                {
                    switchTo.Frames(fc);
                }
            }

            return(framesData);
        }