/// <summary>
        /// The click by index.
        /// </summary>
        /// <param name="findTechnique">
        /// The find technique.
        /// </param>
        /// <param name="index">
        /// The index.
        /// </param>
        public static void ClickByIndex(By findTechnique, int index)
        {
            Log.Logger.Debug(string.Format("Clicking radio button by index ({0})", findTechnique));
            SnapshotManager.TakeSnapshot();
            var radioButtons = BrowserHost.Instance.FindElements(findTechnique);

            radioButtons.ElementAt(index).Click();
        }
Пример #2
0
        /// <summary>
        /// The get.
        /// </summary>
        /// <param name="findTechnique">
        /// The find technique.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public static string Get(By findTechnique)
        {
            Log.Logger.Debug(string.Format("Getting ({0})", findTechnique));
            SnapshotManager.TakeSnapshot();
            var input = BrowserHost.Instance.FindElement(findTechnique);

            return(input.GetAttribute("value"));
        }
Пример #3
0
        /// <summary>
        /// The select by text.
        /// </summary>
        /// <param name="findTechnique">
        /// The find technique.
        /// </param>
        /// <param name="value">
        /// The value.
        /// </param>
        public static void SelectByText(By findTechnique, string value)
        {
            Log.Logger.Debug(string.Format("Selecting element from {1} with text ({0})", value, findTechnique));
            SnapshotManager.TakeSnapshot();
            var select  = BrowserHost.Instance.FindElement(findTechnique);
            var element = new SelectElement(select);

            element.SelectByText(value);
        }
Пример #4
0
        /// <summary>
        /// The toggle.
        /// </summary>
        /// <param name="findTechniqueForLabels">
        /// The find technique for label.
        /// </param>
        /// <param name="index">
        /// Index of switch.
        /// </param>
        public static void Toggle(By findTechniqueForLabels, int index)
        {
            Log.Logger.Debug(string.Format("Switching ({0})", findTechniqueForLabels));
            SnapshotManager.TakeSnapshot();
            var switchElements = BrowserHost.Instance.FindElements(findTechniqueForLabels);

            switchElements[index].Click();
            Thread.Sleep(TimeSpan.FromMilliseconds(250));
        }
Пример #5
0
        /// <summary>
        /// The get value.
        /// </summary>
        /// <param name="findTechnique">
        /// The find technique.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public static bool GetValue(By findTechnique)
        {
            Log.Logger.Debug(string.Format("Getting value for switch ({0})", findTechnique));
            SnapshotManager.TakeSnapshot();
            var inputElement  = BrowserHost.Instance.FindElement(findTechnique);
            var containingDiv = inputElement.FindElement(By.XPath(".."));
            var classes       = containingDiv.GetAttribute("class");

            return(classes.IndexOf("switch-on", StringComparison.OrdinalIgnoreCase) >= 0);
        }
Пример #6
0
        /// <summary>
        /// The click link.
        /// </summary>
        /// <param name="findTechnique">
        /// The find technique.
        /// </param>
        /// <param name="rowIndex">
        /// The row index.
        /// </param>
        /// <param name="elementToClick">
        /// The element to click.
        /// </param>
        public static void ClickLink(By findTechnique, int rowIndex, By elementToClick)
        {
            Log.Logger.Debug(string.Format("Selecting row ({0}) in table {1}", rowIndex, findTechnique));
            SnapshotManager.TakeSnapshot();
            var table           = BrowserHost.Instance.FindElement(findTechnique);
            var rows            = table.FindElements(By.TagName("tr"));
            var rowToClick      = rows[rowIndex];
            var elementsToClick = rowToClick.FindElements(elementToClick);

            elementsToClick[0].Click();
        }
Пример #7
0
        /// <summary>
        /// The select by index.
        /// </summary>
        /// <param name="findTechnique">
        /// The find technique.
        /// </param>
        /// <param name="index">
        /// The index.
        /// </param>
        public static void SelectByIndex(By findTechnique, int index)
        {
            Log.Logger.Debug(string.Format("Selecting element from {1} with index ({0})", index, findTechnique));
            SnapshotManager.TakeSnapshot();
            var select  = BrowserHost.Instance.FindElement(findTechnique);
            var element = new SelectElement(select);

            while (!element.AllSelectedOptions.Any())
            {
                element.SelectByIndex(index);
                Thread.Sleep(TimeSpan.FromMilliseconds(400));
            }
        }
Пример #8
0
 /// <summary>
 /// The wait for.
 /// </summary>
 /// <param name="action">
 /// The action.
 /// </param>
 private static void WaitFor(Action action)
 {
     try
     {
         SnapshotManager.TakeSnapshot();
         action();
     }
     catch (WebDriverTimeoutException)
     {
         var file = ((ITakesScreenshot)BrowserHost.Instance).GetScreenshot();
         file.SaveAsFile("WaitsBroke.png", ImageFormat.Png);
         Log.Logger.Error(string.Format("Item being waited for didn't appear - Current Page Title: ({0})", BrowserHost.Instance.Title));
         throw;
     }
 }
        /// <summary>
        /// The click by value.
        /// </summary>
        /// <param name="findTechnique">
        /// The find technique.
        /// </param>
        /// <param name="value">
        /// The value.
        /// </param>
        public static void ClickByValue(By findTechnique, string value)
        {
            Log.Logger.Debug(string.Format("Clicking radio button ({0})", findTechnique));
            SnapshotManager.TakeSnapshot();
            var radioButtons = BrowserHost.Instance.FindElements(findTechnique);

            for (var i = 0; i < radioButtons.Count; i++)
            {
                var radioButtonValue = radioButtons.ElementAt(i).GetAttribute("value");
                if (value.Equals(radioButtonValue, StringComparison.OrdinalIgnoreCase))
                {
                    radioButtons.ElementAt(i).Click();
                    break;
                }
            }
        }
Пример #10
0
        /// <summary>
        /// The click label.
        /// </summary>
        /// <param name="forInput">
        /// The for input.
        /// </param>
        /// <param name="index">
        /// The index.
        /// </param>
        /// <exception cref="Exception">
        /// Could not find the label
        /// </exception>
        public static void ClickLabel(string forInput, int index)
        {
            Log.Logger.Debug(string.Format("Finding label {0} and index {1}", forInput, index));
            SnapshotManager.TakeSnapshot();
            var labels = BrowserHost.Instance.FindElements(By.TagName("label"));

            foreach (var webElement in labels)
            {
                var labelFor = webElement.GetAttribute("for");
                if (labelFor.Equals(forInput, StringComparison.OrdinalIgnoreCase))
                {
                    webElement.Click();
                    return;
                }
            }

            throw new Exception("Could not find label to click");
        }
Пример #11
0
        /// <summary>
        /// The get value.
        /// </summary>
        /// <param name="forInput">
        /// The for input.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        /// <exception cref="Exception">
        /// Could not find value of switch
        /// </exception>
        public static bool GetValue(string forInput)
        {
            Log.Logger.Debug(string.Format("Getting value for switch ({0})", forInput));
            SnapshotManager.TakeSnapshot();

            var labels = BrowserHost.Instance.FindElements(By.TagName("label"));

            foreach (var webElement in labels)
            {
                var labelFor = webElement.GetAttribute("for");
                if (labelFor.Equals(forInput, StringComparison.OrdinalIgnoreCase))
                {
                    var containingDiv = webElement.FindElement(By.XPath(".."));
                    var classes       = containingDiv.GetAttribute("class");
                    return(classes.IndexOf("switch-on", StringComparison.OrdinalIgnoreCase) >= 0);
                }
            }

            throw new Exception("Could not find value of switch");
        }
Пример #12
0
        /// <summary>
        /// The click first link.
        /// </summary>
        /// <param name="classType">
        /// The class type.
        /// </param>
        /// <param name="startOfLink">
        /// The start of link.
        /// </param>
        public static void ClickFirstLink(string classType, string startOfLink)
        {
            Log.Logger.Debug(string.Format("Finding first link that conforms to {0} and starts with {1}", classType, startOfLink));
            SnapshotManager.TakeSnapshot();
            var hyperlinks = BrowserHost.Instance.FindElements(By.TagName("a"));

            foreach (var webElement in hyperlinks)
            {
                var classes = webElement.GetAttribute("class");
                if (classes.IndexOf(classType, StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    Log.Logger.Debug(string.Format("Found a hyperlink with the class {0}", webElement));
                    var href = webElement.GetAttribute("href");
                    if (href.IndexOf(startOfLink, StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        Log.Logger.Debug(string.Format("Found a hyperlink with the class and starts with the text provided {0}", webElement));
                        webElement.Click();
                        break;
                    }
                }
            }
        }
Пример #13
0
 /// <summary>
 /// The send keys.
 /// </summary>
 /// <param name="findTechnique">
 /// The find technique.
 /// </param>
 /// <param name="inputValue">
 /// The input value.
 /// </param>
 public static void SendKeys(By findTechnique, string inputValue)
 {
     Log.Logger.Debug(string.Format("Sending ({0}) to {1}", inputValue, findTechnique));
     SnapshotManager.TakeSnapshot();
     BrowserHost.Instance.FindElement(findTechnique).SendKeys(inputValue);
 }
Пример #14
0
 /// <summary>
 /// The clear.
 /// </summary>
 /// <param name="findTechnique">
 /// The find technique.
 /// </param>
 public static void Clear(By findTechnique)
 {
     Log.Logger.Debug(string.Format("Clearing ({0})", findTechnique));
     SnapshotManager.TakeSnapshot();
     BrowserHost.Instance.FindElement(findTechnique).Clear();
 }