예제 #1
0
        /// <summary>
        /// Sends keystrokes to the target Web element.
        /// By default, the element will be cleared first, and keystrokes will not be kept private for logging.
        /// Use builder methods to change those defaults.
        /// </summary>
        /// <param name="actor">The Screenplay Actor.</param>
        /// <param name="driver">The WebDriver.</param>
        public override void PerformAs(IActor actor, IWebDriver driver)
        {
            // Wait for the element to exist
            actor.WaitsUntil(Appearance.Of(Locator), IsEqualTo.True());

            // Get the element
            IWebElement element = driver.FindElement(Locator.Query);

            // Clear the element if appropriate
            if (Clear)
            {
                if (UseClearMethod)
                {
                    // Use the plain-old "Clear" method
                    element.Clear();
                }
                else
                {
                    // How many backspaces should be sent?
                    // One for each character in the input!
                    int length = element.GetAttribute("value").Length;

                    if (length > 0)
                    {
                        // Send the backspaces
                        string backspaces = string.Concat(Enumerable.Repeat(Keys.Backspace, length));
                        element.SendKeys(backspaces);

                        // The browser may put the cursor to the left instead of the right
                        // Do the same thing for delete button
                        string deletes = string.Concat(Enumerable.Repeat(Keys.Delete, length));
                        element.SendKeys(deletes);
                    }
                }
            }

            // Send the keys to the element
            element.SendKeys(Keystrokes);

            // Hit the ENTER key if applicable
            if (FinalEnter)
            {
                element.SendKeys(Keys.Enter);
            }

            // Click on the final "safe" element if given
            if (FinalElement != null)
            {
                actor.AttemptsTo(Click.On(FinalElement));
            }
        }
예제 #2
0
        /// <summary>
        /// Waits for an element to appear and refreshes the browser if it doesn't appear within the refresh timeout.
        /// Internally calls Wait.
        /// </summary>
        /// <param name="actor">The Screenplay Actor.</param>
        /// <param name="driver">The WebDriver.</param>
        public override void PerformAs(IActor actor, IWebDriver driver)
        {
            // Construct the waiting interaction
            var wait = Wait.Until(Appearance.Of(Locator), IsEqualTo.True())
                       .ForUpTo(TimeoutSeconds).ForAnAdditional(AdditionalSeconds);

            try
            {
                // Wait for the button to appear
                // This page notoriously takes longer to load than others
                actor.AttemptsTo(wait);
            }
            catch (WaitingException <bool> )
            {
                // If the button doesn't load, refresh the browser and retry
                // That's what a human would do
                actor.AttemptsTo(Refresh.Browser());
                System.Threading.Thread.Sleep(RefreshSeconds * 1000);
                actor.AttemptsTo(wait);
            }
        }
예제 #3
0
 /// <summary>
 /// Hovers over the web element.
 /// Make sure the proper locator is used, or else hovering may have no effect!
 /// </summary>
 /// <param name="actor">The screenplay actor.</param>
 /// <param name="driver">The WebDriver.</param>
 public override void PerformAs(IActor actor, IWebDriver driver)
 {
     actor.WaitsUntil(Appearance.Of(Locator), IsEqualTo.True());
     new Actions(driver).MoveToElement(driver.FindElement(Locator.Query)).Perform();
 }
예제 #4
0
 /// <summary>
 /// Clears the text of the web element.
 /// </summary>
 /// <param name="actor">The Screenplay Actor.</param>
 /// <param name="driver">The WebDriver.</param>
 public override void PerformAs(IActor actor, IWebDriver driver)
 {
     actor.WaitsUntil(Appearance.Of(Locator), IsEqualTo.True());
     driver.FindElement(Locator.Query).Clear();
 }
예제 #5
0
 /// <summary>
 /// Drags the mouse from one element to another
 /// Use browser actions instead of direct click (due to IE).
 /// </summary>
 /// <param name="actor">The Screenplay Actor.</param>
 /// <param name="driver">The WebDriver.</param>
 public override void PerformAs(IActor actor, IWebDriver driver)
 {
     actor.WaitsUntil(Appearance.Of(Locator), IsEqualTo.True());
     actor.WaitsUntil(Appearance.Of(Target), IsEqualTo.True());
     new Actions(driver).DragAndDrop(driver.FindElement(Locator.Query), driver.FindElement(Target.Query)).Perform();
 }