<commit_before>﻿using OpenQA.Selenium;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

namespace CodedSelenium
{
    public class UITestControl
    {
        private readonly string ContainsCharacter = "*";
        private PropertyExpressionCollection searchProperties;

        public UITestControl()
        {
        }

        public UITestControl(UITestControl parent)
        {
            if (parent.WebElement == null)
            {
                this.Parent = parent.Parent;
            }
            else
            {
                this.Parent = parent.WebElement;
            }
        }

        public virtual bool Exists
        {
            get
            {
                return this.WebElement.Displayed;
            }
        }

        public PropertyExpressionCollection SearchProperties
        {
            get
            {
                if (this.searchProperties == null)
                {
                    this.searchProperties = new PropertyExpressionCollection();
                }

                return this.searchProperties;
            }
        }

        protected ISearchContext Parent { get; set; }

        protected virtual IWebElement WebElement
        {
            get
            {
                Dictionary<string, string> dictionary = new Dictionary<string, string>();

                foreach (PropertyExpression searchProperty in this.SearchProperties)
                {
                    string key = searchProperty.PropertyName.ToLowerInvariant();

                    if (searchProperty.PropertyOperator == PropertyExpressionOperator.Contains)
                    {
                        key += this.ContainsCharacter;
                    }

                    dictionary.Add(key, searchProperty.PropertyValue);
                }

                string attributeTemplate = "[{0}=\"{1}\"]";
                IEnumerable<string> attributes = dictionary
                    .Where(item => item.Key != PropertyNames.TagName)
                    .Where(item => item.Key != PropertyNames.InnerText)
                    .Select(item => string.Format(attributeTemplate, item.Key, item.Value));

                IWebElement webElement = null;

                if (dictionary.ContainsKey(PropertyNames.InnerText))
                {
                    ReadOnlyCollection<IWebElement> matchingElements = this.Parent.FindElements(
                        By.CssSelector(dictionary[PropertyNames.TagName] + string.Join(string.Empty, attributes)));

                    if (dictionary[PropertyNames.InnerText].Contains(ContainsCharacter))
                        webElement = matchingElements.FirstOrDefault(item => item.Text.Contains(dictionary[PropertyNames.InnerText]));
                    else
                        webElement = matchingElements.FirstOrDefault(item => item.Text.Equals(dictionary[PropertyNames.InnerText]));
                }
                else
                {
                    webElement = this.Parent.FindElement(
                        By.CssSelector(dictionary[PropertyNames.TagName] + string.Join(string.Empty, attributes)));
                }

                return webElement;
            }
        }

        public virtual void Click()
        {
            this.WebElement.Click();
        }

        public abstract class PropertyNames
        {
            public static readonly string AccessKey = "accesskey";
            public static readonly string Class = "class";
            public static readonly string ControlDefinition = "controldefinition";
            public static readonly string HelpText = "helptext";
            public static readonly string Id = "id";
            public static readonly string InnerText = "innertext";
            public static readonly string TagInstance = "taginstance";<commit_msg>Have updated containsSufix in UITestControl<commit_after>﻿using OpenQA.Selenium;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;

namespace CodedSelenium
{
    public class UITestControl
    {
        private PropertyExpressionCollection searchProperties;

        public UITestControl()
        {
        }

        public UITestControl(UITestControl parent)
        {
            if (parent.WebElement == null)
            {
                this.Parent = parent.Parent;
            }
            else
            {
                this.Parent = parent.WebElement;
            }
        }

        public virtual bool Exists
        {
            get
            {
                return this.WebElement.Displayed;
            }
        }

        public PropertyExpressionCollection SearchProperties
        {
            get
            {
                if (this.searchProperties == null)
                {
                    this.searchProperties = new PropertyExpressionCollection();
                }

                return this.searchProperties;
            }
        }

        protected ISearchContext Parent { get; set; }

        protected virtual IWebElement WebElement
        {
            get
            {
                Dictionary<string, string> dictionary = new Dictionary<string, string>();
                string containsSufix = "*";

                foreach (PropertyExpression searchProperty in this.SearchProperties)
                {
                    string key = searchProperty.PropertyName.ToLowerInvariant();

                    if (searchProperty.PropertyOperator == PropertyExpressionOperator.Contains)
                    {
                        key += containsSufix;
                    }

                    dictionary.Add(key, searchProperty.PropertyValue);
                }

                string attributeTemplate = "[{0}=\"{1}\"]";
                IEnumerable<string> attributes = dictionary
                    .Where(item => item.Key != PropertyNames.TagName)
                    .Where(item => item.Key != PropertyNames.InnerText)
                    .Select(item => string.Format(attributeTemplate, item.Key, item.Value));

                IWebElement webElement = null;

                if (dictionary.ContainsKey(PropertyNames.InnerText))
                {
                    ReadOnlyCollection<IWebElement> matchingElements = this.Parent.FindElements(
                        By.CssSelector(dictionary[PropertyNames.TagName] + string.Join(string.Empty, attributes)));

                    if (dictionary[PropertyNames.InnerText].Contains(containsSufix))
                        webElement = matchingElements.FirstOrDefault(item => item.Text.Contains(dictionary[PropertyNames.InnerText]));
                    else
                        webElement = matchingElements.FirstOrDefault(item => item.Text.Equals(dictionary[PropertyNames.InnerText]));
                }
                else
                {
                    webElement = this.Parent.FindElement(
                        By.CssSelector(dictionary[PropertyNames.TagName] + string.Join(string.Empty, attributes)));
                }

                return webElement;
            }
        }

        public virtual void Click()
        {
            this.WebElement.Click();
        }

        public abstract class PropertyNames
        {
            public static readonly string AccessKey = "accesskey";
            public static readonly string Class = "class";
            public static readonly string ControlDefinition = "controldefinition";
            public static readonly string HelpText = "helptext";
            public static readonly string Id = "id";
            public static readonly string InnerText = "innertext";
            public static readonly string TagInstance = "taginstance";
{'fraction_non_alphanumeric': 0.07556290548276301, 'fraction_numerical': 0.0005088411143620405, 'mean_word_length': 1.5793963254593175, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4096870', 'n_tokens_mistral': 1774, 'n_tokens_neox': 1640, 'n_words': 367}