64
WebDriver + Thucydides TDT – October 2, 2013 Vlad Voicu, Gabi Kis

Webdriver with Thucydides - TdT@Cluj #18

Embed Size (px)

Citation preview

Page 1: Webdriver with Thucydides - TdT@Cluj #18

WebDriver + Thucydides

TDT – October 2, 2013Vlad Voicu, Gabi Kis

Page 2: Webdriver with Thucydides - TdT@Cluj #18

Thucydides introWhy use Thucydides framework ?

#1 Awesome reports Fully integrated with WebDriverMultiple browsers supportedNative support for DDT Native support for BDDContinuous Integration supportIntegrated with JIRA

Page 3: Webdriver with Thucydides - TdT@Cluj #18

ReportsJUnit

Page 4: Webdriver with Thucydides - TdT@Cluj #18

Automate testing processFrom Automation testing to Automated testing

Page 5: Webdriver with Thucydides - TdT@Cluj #18

Project Structure Main tools

WebDriverWhat?

WebDriver is a browser automation APIUsed for?

UI Functional testing

ThucydidesWhat?

Testing framework using WebDriverUsed for?

Running tests, advanced reports

+

Page 6: Webdriver with Thucydides - TdT@Cluj #18

Project structure

Page 1 Page 2 Page 3

Steps

Tests

Page 7: Webdriver with Thucydides - TdT@Cluj #18

Project structure

Page 8: Webdriver with Thucydides - TdT@Cluj #18

• Java JDKo http://www.oracle.com/technetwork/java/javase/downloads/jdk6downloads-19

02814.htmlo Download and install JDK

• Maven o http://maven.apache.org/o Download maven and unpack it on your drive

• Eclipseo http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/j

unosr2o m2eclipse plug-in

Eclipse > Help > Install New Software > Work with: All Available Sites > m2e

• Firefox 11o http://www.oldapps.com/firefox.php?old_firefox=7395o Disable updates

Environment Setup

Page 9: Webdriver with Thucydides - TdT@Cluj #18

Path

Maven Java

Environment Variables

Page 10: Webdriver with Thucydides - TdT@Cluj #18

Check setupOpen Command Prompt and check versions:

Page 11: Webdriver with Thucydides - TdT@Cluj #18

from the command line

from the Eclipse IDE

How to create a new project

Page 12: Webdriver with Thucydides - TdT@Cluj #18

Create a Thucydides project – 1/7

Page 13: Webdriver with Thucydides - TdT@Cluj #18

Create a Thucydides project – 2/7Need to enter a archetype number

Page 14: Webdriver with Thucydides - TdT@Cluj #18

Create a Thucydides project – 3/7How to select the right archetype

Page 15: Webdriver with Thucydides - TdT@Cluj #18

Create a Thucydides project – 4/7Thucydides version number

Page 16: Webdriver with Thucydides - TdT@Cluj #18

Create a Thucydides project – 5/7Group naming

Project naming

Page 17: Webdriver with Thucydides - TdT@Cluj #18

Create a Thucydides project – 6/7

Version and package

Page 18: Webdriver with Thucydides - TdT@Cluj #18

Create a Thucydides project – 7/7

Page 19: Webdriver with Thucydides - TdT@Cluj #18

New Thucydides project - Eclipse

1

2

3

4

Page 20: Webdriver with Thucydides - TdT@Cluj #18

Quick glance on Generated Project

Page Objects

Features

Steps

Tests

Page 21: Webdriver with Thucydides - TdT@Cluj #18

Our Project structure

Page 22: Webdriver with Thucydides - TdT@Cluj #18

ScopeRequirementAs a user I want to enter a search term and navigate to a result.

Test case:Go to Google searchType a search term Grab a search result from the listNavigate to it Validate the navigation

Page 23: Webdriver with Thucydides - TdT@Cluj #18

Creating a pagepublic class GoogleSearchPage{}

Page 24: Webdriver with Thucydides - TdT@Cluj #18

Creating a pagepublic class GoogleSearchPage extends PageObject {}

Page 25: Webdriver with Thucydides - TdT@Cluj #18

Creating a pagepublic class GoogleSearchPage extends PageObject { //add constructor due to PageObject public GoogleSearchPage (WebDriver driver){

super(driver); }}

Page 26: Webdriver with Thucydides - TdT@Cluj #18

Creating a pagepublic class GoogleSearchPage extends PageObject {… //add your WebElement to the Page

private WebElement searchInput;}

Page 27: Webdriver with Thucydides - TdT@Cluj #18

Creating a pagepublic class GoogleSearchPage extends PageObject {…

@FindBy(|)private WebElement searchInput;

}

Page 28: Webdriver with Thucydides - TdT@Cluj #18

Creating a pagepublic class GoogleSearchPage extends PageObject {…

@FindBy(id=“?”)private WebElement searchInput;

}

Page 29: Webdriver with Thucydides - TdT@Cluj #18

Grab elements from HTML

Page 30: Webdriver with Thucydides - TdT@Cluj #18

Grab elements from HTMLFind element id:

Page 31: Webdriver with Thucydides - TdT@Cluj #18

Creating a pagepublic class GoogleSearchPage extends PageObject {…

@FindBy(id=“gbqfq”)private WebElement searchInput;

}

Page 32: Webdriver with Thucydides - TdT@Cluj #18

Creating a pagepublic class GoogleSearchPage extends PageObject {…

@FindBy(id=“gbqfq”)private WebElement searchInput;

@FindBy(id=“gbqfbw”)private WebElement searchButton;

}

Page 33: Webdriver with Thucydides - TdT@Cluj #18

Creating a pagepublic class GoogleSearchPage extends PageObject {…

@FindBy(id=“gbqfq”)private WebElement searchInput;

public void inputTerm(String searchTerm){element(searchInput).waitUntilVisible();

}}

Page 34: Webdriver with Thucydides - TdT@Cluj #18

Creating a pagepublic class GoogleSearchPage extends PageObject {…

@FindBy(id=“gbqfq”)private WebElement searchInput;

public void inputTerm(String searchTerm){element(searchInput).waitUntilVisible();searchInput.sendKeys(searchTerm);

}}

Page 35: Webdriver with Thucydides - TdT@Cluj #18

Creating a pagepublic class GoogleSearchPage extends PageObject {…

@FindBy(id=“gbqfbw”)private WebElement searchButton;

public void clickOnSearch(String searchTerm){element(searchButton).waitUntilVisible();searchButton.click();

}

}

Page 36: Webdriver with Thucydides - TdT@Cluj #18

Creating Second Page

Page 37: Webdriver with Thucydides - TdT@Cluj #18

Creating Second Page

Page 38: Webdriver with Thucydides - TdT@Cluj #18

Creating Second Page

Page 39: Webdriver with Thucydides - TdT@Cluj #18

Creating Second Page

Page 40: Webdriver with Thucydides - TdT@Cluj #18

Creating Second Pagepublic class GoogleResultsPage extends PageObject {…

@FindBy(id=“search”)private WebElement searchResults;

}

Page 41: Webdriver with Thucydides - TdT@Cluj #18

Creating Second Pagepublic 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;}

}}

Page 42: Webdriver with Thucydides - TdT@Cluj #18

Adding Steps

Steps are recorded in reports

Method parameters are captured in the report

Step method names are split by camelCase

Page 43: Webdriver with Thucydides - TdT@Cluj #18

Adding Stepspublic class GoogleSteps extends ScenarioSteps{

public GoogleSteps(Pages pages){super(pages);

}}

Page 44: Webdriver with Thucydides - TdT@Cluj #18

Adding Stepspublic class GoogleSteps extends ScenarioSteps{…

public GoogleSearchPage googleSearchPage(){return

getPages.currentPageAt(GoogleSearchPage.class);}

public GoogleResultsPage googleResultsPage(){return

getPages.currentPageAt(GoogleResultsPage.class);}

}

Page 45: Webdriver with Thucydides - TdT@Cluj #18

Adding Stepspublic class GoogleSteps extends ScenarioSteps{…

@Steppublic void inputSearchTerm(String search){

googleSearchPage().inputTerm(search);}

@Steppublic void clickOnSearch(){

googleSearchPage(). clickOnSearch();}

}

Page 46: Webdriver with Thucydides - TdT@Cluj #18

Adding Stepspublic class GoogleSteps extends ScenarioSteps{…

@StepGrouppublic void performSearch(String search){

inputSearchTerm(search);clickOnSearch();

}

}

Page 47: Webdriver with Thucydides - TdT@Cluj #18

Adding Stepspublic class GoogleSteps extends ScenarioSteps{…

@Steppublic void findSearchResult(String search){

googleResultsPage().findResult(search);}

}

Page 48: Webdriver with Thucydides - TdT@Cluj #18

Adding Stepspublic class GoogleSteps extends ScenarioSteps{…

@Steppublic void verifyUrl(String url){

Assert.assertTrue(“Url does not match! ”, getDriver().getCurrentUrl.contains(url));

}}

Page 49: Webdriver with Thucydides - TdT@Cluj #18

Adding Steps

Page 50: Webdriver with Thucydides - TdT@Cluj #18

Creating a Test@RunWith(ThucydidesRunner.class)public class GoogleSearchTest {

@Managed(uniqueSession = true)public WebDriver webdriver;

@ManagedPages(defaultUrl = “http://www.google.com”)

public Pages pages;

@Stepspublic GoogleSteps googleSteps;

}

Page 51: Webdriver with Thucydides - TdT@Cluj #18

Creating a Test@RunWith(ThucydidesRunner.class)public class GoogleSearchTest {…

@ManagedPages(defaultUrl = “http://www.google.com”)

public Pages pages;…

@Testpublic void googleSearchTest(){

googleSteps.performSearch(“evozon”); googleSteps.findSearchResult(“on Twitter”); googleSteps.verifyUrl(“twitter.com/evozon”);

}}

Page 52: Webdriver with Thucydides - TdT@Cluj #18

Test

Test case:Go to Google searchType a search term Grab a search result from the listNavigate 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”); }}

Page 53: Webdriver with Thucydides - TdT@Cluj #18

Project ExampleProject implementation.

Page 54: Webdriver with Thucydides - TdT@Cluj #18

Run parametersmvn integration-test

will run all tests in the project

mvn test –Dtest=[TEST_NAME]will run specific testNote: need to configure in pom.xml

mvn test –Dwebdriver.dirver=firefoxwill specify the browser to run withNote: other browsers need additional configuration

Page 55: Webdriver with Thucydides - TdT@Cluj #18

Aggregate reportsmvn thucydides:aggregate

aggregate final report

Report location:Project Root – target – site – thucydides – index.html

Page 56: Webdriver with Thucydides - TdT@Cluj #18

Data Driven Testing

TestData3

TestData2

TestData1

Test

CSV File

Outcome 1

Outcome 2

Outcome 3

Page 57: Webdriver with Thucydides - TdT@Cluj #18

Data Driven CSV files

Page 58: Webdriver with Thucydides - TdT@Cluj #18

Group tests in features and stories

Page 59: Webdriver with Thucydides - TdT@Cluj #18

Group tests in suites

Page 60: Webdriver with Thucydides - TdT@Cluj #18

Automate testing process

Jenkins

Page 61: Webdriver with Thucydides - TdT@Cluj #18

Automate testing process

Page 62: Webdriver with Thucydides - TdT@Cluj #18

Jenkins integration

Page 63: Webdriver with Thucydides - TdT@Cluj #18

Questions

Page 64: Webdriver with Thucydides - TdT@Cluj #18

Thank you!