Beispiel #1
0
 public string Invoke(LocatedElements locatedElements, string attributeName)
 => locatedElements
 .ConstraintCount(c => c == 1)
 .Elements
 .First()
 .GetAttribute(attributeName)
 .ToString();
Beispiel #2
0
        public string Invoke(LocatedElements elements, string toleranceValue)
        {
            elements.ConstraintCount(c => c > 0);

            var configuration      = Context.ConfigurationProvider.Get(VisualRegressionConfiguration.Default);
            var baseVersionId      = configuration.ScreenshotStoreBaseVersionId;
            var referenceVersionId = configuration.ScreenshotStoreReferenceVersionId;
            var tolerance          = ParseToleranceLevel(toleranceValue.FallbackEmptyString(() => configuration.ScreenshotDiffTolerance));

            foreach (var element in elements.Elements)
            {
                var screenshot = element.TakeScreenshot(Context.Driver, Context.ConfigurationProvider);
                var elementId  = IdentityProvider.GetIdentifier(Context.Driver, elements, element);
                ScreenshotStore.Store(screenshot, Context.TopicId, elementId, referenceVersionId);

                var diff = ScreenshotStore.Compare(Context.TopicId, elementId, baseVersionId, referenceVersionId);
                Invoker.AddImage(ScreenshotStore.GetPath(Context.TopicId, elementId, configuration.ScreenshotStoreBaseVersionId));
                Invoker.AddImage(ScreenshotStore.GetPath(Context.TopicId, elementId, configuration.ScreenshotStoreReferenceVersionId));
                Invoker.AddImage(ScreenshotStore.GetPath(Context.TopicId, elementId, configuration.ScreenshotStoreDiffVersionId));

                Invoker.AddInfo($"Total difference {diff}");
                if (diff > tolerance)
                {
                    throw new ComparisonAssertionException(elementId, baseVersionId, referenceVersionId, diff * 100, tolerance * 100);
                }
            }

            return("true");
        }
Beispiel #3
0
 public string Invoke(LocatedElements locatedElements)
 => locatedElements
 .ConstraintCount(c => c == 1)
 .Elements
 .First()
 .Displayed
 .ToString();
Beispiel #4
0
 public string Invoke(LocatedElements elements, string pattern)
 {
     elements
     .ConstraintCount(c => c > 0)
     .Elements
     .ForEach(e => VerifyElement(pattern, e));
     return("true");
 }
Beispiel #5
0
 public void Invoke(LocatedElements elements, string value)
 => elements
 .ConstraintCount(c => c > 0)
 .Elements
 .ForEach(
     x => Context
     .Driver
     .ExecuteScriptWithArguments(JavascriptCode.SetValue(value), x));
Beispiel #6
0
 public string Invoke(LocatedElements elements)
 => elements
 .ConstraintCount(c => c == 1)
 .Elements
 .First()
 .Size
 .Height
 .ToString();
Beispiel #7
0
        public void Invoke(LocatedElements elements, OptionLocator optionLocator)
        {
            var action = new OpenQA.Selenium.Interactions.Actions(Context.Driver);

            elements
            .ConstraintCount(c => c == 1)
            .Elements
            .ForEach(x => PerformSelection(new SelectElement(x), optionLocator));
        }
Beispiel #8
0
        public string Invoke(LocatedElements elements)
        {
            if (!elements.Elements.Any())
            {
                throw new AssertionException("Element expected to exists", "No element found", WebDrivers.Default);
            }

            return("true");
        }
Beispiel #9
0
        public void Invoke(LocatedElements elements)
        {
            var action = new OpenQA.Selenium.Interactions.Actions(Context.Driver);

            elements
            .ConstraintCount(c => c == 1)
            .Elements
            .ForEach(x =>
                     action
                     .Release(x)
                     .Perform());
        }
Beispiel #10
0
        public void Invoke(LocatedElements elements)
        {
            var action = new OpenQA.Selenium.Interactions.Actions(Context.Driver);

            elements
            .ConstraintCount(c => c > 0)
            .Elements
            .ForEach(x =>
                     action
                     .MoveToElement(x)
                     .DoubleClick()
                     .Perform());
        }
Beispiel #11
0
        public void Invoke(LocatedElements elements, Point coordinate)
        {
            var action = new OpenQA.Selenium.Interactions.Actions(Context.Driver);

            elements
            .ConstraintCount(c => c == 1)
            .Elements
            .ForEach(x =>
                     action
                     .MoveToElement(x, (int)coordinate.X, (int)coordinate.Y)
                     .ClickAndHold()
                     .Perform());
        }
Beispiel #12
0
        public void Invoke(LocatedElements elements, Point coordinates)
        {
            var action = new OpenQA.Selenium.Interactions.Actions(Context.Driver);

            elements
            .ConstraintCount(c => c > 0)
            .Elements
            .ForEach(e =>
                     action
                     .MoveToElement(e, (int)coordinates.X, (int)coordinates.Y)
                     .Click()
                     .Perform());
        }
Beispiel #13
0
        public string GetIdentifier(IWebDriver driver, LocatedElements elements, IWebElement element)
        {
            var replacedCharacters = Path.GetInvalidFileNameChars()
                                     .Concat(new[] { '_' })
                                     .ToArray();
            var id = string.Join("_",
                                 GetElementIndex(elements, element),
                                 element.TagName,
                                 elements.Locator.Id,
                                 elements.Parameter);
            var safeId = string.Join("_", id.Split(replacedCharacters, StringSplitOptions.RemoveEmptyEntries));

            return(safeId.Length > MAX_ID_LENGTH?safeId.Substring(0, MAX_ID_LENGTH) : safeId);
        }
Beispiel #14
0
        public string Invoke(LocatedElements elements)
        {
            elements.ConstraintCount(c => c > 0);

            var configuration = Context.ConfigurationProvider.Get(VisualRegressionConfiguration.Default);
            var versionId     = configuration.ScreenshotStoreReferenceVersionId;

            foreach (var element in elements.Elements)
            {
                var screenshot = element.TakeScreenshot(Context.Driver, Context.ConfigurationProvider);
                var elementId  = IdentityProvider.GetIdentifier(Context.Driver, elements, element);
                ScreenshotStore.Store(screenshot, Context.TopicId, elementId, versionId);

                return(ScreenshotStore.GetPath(Context.TopicId, elementId, versionId));
            }
            return("");
        }
Beispiel #15
0
        public string Invoke(LocatedElements elements)
        {
            elements.ConstraintCount(c => c == 1);

            var configuration  = Context.ConfigurationProvider.Get(VisualRegressionConfiguration.Default);
            var deltaVersionId = configuration.ScreenshotStoreDiffVersionId;
            var elementId      = IdentityProvider.GetIdentifier(Context.Driver, elements, elements.Elements.First());
            var image          = ScreenshotStore.GetPath(Context.TopicId, elementId, deltaVersionId);

            const long BYTE_LIMIT = 0x186A0;

            if (ImageInliner.TryInlineImage(image, "400", BYTE_LIMIT, out string base64))
            {
                return(base64);
            }
            else
            {
                return($"Image has reached a size limit of {BYTE_LIMIT} bytes");
            }
        }
Beispiel #16
0
 public void Invoke(LocatedElements elements)
 => elements
 .ConstraintCount(c => c == 1)
 .Elements
 .First()
 .Submit();
Beispiel #17
0
 public string Invoke(LocatedElements elements)
 => elements.Elements.Count() + "";
Beispiel #18
0
 public string Invoke(LocatedElements elements)
 => elements
 .ConstraintCount(c => c == 1)
 .Elements
 .First()
 .TagName;
Beispiel #19
0
 private int GetElementIndex(LocatedElements elements, IWebElement element)
 => elements
 .Elements
 .ToList()
 .IndexOf(element) + 1;
Beispiel #20
0
 public void Invoke(LocatedElements elements)
 => elements
 .ConstraintCount(c => c > 0)
 .Elements
 .ForEach(x => Context.Driver.ExecuteScriptWithArguments(ChangeHighlightScript, x));
Beispiel #21
0
 public string Invoke(LocatedElements locatedElements, string propertyName)
 => locatedElements
 .ConstraintCount(c => c == 1)
 .Elements
 .First()
 .GetCssValue(propertyName);
Beispiel #22
0
 public void Invoke(LocatedElements elements, string keys)
 => elements
 .ConstraintCount(c => c > 0)
 .Elements
 .ForEach(e => TypeLikeHuman(e, keys));
Beispiel #23
0
 public void Invoke(LocatedElements elements, string keys)
 => elements
 .ConstraintCount(c => c > 0)
 .Elements
 .ForEach(x => x.SendKeys(keys));
Beispiel #24
0
 public string Invoke(LocatedElements elements)
 => elements
 .ConstraintCount(c => c == 1)
 .Elements
 .First()
 .GetAttribute("innerHTML");
Beispiel #25
0
 public void Invoke(LocatedElements elements)
 => elements
 .ConstraintCount(c => c > 0)
 .Elements
 .ForEach(x => x.Click());
Beispiel #26
0
 public void Invoke(LocatedElements elements)
 => elements
 .ConstraintCount(c => c == 1)
 .Elements
 .ForEach(x => x.SendKeys(""));