Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Webdriver with Thucydides - TdT@Cluj #18

1,895 views

Published on

Selenium Webdriver with Thucydides

Published in: Technology

Webdriver with Thucydides - TdT@Cluj #18

  1. 1. WebDriver + Thucydides TDT – October 2, 2013 Vlad Voicu, Gabi Kis
  2. 2. Thucydides intro Why use Thucydides framework ? #1 Awesome reports  Fully integrated with WebDriver Multiple browsers supported Native support for DDT Native support for BDD Continuous Integration support Integrated with JIRA
  3. 3. Reports JUnit
  4. 4. Automate testing process From Automation testing to Automated testing
  5. 5. Project Structure Main tools WebDriver What? WebDriver is a browser automation API Used for? UI Functional testing Thucydides What? Testing framework using WebDriver Used for? Running tests, advanced reports +
  6. 6. Project structure Page 1 Page 2 Page 3 Steps Tests
  7. 7. Project structure
  8. 8. • Java JDK o http://www.oracle.com/technetwork/java/javase/downloads/jdk6downloads- 1902814.html o Download and install JDK • Maven o http://maven.apache.org/ o Download maven and unpack it on your drive • Eclipse o http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee- developers/junosr2 o m2eclipse plug-in  Eclipse > Help > Install New Software > Work with: All Available Sites > m2e • Firefox 11 o http://www.oldapps.com/firefox.php?old_firefox=7395 o Disable updates Environment Setup
  9. 9. Path MavenJava Environment Variables
  10. 10. Check setup Open Command Prompt and check versions:
  11. 11. from the command line from the Eclipse IDE How to create a new project
  12. 12. Create a Thucydides project – 1/7
  13. 13. Create a Thucydides project – 2/7 Need to enter a archetype number
  14. 14. Create a Thucydides project – 3/7 How to select the right archetype
  15. 15. Create a Thucydides project – 4/7 Thucydides version number
  16. 16. Create a Thucydides project – 5/7 Group naming Project naming
  17. 17. Create a Thucydides project – 6/7 Version and package
  18. 18. Create a Thucydides project – 7/7
  19. 19. New Thucydides project - Eclipse 1 2 3 4
  20. 20. Quick glance on Generated Project Page Objects Features Steps Tests
  21. 21. Our Project structure
  22. 22. Scope Requirement As a user I want to enter a search term and navigate to a result. Test case: Go to Google search Type a search term Grab a search result from the list Navigate to it Validate the navigation
  23. 23. Creating a page public class GoogleSearchPage{ }
  24. 24. Creating a page public class GoogleSearchPage extends PageObject { }
  25. 25. Creating a page public class GoogleSearchPage extends PageObject { //add constructor due to PageObject public GoogleSearchPage (WebDriver driver){ super(driver); } }
  26. 26. Creating a page public class GoogleSearchPage extends PageObject { … //add your WebElement to the Page private WebElement searchInput; }
  27. 27. Creating a page public class GoogleSearchPage extends PageObject { … @FindBy(|) private WebElement searchInput; }
  28. 28. Creating a page public class GoogleSearchPage extends PageObject { … @FindBy(id=“?”) private WebElement searchInput; }
  29. 29. Grab elements from HTML
  30. 30. Grab elements from HTML Find element id:
  31. 31. Creating a page public class GoogleSearchPage extends PageObject { … @FindBy(id=“gbqfq”) private WebElement searchInput; }
  32. 32. Creating a page public class GoogleSearchPage extends PageObject { … @FindBy(id=“gbqfq”) private WebElement searchInput; @FindBy(id=“gbqfbw”) private WebElement searchButton; }
  33. 33. Creating a page public class GoogleSearchPage extends PageObject { … @FindBy(id=“gbqfq”) private WebElement searchInput; public void inputTerm(String searchTerm){ element(searchInput).waitUntilVisible(); } }
  34. 34. Creating a page public class GoogleSearchPage extends PageObject { … @FindBy(id=“gbqfq”) private WebElement searchInput; public void inputTerm(String searchTerm){ element(searchInput).waitUntilVisible(); searchInput.sendKeys(searchTerm); } }
  35. 35. Creating a page public class GoogleSearchPage extends PageObject { … @FindBy(id=“gbqfbw”) private WebElement searchButton; public void clickOnSearch(String searchTerm){ element(searchButton).waitUntilVisible(); searchButton.click(); } }
  36. 36. Creating Second Page
  37. 37. Creating Second Page
  38. 38. Creating Second Page
  39. 39. Creating Second Page
  40. 40. Creating Second Page public class GoogleResultsPage extends PageObject { … @FindBy(id=“search”) private WebElement searchResults; }
  41. 41. Creating Second Page public class GoogleResultsPage extends PageObject { public void findResult(String resultTerm){ element(searchResults).waitUntilVisible(); waitFor(ExpectedConditions.presenceOfAllElementsLocatedBy (By.cssSelector(“div#search li.g”))); List<WebElement> resultList = searchResults.findElements(By.cssSelector(“li.g”)); for(WebElement elementNow:resultList){ if(elementNow.getText().contains(resultsTerm)){ elementNow.findElement(By.cssSelector(“a.l”)).click(); break; } }}
  42. 42. Adding Steps Steps are recorded in reports Method parameters are captured in the report Step method names are split by camelCase
  43. 43. Adding Steps public class GoogleSteps extends ScenarioSteps{ public GoogleSteps(Pages pages){ super(pages); } }
  44. 44. Adding Steps public class GoogleSteps extends ScenarioSteps{ … public GoogleSearchPage googleSearchPage(){ return getPages.currentPageAt(GoogleSearchPage.class); } public GoogleResultsPage googleResultsPage(){ return getPages.currentPageAt(GoogleResultsPage.class); } }
  45. 45. Adding Steps public class GoogleSteps extends ScenarioSteps{ … @Step public void inputSearchTerm(String search){ googleSearchPage().inputTerm(search); } @Step public void clickOnSearch(){ googleSearchPage(). clickOnSearch(); } }
  46. 46. Adding Steps public class GoogleSteps extends ScenarioSteps{ … @StepGroup public void performSearch(String search){ inputSearchTerm(search); clickOnSearch(); } }
  47. 47. Adding Steps public class GoogleSteps extends ScenarioSteps{ … @Step public void findSearchResult(String search){ googleResultsPage().findResult(search); } }
  48. 48. Adding Steps public class GoogleSteps extends ScenarioSteps{ … @Step public void verifyUrl(String url){ Assert.assertTrue(“Url does not match! ”, getDriver().getCurrentUrl.contains(url)); } }
  49. 49. Adding Steps
  50. 50. Creating a Test @RunWith(ThucydidesRunner.class) public class GoogleSearchTest { @Managed(uniqueSession = true) public WebDriver webdriver; @ManagedPages(defaultUrl = “http://www.google.com”) public Pages pages; @Steps public GoogleSteps googleSteps; }
  51. 51. Creating a Test @RunWith(ThucydidesRunner.class) public class GoogleSearchTest { … @ManagedPages(defaultUrl = “http://www.google.com”) public Pages pages; … @Test public void googleSearchTest(){ googleSteps.performSearch(“evozon”); googleSteps.findSearchResult(“on Twitter”); googleSteps.verifyUrl(“twitter.com/evozon”); } }
  52. 52. Test Test case: Go to Google search Type a search term Grab a search result from the list Navigate to it Validate the navigation @RunWith(ThucydidesRunner.class) public class GoogleSearchTest { … @ManagedPages(defaultUrl = “http://www.google.com”) public Pages pages; … @Test public void googleSearchTest(){ googleSteps.performSearch(“evozon”); googleSteps.findSearchResult(“on Twitter”); googleSteps.verifyUrl(“twitter.com/evozon”); } }
  53. 53. Project Example Project implementation.
  54. 54. Run parameters mvn integration-test will run all tests in the project mvn test –Dtest=[TEST_NAME] will run specific test Note: need to configure in pom.xml mvn test –Dwebdriver.dirver=firefox will specify the browser to run with Note: other browsers need additional configuration
  55. 55. Aggregate reports mvn thucydides:aggregate aggregate final report Report location: Project Root – target – site – thucydides – index.html
  56. 56. Data Driven Testing TestData3 TestData2 TestData1 Test CSV File Outcome 1 Outcome 2 Outcome 3
  57. 57. Data Driven CSV files
  58. 58. Group tests in features and stories
  59. 59. Group tests in suites
  60. 60. Automate testing process Jenkins
  61. 61. Automate testing process
  62. 62. Jenkins integration
  63. 63. Questions
  64. 64. Thank you!

×