O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

Session on "The Screenplay Pattern: Better Interactions for Better Automation" By Andrew Knight

Andrew Knight delivered a session on "The Screenplay Pattern: Better Interactions for Better Automation" at #SeleniumSummit21

Andrew is the “Automation Panda” – an engineer, consultant, and international speaker who builds solutions for software testing problems. He has designed and built robust test automation projects for operating systems, service APIs, and Web apps with thousands of tests running continuously. He is the lead developer for Boa Constrictor, the .NET Screenplay Pattern.

To know more about #SeleniumSummit21 please check :
https://seleniumsummit21.agiletestingalliance.org/

  • Seja o primeiro a comentar

  • Seja a primeira pessoa a gostar disto

Session on "The Screenplay Pattern: Better Interactions for Better Automation" By Andrew Knight

  1. 1. IWebDriver driver = new ChromeDriver();
  2. 2. IWebDriver driver = new ChromeDriver(); // Open the search engine driver.Navigate().GoToUrl("https://duckduckgo.com/");
  3. 3. IWebDriver driver = new ChromeDriver(); // Open the search engine driver.Navigate().GoToUrl("https://duckduckgo.com/"); // Search for a phrase driver.FindElement(By.Id("search_form_input_homepage")).SendKeys("panda"); driver.FindElement(By.Id("search_button_homepage")).Click();
  4. 4. IWebDriver driver = new ChromeDriver(); // Open the search engine driver.Navigate().GoToUrl("https://duckduckgo.com/"); // Search for a phrase driver.FindElement(By.Id("search_form_input_homepage")).SendKeys("panda"); driver.FindElement(By.Id("search_button_homepage")).Click(); // Verify results appear driver.Title.ToLower().Should().Contain("panda"); driver.FindElements(By.CssSelector("a.result__a")).Should().BeGreaterThan(0);
  5. 5. IWebDriver driver = new ChromeDriver(); // Open the search engine driver.Navigate().GoToUrl("https://duckduckgo.com/"); // Search for a phrase driver.FindElement(By.Id("search_form_input_homepage")).SendKeys("panda"); driver.FindElement(By.Id("search_button_homepage")).Click(); // Verify results appear driver.Title.ToLower().Should().Contain("panda"); driver.FindElements(By.CssSelector("a.result__a")).Should().BeGreaterThan(0); driver.Quit();
  6. 6. IWebDriver driver = new ChromeDriver(); // Open the search engine driver.Navigate().GoToUrl("https://duckduckgo.com/"); // Search for a phrase driver.FindElement(By.Id("search_form_input_homepage")).SendKeys("panda"); driver.FindElement(By.Id("search_button_homepage")).Click(); // Verify results appear driver.Title.ToLower().Should().Contain("panda"); driver.FindElements(By.CssSelector("a.result__a")).Should().BeGreaterThan(0); driver.Quit();
  7. 7. IWebDriver driver = new ChromeDriver(); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30); // Open the search engine driver.Navigate().GoToUrl("https://duckduckgo.com/"); // Search for a phrase driver.FindElement(By.Id("search_form_input_homepage")).SendKeys("panda"); driver.FindElement(By.Id("search_button_homepage")).Click(); // Verify results appear driver.Title.ToLower().Should().Contain("panda"); driver.FindElements(By.CssSelector("a.result__a")).Should().BeGreaterThan(0); driver.Quit();
  8. 8. IWebDriver driver = new ChromeDriver(); WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); // Open the search engine driver.Navigate().GoToUrl("https://duckduckgo.com/"); // Search for a phrase wait.Until(d => d.FindElements(By.Id("search_form_input_homepage")).Count > 0); driver.FindElement(By.Id("search_form_input_homepage")).SendKeys("panda"); driver.FindElement(By.Id("search_button_homepage")).Click(); // Verify results appear wait.Until(d => d.Title.ToLower().Contains("panda")); wait.Until(d => d.FindElements(By.CssSelector("a.result__a"))).Count > 0); driver.Quit();
  9. 9. IWebDriver driver = new ChromeDriver(); WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); // Open the search engine driver.Navigate().GoToUrl("https://duckduckgo.com/"); // Search for a phrase wait.Until(d => d.FindElements(By.Id("search_form_input_homepage")).Count > 0); driver.FindElement(By.Id("search_form_input_homepage")).SendKeys("panda"); driver.FindElement(By.Id("search_button_homepage")).Click(); // Verify results appear wait.Until(d => d.Title.ToLower().Contains("panda")); wait.Until(d => d.FindElements(By.CssSelector("a.result__a"))).Count > 0); driver.Quit();
  10. 10. IWebDriver driver = new ChromeDriver(); WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); driver.Navigate().GoToUrl("https://duckduckgo.com/"); wait.Until(d => d.FindElements(By.Id("search_form_input_homepage")).Count > 0); driver.FindElement(By.Id("search_form_input_homepage")).SendKeys("panda"); driver.FindElement(By.Id("search_button_homepage")).Click(); wait.Until(d => d.Title.ToLower().Contains("panda")); wait.Until(d => d.FindElements(By.CssSelector("a.result__a"))).Count > 0); driver.Quit();
  11. 11. public class SearchPage { }
  12. 12. public class SearchPage { public const string Url = "https://duckduckgo.com/"; public static By SearchInput => By.Id("search_form_input_homepage"); public static By SearchButton => By.Id("search_button_homepage"); }
  13. 13. public class SearchPage { public const string Url = "https://duckduckgo.com/"; public static By SearchInput => By.Id("search_form_input_homepage"); public static By SearchButton => By.Id("search_button_homepage"); public IWebDriver Driver { get; private set; } public SearchPage(IWebDriver driver) => Driver = driver; }
  14. 14. public class SearchPage { public const string Url = "https://duckduckgo.com/"; public static By SearchInput => By.Id("search_form_input_homepage"); public static By SearchButton => By.Id("search_button_homepage"); public IWebDriver Driver { get; private set; } public SearchPage(IWebDriver driver) => Driver = driver; public void Load() => driver.Navigate().GoToUrl(Url); }
  15. 15. public class SearchPage { public const string Url = "https://duckduckgo.com/"; public static By SearchInput => By.Id("search_form_input_homepage"); public static By SearchButton => By.Id("search_button_homepage"); public IWebDriver Driver { get; private set; } public SearchPage(IWebDriver driver) => Driver = driver; public void Load() => driver.Navigate().GoToUrl(Url); public void Search(string phrase) { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)); wait.Until(d => d.FindElements(SearchInput).Count > 0); driver.FindElement(SearchInput).SendKeys(phrase); driver.FindElement(SearchButton).Click(); } }
  16. 16. IWebDriver driver = new ChromeDriver(); SearchPage searchPage = new SearchPage(driver); searchPage.Load(); searchPage.Search(“panda”);
  17. 17. IWebDriver driver = new ChromeDriver(); SearchPage searchPage = new SearchPage(driver); searchPage.Load(); searchPage.Search(“panda”); ResultPage resultPage = new ResultPage(driver); resultPage.WaitForTitle(“panda”); resultPage.WaitForResultLinks(); driver.Quit();
  18. 18. public class AnyPage { // ... }
  19. 19. public class AnyPage { // ... public void ClickButton() { Wait.Until(d => d.FindElements(Button).Count > 0); driver.FindElement(Button).Click(); } }
  20. 20. public class AnyPage { // ... public void ClickButton() { Wait.Until(d => d.FindElements(Button).Count > 0); driver.FindElement(Button).Click(); } public void ClickOtherButton() { Wait.Until(d => d.FindElements(OtherButton).Count > 0); driver.FindElement(OtherButton).Click(); } }
  21. 21. public class AnyPage { // ... public void ClickButton() { Wait.Until(d => d.FindElements(Button).Count > 0); driver.FindElement(Button).Click(); } public void ClickOtherButton() { Wait.Until(d => d.FindElements(OtherButton).Count > 0); driver.FindElement(OtherButton).Click(); } }
  22. 22. public class BasePage { }
  23. 23. public class BasePage { public IWebDriver Driver { get; private set; } public WebDriverWait Wait { get; private set; } public SearchPage(IWebDriver driver) { Driver = driver; Wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(30)); } }
  24. 24. public class BasePage { public IWebDriver Driver { get; private set; } public WebDriverWait Wait { get; private set; } public SearchPage(IWebDriver driver) { Driver = driver; Wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(30)); } protected void Click(By locator) { Wait.Until(d => d.FindElements(locator).Count > 0); driver.FindElement(locator).Click(); } }
  25. 25. public class AnyPage : BasePage { // ... public AnyPage(IWebDriver driver) : base(driver) {} public void ClickButton() => Click(Button); public void ClickOtherButton() => Click(OtherButton); }
  26. 26. public class AnyPage : BasePage { // ... public void ClickButton() => Click(Button); public void ClickOtherButton() => Click(OtherButton); public void ButtonText() => Text(Button); public void OtherButtonText() => Text(OtherButton); public void IsButtonDisplayed() => IsDisplayed(Button); public void IsButtonDisplayed() => IsDisplayed(OtherButton); }
  27. 27. • • • • •
  28. 28. // NuGet Packages: // Boa.Constrictor // FluentAssertions // Selenium.Support // Selenium.WebDriver using Boa.Constrictor.Logging; using Boa.Constrictor.Screenplay; using Boa.Constrictor.WebDriver; using FluentAssertions; using OpenQA.Selenium.Chrome; using static Boa.Constrictor.WebDriver.WebLocator;
  29. 29. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger());
  30. 30. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver()));
  31. 31. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver())); public class BrowseTheWeb : IAbility { public IWebDriver WebDriver { get; } private BrowseTheWeb(IWebDriver driver) => WebDriver = driver;   public static BrowseTheWeb With(IWebDriver driver) => new BrowseTheWeb(driver); }
  32. 32. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver())); public static class SearchPage { public const string Url = "https://www.duckduckgo.com/";   public static IWebLocator SearchInput => L( "DuckDuckGo Search Input", By.Id("search_form_input_homepage")); }
  33. 33. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver())); actor.AttemptsTo(Navigate.ToUrl(SearchPage.Url));
  34. 34. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver())); actor.AttemptsTo(Navigate.ToUrl(SearchPage.Url)); public void AttemptsTo(ITask task) { task.PerformAs(this); }
  35. 35. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver())); actor.AttemptsTo(Navigate.ToUrl(SearchPage.Url)); public class Navigate : ITask { private string Url { get; set; }   private Navigate(string url) => Url = url;   public static Navigate ToUrl(string url) => new Navigate(url);   public void PerformAs(IActor actor) { var driver = actor.Using<BrowseTheWeb>().WebDriver; driver.Navigate().GoToUrl(Url); } }
  36. 36. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver())); actor.AttemptsTo(Navigate.ToUrl(SearchPage.Url)); public class Navigate : ITask { private string Url { get; set; }   private Navigate(string url) => Url = url;   public static Navigate ToUrl(string url) => new Navigate(url);   public void PerformAs(IActor actor) { var driver = actor.Using<BrowseTheWeb>().WebDriver; driver.Navigate().GoToUrl(Url); } }
  37. 37. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver())); actor.AttemptsTo(Navigate.ToUrl(SearchPage.Url)); public static class SearchPage { public const string Url = "https://www.duckduckgo.com/";   public static IWebLocator SearchInput => L( "DuckDuckGo Search Input", By.Id("search_form_input_homepage")); }
  38. 38. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver())); actor.AttemptsTo(Navigate.ToUrl(SearchPage.Url)); actor.AskingFor(ValueAttribute.Of(SearchPage.SearchInput)).Should().BeEmpty();
  39. 39. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver())); actor.AttemptsTo(Navigate.ToUrl(SearchPage.Url)); actor.AskingFor(ValueAttribute.Of(SearchPage.SearchInput)).Should().BeEmpty(); public TAnswer AskingFor<TAnswer>(IQuestion<TAnswer> question) { return question.RequestAs(this); }
  40. 40. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver())); actor.AttemptsTo(Navigate.ToUrl(SearchPage.Url)); actor.AskingFor(ValueAttribute.Of(SearchPage.SearchInput)).Should().BeEmpty(); public class ValueAttribute : IQuestion<string> { public IWebLocator Locator { get; }   private ValueAttribute(IWebLocator locator) => Locator = locator;   public static ValueAttribute Of(IWebLocator locator) => new ValueAttribute(locator);   public string RequestAs(IActor actor) { var driver = actor.Using<BrowseTheWeb>().WebDriver; actor.AttemptsTo(Wait.Until(Existence.Of(Locator), IsEqualTo.True())); return driver.FindElement(Locator.Query).GetAttribute("value"); } }
  41. 41. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver())); actor.AttemptsTo(Navigate.ToUrl(SearchPage.Url)); actor.AskingFor(ValueAttribute.Of(SearchPage.SearchInput)).Should().BeEmpty(); public class ValueAttribute : IQuestion<string> { public IWebLocator Locator { get; }   private ValueAttribute(IWebLocator locator) => Locator = locator;   public static ValueAttribute Of(IWebLocator locator) => new ValueAttribute(locator);   public string RequestAs(IActor actor) { var driver = actor.Using<BrowseTheWeb>().WebDriver; actor.AttemptsTo(Wait.Until(Existence.Of(Locator), IsEqualTo.True())); return driver.FindElement(Locator.Query).GetAttribute("value"); } }
  42. 42. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver())); actor.AttemptsTo(Navigate.ToUrl(SearchPage.Url)); actor.AskingFor(ValueAttribute.Of(SearchPage.SearchInput)).Should().BeEmpty(); public static class SearchPage { public const string Url = "https://www.duckduckgo.com/";   public static IWebLocator SearchInput => L( "DuckDuckGo Search Input", By.Id("search_form_input_homepage")); }
  43. 43. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver())); actor.AttemptsTo(Navigate.ToUrl(SearchPage.Url)); actor.AskingFor(ValueAttribute.Of(SearchPage.SearchInput)).Should().BeEmpty();
  44. 44. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver())); actor.AttemptsTo(Navigate.ToUrl(SearchPage.Url)); actor.AskingFor(ValueAttribute.Of(SearchPage.SearchInput)).Should().BeEmpty(); actor.AttemptsTo(SearchDuckDuckGo.For("panda"));
  45. 45. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver())); actor.AttemptsTo(Navigate.ToUrl(SearchPage.Url)); actor.AskingFor(ValueAttribute.Of(SearchPage.SearchInput)).Should().BeEmpty(); actor.AttemptsTo(SearchDuckDuckGo.For("panda")); public class SearchDuckDuckGo : ITask { public string Phrase { get; }   private SearchDuckDuckGo(string phrase) => Phrase = phrase;   public static SearchDuckDuckGo For(string phrase) => new SearchDuckDuckGo(phrase);   public void PerformAs(IActor actor) { actor.AttemptsTo(SendKeys.To(SearchPage.SearchInput, Phrase)); actor.AttemptsTo(Click.On(SearchPage.SearchButton)); } }
  46. 46. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver())); actor.AttemptsTo(Navigate.ToUrl(SearchPage.Url)); actor.AskingFor(ValueAttribute.Of(SearchPage.SearchInput)).Should().BeEmpty(); actor.AttemptsTo(SearchDuckDuckGo.For("panda")); public class SearchDuckDuckGo : ITask { public string Phrase { get; }   private SearchDuckDuckGo(string phrase) => Phrase = phrase;   public static SearchDuckDuckGo For(string phrase) => new SearchDuckDuckGo(phrase);   public void PerformAs(IActor actor) { actor.AttemptsTo(SendKeys.To(SearchPage.SearchInput, Phrase)); actor.AttemptsTo(Click.On(SearchPage.SearchButton)); } }
  47. 47. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver())); actor.AttemptsTo(Navigate.ToUrl(SearchPage.Url)); actor.AskingFor(ValueAttribute.Of(SearchPage.SearchInput)).Should().BeEmpty(); actor.AttemptsTo(SearchDuckDuckGo.For("panda"));
  48. 48. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver())); actor.AttemptsTo(Navigate.ToUrl(SearchPage.Url)); actor.AskingFor(ValueAttribute.Of(SearchPage.SearchInput)).Should().BeEmpty(); actor.AttemptsTo(SearchDuckDuckGo.For("panda")); actor.AttemptsTo(Wait.Until(Appearance.Of(ResultPage.ResultLinks), IsEqualTo.True()));
  49. 49. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver())); actor.AttemptsTo(Navigate.ToUrl(SearchPage.Url)); actor.AskingFor(ValueAttribute.Of(SearchPage.SearchInput)).Should().BeEmpty(); actor.AttemptsTo(SearchDuckDuckGo.For("panda")); actor.AttemptsTo(Wait.Until(Appearance.Of(ResultPage.ResultLinks), IsEqualTo.True()));
  50. 50. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver())); actor.AttemptsTo(Navigate.ToUrl(SearchPage.Url)); actor.AskingFor(ValueAttribute.Of(SearchPage.SearchInput)).Should().BeEmpty(); actor.AttemptsTo(SearchDuckDuckGo.For("panda")); actor.AttemptsTo(Wait.Until(Appearance.Of(ResultPage.ResultLinks), IsEqualTo.True())); public static IWebLocator ResultLinks => L( "DuckDuckGo Result Page Links", By.ClassName("result__a"));
  51. 51. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver())); actor.AttemptsTo(Navigate.ToUrl(SearchPage.Url)); actor.AskingFor(ValueAttribute.Of(SearchPage.SearchInput)).Should().BeEmpty(); actor.AttemptsTo(SearchDuckDuckGo.For("panda")); actor.AttemptsTo(Wait.Until(Appearance.Of(ResultPage.ResultLinks), IsEqualTo.True()));
  52. 52. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver())); actor.AttemptsTo(Navigate.ToUrl(SearchPage.Url)); actor.AskingFor(ValueAttribute.Of(SearchPage.SearchInput)).Should().BeEmpty(); actor.AttemptsTo(SearchDuckDuckGo.For("panda")); actor.AttemptsTo(Wait.Until(Appearance.Of(ResultPage.ResultLinks), IsEqualTo.True()));
  53. 53. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver())); actor.AttemptsTo(Navigate.ToUrl(SearchPage.Url)); actor.AskingFor(ValueAttribute.Of(SearchPage.SearchInput)).Should().BeEmpty(); actor.AttemptsTo(SearchDuckDuckGo.For("panda")); actor.AttemptsTo(Wait.Until(Appearance.Of(ResultPage.ResultLinks), IsEqualTo.True())); actor.AttemptsTo(QuitWebDriver.ForBrowser());
  54. 54. IActor actor = new Actor(name: "Andy", logger: new ConsoleLogger()); actor.Can(BrowseTheWeb.With(new ChromeDriver())); actor.AttemptsTo(Navigate.ToUrl(SearchPage.Url)); actor.AskingFor(ValueAttribute.Of(SearchPage.SearchInput)).Should().BeEmpty(); actor.AttemptsTo(SearchDuckDuckGo.For("panda")); actor.AttemptsTo(Wait.Until(Appearance.Of(ResultPage.ResultLinks), IsEqualTo.True())); actor.AttemptsTo(QuitWebDriver.ForBrowser());
  55. 55.
  56. 56. • •
  57. 57. • • •
  58. 58. • • • •

×