WebDriver + Thucydides
TDT – October 2, 2013
Vlad Voicu, Gabi Kis
Thucydides intro
Why use Thucydides framework ?
#1 Awesome reports 
Fully integrated with WebDriver
Multiple browsers sup...
Reports
JUnit
Automate testing process
From Automation testing to Automated testing
Project Structure
Main tools
WebDriver
What?
WebDriver is a browser automation API
Used for?
UI Functional testing
Thucydi...
Project structure
Page 1 Page 2 Page 3
Steps
Tests
Project structure
• Java JDK
o http://www.oracle.com/technetwork/java/javase/downloads/jdk6downloads-
1902814.html
o Download and install JD...
Path
MavenJava
Environment Variables
Check setup
Open Command Prompt and check versions:
from the command line
from the Eclipse IDE
How to create a new project
Create a Thucydides project – 1/7
Create a Thucydides project – 2/7
Need to enter a archetype number
Create a Thucydides project – 3/7
How to select the right archetype
Create a Thucydides project – 4/7
Thucydides version number
Create a Thucydides project – 5/7
Group naming
Project naming
Create a Thucydides project – 6/7
Version and package
Create a Thucydides project – 7/7
New Thucydides project - Eclipse
1
2
3
4
Quick glance on Generated Project
Page Objects
Features
Steps
Tests
Our Project structure
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 ...
Creating a page
public class GoogleSearchPage{
}
Creating a page
public class GoogleSearchPage extends PageObject {
}
Creating a page
public class GoogleSearchPage extends PageObject {
//add constructor due to PageObject
public GoogleSearch...
Creating a page
public class GoogleSearchPage extends PageObject {
…
//add your WebElement to the Page
private WebElement ...
Creating a page
public class GoogleSearchPage extends PageObject {
…
@FindBy(|)
private WebElement searchInput;
}
Creating a page
public class GoogleSearchPage extends PageObject {
…
@FindBy(id=“?”)
private WebElement searchInput;
}
Grab elements from HTML
Grab elements from HTML
Find element id:
Creating a page
public class GoogleSearchPage extends PageObject {
…
@FindBy(id=“gbqfq”)
private WebElement searchInput;
}
Creating a page
public class GoogleSearchPage extends PageObject {
…
@FindBy(id=“gbqfq”)
private WebElement searchInput;
@...
Creating a page
public class GoogleSearchPage extends PageObject {
…
@FindBy(id=“gbqfq”)
private WebElement searchInput;
p...
Creating a page
public class GoogleSearchPage extends PageObject {
…
@FindBy(id=“gbqfq”)
private WebElement searchInput;
p...
Creating a page
public class GoogleSearchPage extends PageObject {
…
@FindBy(id=“gbqfbw”)
private WebElement searchButton;...
Creating Second Page
Creating Second Page
Creating Second Page
Creating Second Page
Creating Second Page
public class GoogleResultsPage extends PageObject {
…
@FindBy(id=“search”)
private WebElement searchR...
Creating Second Page
public class GoogleResultsPage extends PageObject {
public void findResult(String resultTerm){
elemen...
Adding Steps
Steps are recorded in reports
Method parameters are captured in the report
Step method names are split by cam...
Adding Steps
public class GoogleSteps extends ScenarioSteps{
public GoogleSteps(Pages pages){
super(pages);
}
}
Adding Steps
public class GoogleSteps extends ScenarioSteps{
…
public GoogleSearchPage googleSearchPage(){
return getPages...
Adding Steps
public class GoogleSteps extends ScenarioSteps{
…
@Step
public void inputSearchTerm(String search){
googleSea...
Adding Steps
public class GoogleSteps extends ScenarioSteps{
…
@StepGroup
public void performSearch(String search){
inputS...
Adding Steps
public class GoogleSteps extends ScenarioSteps{
…
@Step
public void findSearchResult(String search){
googleRe...
Adding Steps
public class GoogleSteps extends ScenarioSteps{
…
@Step
public void verifyUrl(String url){
Assert.assertTrue(...
Adding Steps
Creating a Test
@RunWith(ThucydidesRunner.class)
public class GoogleSearchTest {
@Managed(uniqueSession = true)
public Web...
Creating a Test
@RunWith(ThucydidesRunner.class)
public class GoogleSearchTest {
…
@ManagedPages(defaultUrl = “http://www....
Test
Test case:
Go to Google search
Type a search term
Grab a search result from the list
Navigate to it
Validate the navi...
Project Example
Project implementation.
Run parameters
mvn integration-test
will run all tests in the project
mvn test –Dtest=[TEST_NAME]
will run specific test
N...
Aggregate reports
mvn thucydides:aggregate
aggregate final report
Report location:
Project Root
– target
– site
– thucydid...
Data Driven Testing
TestData3
TestData2
TestData1
Test
CSV
File
Outcome
1
Outcome
2
Outcome
3
Data Driven
CSV files
Group tests in features and stories
Group tests in suites
Automate testing process
Jenkins
Automate testing process
Jenkins integration
Questions
Thank you!
Upcoming SlideShare
Loading in …5
×

Webdriver with Thucydides - TdT@Cluj #18

1,810 views

Published on

Selenium Webdriver with Thucydides

Published in: Technology
1 Comment
1 Like
Statistics
Notes
No Downloads
Views
Total views
1,810
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
43
Comments
1
Likes
1
Embeds 0
No embeds

No notes for slide
  • Bonus pelangatoateastea a fostcaRapoartelearataumultmai bine siEchipa de sales a reusitsaprindanistecontractemaiinteresante.Story Noul Framework – Tocmaidescoperisemframeworkul – am fostchemat de team Lead – new ProjectCand am auzitclientu mi-o picat fata. Probabilatiauzit de ei– Press Association – UK – ceamai mare agentie de presa din anglia
  • Problemele au continuatsaapara…acumatrebuiasaluamdouavariante de rapoartesisa le comaramintreele.generamrapoartemari la fiecare run Nevoie de a vedeadiferenteintrerapoarterapide
  • API - Application programming interface - in term this means it is not language specific. You can write your code in the language of your choice.
  • http://www.oracle.com/technetwork/java/javase/downloads/jdk6downloads-1902814.htmlhttp://maven.apache.org/http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/junosr2
  • http://www.oracle.com/technetwork/java/javase/downloads/jdk6downloads-1902814.htmlhttp://maven.apache.org/http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/junosr2
  • Oxford University Press Aplicatia era un document management system. ProvocariTestare cu 5 tipuri de useriptfiecare flow Jenkins for CISolutiaDDT – Data Driven Testing – un scenariu era rulatpentru 5 tipuri de utilizatorisiasteptamdiferiteoutcomeuri
  • Jenkinseste un tool de continuous integrationContinuous integration (CI) is a software engineering practice in which isolated changes are immediately tested and reported on when they are added to a larger code base.Practiccandechipa de dev face un nou deploy de aplicatieTestelesuntporniteimediatdupa deployRuleazatestelesiai un raport instant… de passed and failed
  • Jenkinseste un tool de continuous integrationPracticcandechipa de dev face un nou deploy de aplicatieTestelesuntporniteimediatdupa deployRuleazatestelesiai un raport instant… de passed and failed
  • 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!

    ×