Webdriver with Thucydides - TdT@Cluj #18

Post on 22-Mar-2017

1.820 views 0 download

Transcript of Webdriver with Thucydides - TdT@Cluj #18

WebDriver + Thucydides

TDT – October 2, 2013Vlad Voicu, Gabi Kis

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

ReportsJUnit

Automate testing processFrom Automation testing to Automated testing

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

+

Project structure

Page 1 Page 2 Page 3

Steps

Tests

Project structure

• 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

Path

Maven Java

Environment Variables

Check setupOpen 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/7Need to enter a archetype number

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

Create a Thucydides project – 4/7Thucydides version number

Create a Thucydides project – 5/7Group 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

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

Creating a pagepublic class GoogleSearchPage{}

Creating a pagepublic class GoogleSearchPage extends PageObject {}

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

super(driver); }}

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

private WebElement searchInput;}

Creating a pagepublic class GoogleSearchPage extends PageObject {…

@FindBy(|)private WebElement searchInput;

}

Creating a pagepublic class GoogleSearchPage extends PageObject {…

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

}

Grab elements from HTML

Grab elements from HTMLFind element id:

Creating a pagepublic class GoogleSearchPage extends PageObject {…

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

}

Creating a pagepublic class GoogleSearchPage extends PageObject {…

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

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

}

Creating a pagepublic class GoogleSearchPage extends PageObject {…

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

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

}}

Creating a pagepublic class GoogleSearchPage extends PageObject {…

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

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

}}

Creating a pagepublic class GoogleSearchPage extends PageObject {…

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

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

}

}

Creating Second Page

Creating Second Page

Creating Second Page

Creating Second Page

Creating Second Pagepublic class GoogleResultsPage extends PageObject {…

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

}

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;}

}}

Adding Steps

Steps are recorded in reports

Method parameters are captured in the report

Step method names are split by camelCase

Adding Stepspublic class GoogleSteps extends ScenarioSteps{

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

}}

Adding Stepspublic class GoogleSteps extends ScenarioSteps{…

public GoogleSearchPage googleSearchPage(){return

getPages.currentPageAt(GoogleSearchPage.class);}

public GoogleResultsPage googleResultsPage(){return

getPages.currentPageAt(GoogleResultsPage.class);}

}

Adding Stepspublic class GoogleSteps extends ScenarioSteps{…

@Steppublic void inputSearchTerm(String search){

googleSearchPage().inputTerm(search);}

@Steppublic void clickOnSearch(){

googleSearchPage(). clickOnSearch();}

}

Adding Stepspublic class GoogleSteps extends ScenarioSteps{…

@StepGrouppublic void performSearch(String search){

inputSearchTerm(search);clickOnSearch();

}

}

Adding Stepspublic class GoogleSteps extends ScenarioSteps{…

@Steppublic void findSearchResult(String search){

googleResultsPage().findResult(search);}

}

Adding Stepspublic class GoogleSteps extends ScenarioSteps{…

@Steppublic void verifyUrl(String url){

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

}}

Adding Steps

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;

}

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”);

}}

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”); }}

Project ExampleProject implementation.

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

Aggregate reportsmvn thucydides:aggregate

aggregate final report

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

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!