public void PerformAs(IActor actor)
        {
            foreach (var row in _rows)
            {
                switch (row.Label.ToUpper())
                {
                case "URL":
                    actor.AttemptsTo(SendKeys.To(SubmissionPage.UrlInputField, row.Value));
                    break;

                case "TYPE":
                    actor.AttemptsTo(Select.ByText(SubmissionPage.TypeSelect, row.Value));
                    break;

                case "EMAIL":
                    actor.AttemptsTo(SendKeys.To(SubmissionPage.EmailInputField, row.Value));
                    break;

                case "DESCRIPTION":
                    actor.AttemptsTo(SendKeys.To(SubmissionPage.DescriptionInputField, row.Value));
                    break;

                case "NAME":
                    actor.AttemptsTo(SendKeys.To(SubmissionPage.NameField, row.Value));
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
        }
Пример #2
0
        public void InitializeScreenplay()
        {
            actor = new Actor(name: "Harshit", logger: new ConsoleLogger());
            string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            actor.Can(BrowseTheWeb.With(new ChromeDriver(directoryName + "\\Drivers")));
            actor.AttemptsTo(Navigate.ToUrl(LoginPage.Url));
            actor.AttemptsTo(MaximizeWindow.ForBrowser());
        }
Пример #3
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.AttemptsTo(Wait.Until(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;

                    // 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));
            }
        }
Пример #4
0
        public void GivenTheseExistingCars(Table table)
        {
            table.Rows.ForEach(values =>
            {
                _actor.AttemptsTo(DeleteCar.ByRegistration(values["Registration"]));

                int customerId = _actor.AsksFor(
                    values.ContainsKey("Customer") ? StoredCustomerId.ForName(values["Customer"]) : StoredCustomerId.First());

                _actor.AttemptsTo(
                    InsertCar.WithRegistration(values["Registration"])
                    .ForCustomer(customerId)
                    .WithMake(values["Make"])
                    .WithModel(values["Model"]));
            });
        }
Пример #5
0
        /// <summary>
        /// Waits for an file input element to appear and uploads a file to it.
        /// 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)
        {
            actor.AttemptsTo(Wait.Until(Existence.Of(Locator), IsEqualTo.True()));
            var element = driver.FindElement(Locator.Query);

            element.SendKeys(FilePath);
        }
Пример #6
0
        /// <summary>
        /// Gets the list of the Web element's CSS classes.
        /// </summary>
        /// <param name="actor">The actor.</param>
        /// <param name="driver">The WebDriver.</param>
        /// <returns></returns>
        public override string[] RequestAs(IActor actor, IWebDriver driver)
        {
            actor.AttemptsTo(Wait.Until(Existence.Of(Locator), IsEqualTo.True()));
            string classes = driver.FindElement(Locator.Query).GetAttribute("class");

            return(classes.Split());
        }
Пример #7
0
 protected override void PerformAs(IActor actor, AutoWorkshopDriver driver)
 {
     actor.AttemptsTo(
         SendKeys.To(ChangeCarRegistrationPage.CurrentRegistration, _currentRegistration),
         SendKeys.To(ChangeCarRegistrationPage.NewRegistration, _newRegistration),
         Click.On(ChangeCarRegistrationPage.UpdateRegistration),
         AcceptAlert.StartsWithText($"Change registration {_currentRegistration} to registration {_newRegistration}?"));
 }
        public void GivenThisExistingCustomer(Table table)
        {
            var values = table.Rows.Single();

            _actor.AttemptsTo(DeleteCustomers.WithName(values["Name"]));

            _storedCustomer = new CustomerInfo(
                values["Title"],
                values["Name"],
                values["Address Line 1"],
                values["Address Line 2"],
                values["Address Line 3"],
                values["Postcode"],
                values["Home Phone"],
                values["Mobile"],
                1);

            _actor.AttemptsTo(
                InsertCustomer.Named(values["Name"])
                .Titled(values["Title"])
                .OfAddress(
                    values["Address Line 1"],
                    values["Address Line 2"],
                    values["Address Line 3"],
                    values["Postcode"])
                .WithHomePhone(values["Home Phone"])
                .WithMobile(values["Mobile"]));
        }
Пример #9
0
 protected override void PerformAs(IActor actor, AutoWorkshopDriver driver)
 {
     actor.AttemptsTo(
         SendKeys.To(CarMaintenancePage.Registration, _registration),
         SendKeys.To(CarMaintenancePage.Make, _make),
         SendKeys.To(CarMaintenancePage.Model, _model),
         SendKeys.To(CarMaintenancePage.Year, _year),
         Click.On(CarMaintenancePage.Save));
 }
Пример #10
0
        /// <summary>
        /// Gets the Web element's text.
        /// </summary>
        /// <param name="actor">The actor.</param>
        /// <param name="driver">The WebDriver.</param>
        /// <returns></returns>
        public override IEnumerable <string> RequestAs(IActor actor, IWebDriver driver)
        {
            actor.AttemptsTo(Wait.Until(Existence.Of(Locator), IsEqualTo.True()));
            var elements = driver.FindElements(Locator.Query);
            var strings  = from e in elements select e.Text;

            // ToList() will avoid lazy evaluation
            return(strings.ToList());
        }
Пример #11
0
        /// <summary>
        /// Navigates the browser to the target URL if necessary.
        /// </summary>
        /// <param name="actor">The screenplay actor.</param>
        public void PerformAs(IActor actor)
        {
            string currentUrl = actor.AsksFor(CurrentUrl.FromBrowser());

            if (Acceptable.Match(currentUrl).Success)
            {
                actor.Logger.Info("The current URL is acceptable, so navigation will not be attempted");
            }
            else
            {
                actor.Logger.Info("The current URL is not acceptable, so navigation will be attempted");
                actor.AttemptsTo(Navigate.ToUrl(Url));

                if (AcceptAlerts)
                {
                    actor.AttemptsTo(AcceptAlert.IfItExists());
                }
            }
        }
Пример #12
0
 protected override void PerformAs(IActor actor, AutoWorkshopDriver driver)
 {
     actor.AttemptsTo(
         SendKeys.To(JobMaintenancePage.Description, _description),
         ChooseDate.For(JobMaintenancePage.Start, _date),
         SendKeys.To(JobMaintenancePage.Hours, _hours.ToString("0.##")),
         SendKeys.To(JobMaintenancePage.Mileage, _mileage.ToString()),
         Click.On(JobMaintenancePage.Save),
         AcceptAlert.StartsWithText("Have you checked MOT"));
 }
Пример #13
0
        /// <summary>
        /// Checks an element if not already selected
        /// Useful for checkboxes or radio buttons
        /// </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());
            bool selectedState = actor.AsksFor(SelectedState.Of(Locator));

            if (selectedState != CheckState)
            {
                actor.AttemptsTo(Click.On(Locator));
            }
        }
        /// <summary>
        /// Makes a direct call to a JavaScript element and returns the result.
        /// </summary>
        /// <param name="actor">The actor.</param>
        /// <param name="driver">The WebDriver.</param>
        /// <returns></returns>
        public override TValue RequestAs(IActor actor, IWebDriver driver)
        {
            actor.AttemptsTo(Wait.Until(Existence.Of(Locator), IsEqualTo.True()));

            var e       = driver.FindElement(Locator.Query);
            var newList = Args.ToList();

            newList.Insert(0, e);

            return((TValue)((IJavaScriptExecutor)driver).ExecuteScript(Script, newList.ToArray()));
        }
Пример #15
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);
            }
        }
Пример #16
0
 protected override void PerformAs(IActor actor, AutoWorkshopDriver driver)
 {
     actor.AttemptsTo(
         Select.ByText(CustomerMaintenancePage.Title, _title),
         SendKeys.To(CustomerMaintenancePage.Name, _name),
         SendKeys.To(CustomerMaintenancePage.AddressLine1, _addressLine1),
         SendKeys.To(CustomerMaintenancePage.AddressLine2, _addressLine2),
         SendKeys.To(CustomerMaintenancePage.AddressLine3, _addressLine3),
         SendKeys.To(CustomerMaintenancePage.Postcode, _postcode),
         SendKeys.To(CustomerMaintenancePage.HomePhone, _homePhone),
         SendKeys.To(CustomerMaintenancePage.Mobile, _mobile),
         Click.On(CustomerMaintenancePage.Save));
 }
Пример #17
0
        public void WhenICreateTheFollowingJobForCar(string registration, Table table)
        {
            var values = table.Rows.Single();

            _uiViewInfo = new JobUiViewInfo(
                registration,
                values["Description"],
                values.GetDate("Date"),
                values.GetDecimal("Hours"),
                values.GetInt("Mileage"));

            _actor.AttemptsTo(
                CreateJob.WithDescription(_uiViewInfo.Description)
                .OnDate(_uiViewInfo.Date)
                .TakingHours(_uiViewInfo.Hours)
                .AtMileage(_uiViewInfo.Mileage));
        }
Пример #18
0
        /// <summary>
        /// Refreshes the browser.
        /// </summary>
        /// <param name="actor">The Screenplay Actor.</param>
        /// <param name="driver">The WebDriver.</param>
        public override void PerformAs(IActor actor, IWebDriver driver)
        {
            if (QuitOldDriver)
            {
                actor.Logger.Info("Attempting to quit the current WebDriver instance");

                try
                {
                    actor.AttemptsTo(QuitWebDriver.ForBrowser());
                }
                catch (Exception e)
                {
                    actor.Logger.Warning("Failed to quit the current WebDriver instance");
                    actor.Logger.Warning(e.Message);
                }
            }

            actor.Logger.Info("Setting the new WebDriver instance in the Actor's BrowseTheWeb Ability");
            actor.Using <BrowseTheWeb>().WebDriver = NewDriver;
        }
Пример #19
0
 public void PerformAs(IActor actor)
 {
     try
     {
         Wait.Until(Appearance.Of(LoginPage.LoginOrCreateAccuntButton), IsEqualTo.True());
         actor.AttemptsTo(Click.On(LoginPage.LoginOrCreateAccuntButton));
     }
     catch (Exception e)
     {
         actor.AttemptsTo(Click.On(LoginPage.LoginOrCreateAccuntButton2));
     }
     actor.AttemptsTo(SendKeys.To(LoginPage.EmailInput, Email));
     actor.AttemptsTo(Click.On(LoginPage.ContinueButton));
     actor.AttemptsTo(SendKeys.To(LoginPage.PasswordInput, Password));
     actor.AttemptsTo(Click.On(LoginPage.LoginButton));
 }
Пример #20
0
        /// <summary>
        /// Selects an option by text in a select element.
        /// </summary>
        /// <param name="actor">The screenplay actor.</param>
        /// <param name="driver">The WebDriver.</param>
        public override void PerformAs(IActor actor, IWebDriver driver)
        {
            actor.AttemptsTo(Wait.Until(Existence.Of(Locator), IsEqualTo.True()));

            var select = new SelectElement(driver.FindElement(Locator.Query));

            if (Index != null)
            {
                select.SelectByIndex((int)Index);
            }
            else if (Text != null)
            {
                select.SelectByText(Text, PartialMatch);
            }
            else if (Value != null)
            {
                select.SelectByValue(Value);
            }
            else
            {
                throw new BrowserInteractionException(
                          $"No select method (index, text, or value) provided for Select task");
            }
        }
Пример #21
0
 public void QuitBrowser()
 {
     Actor.AttemptsTo(QuitWebDriver.ForBrowser());
 }
 public void GivenTheDateIs(ScenarioDate currentDate)
 {
     _actor.AttemptsTo(SetCurrentDate.To(currentDate));
 }
Пример #23
0
 /// <summary>
 /// Gets a web element's HTML attribute by name.
 /// </summary>
 /// <param name="actor">The actor.</param>
 /// <param name="driver">The WebDriver.</param>
 /// <returns></returns>
 public override string RequestAs(IActor actor, IWebDriver driver)
 {
     actor.AttemptsTo(Wait.Until(Existence.Of(Locator), IsEqualTo.True()));
     return(driver.FindElement(Locator.Query).GetAttribute(PropertyName));
 }
 public void GivenThereAreNoCustomersNamed(string customerName)
 {
     _actor.AttemptsTo(DeleteCustomers.WithName(customerName));
 }
Пример #25
0
        /// <summary>
        /// Gets the latest window handle and switches to it.
        /// </summary>
        /// <param name="actor">The Screenplay Actor.</param>
        /// <param name="driver">The WebDriver from the BrowseTheWeb Ability.</param>
        public override void PerformAs(IActor actor, IWebDriver driver)
        {
            string handle = actor.AsksFor(WindowHandle.Latest());

            actor.AttemptsTo(SwitchWindow.To(handle));
        }
Пример #26
0
 public void WhenIChangeTheRegistrationOfTo(string currentRegistration, string newRegistration)
 {
     _actor.AttemptsTo(
         Navigate.To(ChangeCarRegistrationPage.Path),
         ChangeCarRegistration.From(currentRegistration).To(newRegistration));
 }
Пример #27
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.AttemptsTo(Wait.Until(Appearance.Of(Locator), IsEqualTo.True()));
     new Actions(driver).MoveToElement(driver.FindElement(Locator.Query)).Perform();
 }
Пример #28
0
 public void GivenThereIsNoCarWithRegistration(string registration)
 {
     _actor.AttemptsTo(DeleteCar.WithRegistration(registration));
 }
Пример #29
0
 /// <summary>
 /// Returns true if the element is enabled on the page; false otherwise.
 /// </summary>
 /// <param name="actor">The actor.</param>
 /// <param name="driver">The WebDriver.</param>
 /// <returns></returns>
 public override bool RequestAs(IActor actor, IWebDriver driver)
 {
     actor.AttemptsTo(Wait.Until(Existence.Of(Locator), IsEqualTo.True()));
     return(driver.FindElement(Locator.Query).Enabled);
 }
Пример #30
0
 /// <summary>
 /// Gets the text of a select Web element's selected option.
 /// </summary>
 /// <param name="actor">The actor.</param>
 /// <param name="driver">The WebDriver.</param>
 /// <returns></returns>
 public override string RequestAs(IActor actor, IWebDriver driver)
 {
     actor.AttemptsTo(Wait.Until(Existence.Of(Locator), IsEqualTo.True()));
     return(new SelectElement(driver.FindElement(Locator.Query)).SelectedOption.Text);
 }