Top Banner
T EST AUTOMATION PRACTICE WITH S ELENIUM W EBDRIVER Csapó Péter Mikó Szilárd EPAM Systems, Budapest, 2015
86

TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

Feb 02, 2017

Download

Documents

vanminh
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

TEST AUTOMATION PRACTICE

WITH SELENIUM WEBDRIVER

Csapó Péter

Mikó Szilárd

EPAM Systems, Budapest, 2015

Page 2: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

2CONFIDENTIAL

Basics Agenda

Assertion1

Navigation2

Interrogation3

Manipulation4

Page 3: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

3CONFIDENTIAL

Basics 1

ASSERTION

Page 4: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

4CONFIDENTIAL

Assertion

Fail method

fail(error_message)

Conditional assert

assertTrue(error_message, boolean_condition)

Equality assert

assertEquals(error_message, expected, actual)

Provide meaningful messages in assertions!

Page 5: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

5CONFIDENTIAL

Assertion

Identity assert

assertSame(error_message, expected_object, actual_object)

Custom assert

assertThat(actual_object, Matcher<object> matcher)

String assert

assertThat("myString", containsString("ring"))

Click here for more JUnit assertions

Benefits of assertThat

Page 6: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

6CONFIDENTIAL

Basics 2

NAVIGATION

Page 7: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

7CONFIDENTIAL

Navigation

• driver.get(java.lang.String)

• driver.navigate().to(java.lang.String)

• driver.navigate().to(java.net.URL)

Loading a web page in current browser window

Page 8: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

8CONFIDENTIAL

Navigation

• Driver.Navigate().Back()

• Driver.Navigate().Forward()

Move back & forward

Refresh page

• Driver.Navigate().Refresh()

Page 9: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

9CONFIDENTIAL

Basics 3

INTERROGATION

Page 10: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

10CONFIDENTIAL

Interrogation

• driver.getTitle()

Window Title

Current URL

Page Source

• driver.getCurrentUrl()

• driver.getPageSource()

Page 11: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

11CONFIDENTIAL

Interrogation

• driver.findElement(org.openqa.selenium.By)

– 0 match -> throws exception

– 1 match -> returns a WebElement instance

– 2+ matches -> returns only the first match from web page

• driver.findElements(org.openqa.selenium.By)

– 0 match -> returns an empty list

– 1 match -> returns a list with one WebElement

– 2+ matches -> returns list with all matching WebElements

Locating web elements

Page 12: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

12CONFIDENTIAL

Interrogation

• Supports various locator strategies

• By locating mechanisms

– Id

– ClassName

– LinkText

– PartialLinkText

– Name

– TagName

– CssSelector

– XPath

By class

Page 13: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

13CONFIDENTIAL

Interrogation

• Firefox

– Firebug add-on (Right click -> Inspect element / F12)

– Firefinder add-on (Try out your CSS & Xpath expressions)

• Chrome

– Built-in (Right click -> Inspect element / F12)

• IE

– Built-in (Tools -> Developer Tools / F12)

Inspecting elements in web browsers

Page 14: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

14CONFIDENTIAL

Interrogation

• driver.findElement(By.id(”some_id”));

• Ideal solution, however…

– Ids don’t always exist

– Their uniqueness is not enforced

– Used by developers as well

Id

ClassName

• driver.findElement(By.className(”some_class_name”));

Page 15: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

15CONFIDENTIAL

Interrogation

• driver.findElement(By.linkText(”Sign in”));

• driver.findElement(By.partiallinkText(”Sign”));

Linktext

Name

• <input id=”modCustLoginPassword” name=”password”>

• driver.findElement(By.name(”password”));

Page 16: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

16CONFIDENTIAL

Interrogation

tagName

• <label>Email address</label>

• driver.findElement(By.tagName(”label”));

Support classes

• Return all that matches each of the locators in sequence

– driver.findElements(new ByChained(by1, by2))

• Return all that matches any of the locators in sequence

– driver.findElements(new ByAll(by1, by2))

Page 17: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

17CONFIDENTIAL

Interrogation

CssSelector

• Absolute path

– driver.findElement(By.cssSelector(”html>body>div>p>input”));

• Relative path

– driver.findElement(By.cssSelector(”input”));

• Attribute selection

– driver.findElement(By.cssSelector(”button[name]”));

– driver.findElement(By.cssSelector(”button[name=‚cancel’]”));

– driver.findElement(By.cssSelector(”img:not[alt]”));

Page 18: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

18CONFIDENTIAL

Interrogation

CssSelector

• Id selection

– driver.findElement(By.cssSelector(”#save”));

• Class selection

– driver.findElement(By.cssSelector(”.login”));

• Combined selection

– driver.findElement(By.cssSelector(”button#save”));

– driver.findElement(By.cssSelector(”input.login”));

Page 19: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

19CONFIDENTIAL

Interrogation

CssSelector

• First matching child of the specified tag

– driver.findElement(By.cssSelector(”div#students:first-child”));

• Nth matching child of the specified tag

– driver.findElement(By.cssSelector(”#loginForm:nth-child(3)”));

• First matching enabled tag

– driver.findElement(By.cssSelector(”button:enabled”));

Page 20: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

20CONFIDENTIAL

Interrogation

XPath

• Absolute path

– driver.findElement(By.xpath(”html/body/p/input”));

• Relative path

– driver.findElement(By.xpath(”//input”));

• Attribute selection

– driver.findElement(By.xpath(”//input[@id=’username’]”));

– driver.findElement(By.xpath(”//*[@id=’myId’]”))

Page 21: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

21CONFIDENTIAL

Interrogation

Element interrogation

• element.getText();

• element.getAttribute();

• element.getTagName();

• element.isDisplayed();

• element.isEnabled();

• element.isSelected(); -> checkbox is selected or not

• selectElement.isMultiple(); -> multi select listbox or not

• selectElement.getOptions(); -> listbox select options

Page 22: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

22CONFIDENTIAL

Basics 4

MANIPULATION

Page 23: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

23CONFIDENTIAL

Manipulation

• element.click()

– Button

– Link

– Checkbox

– Combobox

Click

Submit

• form.submit()

– Form

Page 24: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

24CONFIDENTIAL

Manipulation

• Actions(driver).keyDown(Keys.SHIFT).click(element).

keyUp(Keys.SHIFT).build().perform();

Shift + Click

Special Actions

• Actions(driver).moveToElement(element).build().perform();

• Actions(driver).contextClick().build().perform();

• Actions(driver).doubleClick().build().perform();

• Actions(driver).clickAndHold().build().perform();

• Actions(driver).release().build().perform();

Page 25: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

25CONFIDENTIAL

Manipulation

• element.sendKeys(”string”)

– Input field

Type text

Clear text

• element.clear()

Page 26: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

26CONFIDENTIAL

Manipulation

• new Select(element).selectByIndex(elementCount)

Listbox Selection

Listbox Manipulating Commands

• select[ByIndex, ByVisibleText, ByValue]

• deselect[ByIndex, ByVisibleText, ByValue]

• deselectAll()

Page 27: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

27CONFIDENTIAL

Questions

Page 28: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

28CONFIDENTIAL

Advanced Agenda

Synchronization1

Window Handling2

Screenshots3

Browser Profile4

Cookies5

Page 29: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

29CONFIDENTIAL

Advanced 1

SYNCHRONIZATION

Page 30: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

30CONFIDENTIAL

Synchronization

• Sets the amount of time to wait for a page load to complete

• Global setting of the Webdriver object

• Negative value means indefinite wait time

Page Load Timeout

Example

• driver.manage().timeouts(). pageLoadTimeout(30, TimeUnit.SECONDS);

Page 31: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

31CONFIDENTIAL

Synchronization

• Specifies the waiting time for element not immediately visible

• Global setting of the Webdriver object

• 0 by default

Implicit Wait

Example

• driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

Page 32: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

32CONFIDENTIAL

Synchronization

• Waiting for a certain condition

• Poor alternative

– Thread.sleep(1000);

• Recommended

– WebDriverWait class

Explicit Wait

Example

• WebDriverWait wait = new WebDriverWait(driver, TIME_OUT);

• wait.until(ExpectedConditions.method);

Page 33: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

33CONFIDENTIAL

Synchronization

• presenceOfElementLocated(By locator)

• textToBePresentInElement(WebElement element, java.lang.String text)

• titleContains(java.lang.String title)

• visibilityOf(WebElement element)

• invisibilityOfElementLocated(By locator)

• elementToBeSelected(WebElement element)

• elementToBeClickable(By locator)

ExpectedConditions class

Click here for more ExpectedConditions

Page 34: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

34CONFIDENTIAL

Advanced 2

WINDOW HANDLING

Page 35: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

35CONFIDENTIAL

Window Handling

• driver.manage().window().getSize()

• driver.manage().window().setSize(Dimension d);

• driver.manage().window().maximize();

Size

• driver.manage().window().getPosition()

• driver.manage().window().setPosition(Point p);

Position

.getHeight();

.getWidth();

.getX();

.getY();

Page 36: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

36CONFIDENTIAL

Window Handling

• String windowHandle = driver.getWindowHandle();

• Iterator<String> windowIterator = browser.getWindowHandles();

Handles

• driver.switchTo().window(windowHandle);

Switch To

Page 37: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

37CONFIDENTIAL

Advanced 3

SCREENSHOTS

Page 38: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

38CONFIDENTIAL

Screenshots

• Keep track of changing UI

• Store pages with error

Advantages

• File screenshot =

((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

• FileUtils.copyFile(screenshot, new File(fileSource));

Example

Page 39: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

39CONFIDENTIAL

Advanced 4

BROWSER PROFILE

Page 40: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

40CONFIDENTIAL

Browser Profile

• c:\Users\[user]\AppData\Roaming\Mozilla\Firefox\Profiles\

• Unlimited number of profiles

• Stores many user attributes

– Passwords

– Bookmarks

– Browser history

– Settings

– Etc.

Introduction

Page 41: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

41CONFIDENTIAL

Browser Profile

• Set preferred language

• Change User Agent

• Set trusted sites

• Disable confirmation dialog

• Enable Firefox extensions, e.g. Firebug and Firefinder

• Enable native events for drag-and-drop

Usages

Page 42: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

42CONFIDENTIAL

Browser Profile

• var profile= new FirefoxProfile();

• profile.setPreference("intl.accept_languages", "de");

• IWebDriver driver = newFirefoxDriver(profile);

• Search for preference keys on Firefox by about:config

• Get all special pages about:about

Set preferred language

Page 43: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

43CONFIDENTIAL

Browser Profile

• var profile= new FirefoxProfile();

• profile.setPreference(USERAGENT_OVERRIDE, "Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac

OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314

Safari/531.21.10");

Changing user agent

Page 44: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

44CONFIDENTIAL

Browser Profile

• var profile= new FirefoxProfile();

• profile.addExtension(new File(PATH_TO_FIREBUG));

• profile.setPreference("extensions.firebug.currentVersion", "2.0.12");

Enable Extension

Page 45: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

45CONFIDENTIAL

Advanced 5

COOKIES

Page 46: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

46CONFIDENTIAL

Cookies

• Useful for testing the login feature

• Getting or setting session IDs

• Cookie attributes

– Name

– Value

– Domain

– Path

– Expiry

– Secure

– Http only

Introduction

Page 47: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

47CONFIDENTIAL

Cookies

• Get all cookies from the current session

– driver.manage().getCookies();

• Get cookie with a given name

– driver.manage().getCookieNamed(cookieToTest);

Interrogation

Page 48: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

48CONFIDENTIAL

Cookies

• Delete all cookies from the current session

– driver.manage().deleteAllCookies()

• Delete a specific cookie

– driver.manage().deleteCookie(TestCookie);

• Delete cookie with a given name

– driver.manage().deleteCookieNamed(cookieToTest);

Manipulation

Page 49: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

49CONFIDENTIAL

Cookies

• Add a specific cookie

– Cookie cookie = new Cookie("mycookie", "123456");

– driver.manage().addCookie(cookie);

• Domain attribute is the current document by default

Manipulation

Page 50: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

50CONFIDENTIAL

Questions

Page 51: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

51CONFIDENTIAL

Test Design Agenda

Data Driven Testing1

Page Object Model2

Page 52: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

52CONFIDENTIAL

Test Design 1

DATA DRIVEN TESTING

Page 53: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

53CONFIDENTIAL

Data Driven Testing

• Use pre-stored data as input and expected output

• Run your script to get actual output and compare them

• Continue testing with the next set of data

Concept

Page 54: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

54CONFIDENTIAL

Data Driven Testing

• Database

• XML file

• Property file

• Etc.

Possible data sources Pros of Data Driven Testing

• Repeatability and reusability

• Separation of test code and data

• Reduction in number of tests

Page 55: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

55CONFIDENTIAL

Data Driven Testing

• Testing different localizations of a site

– <testData lang="en" phone="(+36-1) 444 44 99" />

– <testData lang="hu" phone="06 (40) 49 49 49" />

Where to use

Page 56: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

56CONFIDENTIAL

Data Driven Testing

• Use JUnitParamsRunner class

– @RunWith(JUnitParamsRunner.class)

– public class Testclass { … }

• Add test parameters

– @Parameters(method = "testData")

– public void testCase(String param1, String param2) { … }

How to use

Page 57: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

57CONFIDENTIAL

Test Design 2

PAGE OBJECT MODEL

Page 58: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

58CONFIDENTIAL

Page Object Model

• New Approach

• @FindBy annotation

• PageFactory class

• Page Flow

• Best practices

Agenda

Page 59: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

59CONFIDENTIAL

Page Object Model

• Every UI change could cause a lot of test maintenance work

• We have to keep maintenance changes as low as possible

• We minimize the change sensitive automation code

New Approach

Page 60: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

60CONFIDENTIAL

Page Object Model

• We accept that the application and its elements are bound to change

• We create a new layer which contains change prone data

• This way we can adapt to changes with minimal refactoring cost

How to do it

Page 61: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

61CONFIDENTIAL

Page Object Model

• What describes one page should be in one class

• Use class methods to interact with your page

• This class represents your page in the test code

• Divide complex pages into smaller components called widgets

• Create widgets with the same approach as pages

Rules

Page 62: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

62CONFIDENTIAL

Page Object Model

• We mark elements with the @FindBy annotation

• FindBy directs Webdriver to locate an element

1. @FindBy(how = How.ID, using = "i")

public WebElement routeFrom;

2. @FindBy(id = "i")

public WebElement routeFrom;

3. public WebElement i;

@FindBy Annotation

Page 63: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

63CONFIDENTIAL

Page Object Model

• You can instantiate page/widget WebElements using the PageFactory class

• Use static method initElements

• WebElements are evaluated lazily

PageFactory Class

Example

• PageFactory.initElements(WebDriver driver, java.lang.Class PageObjectClass);

• initElements returns PageObjectClass

Page 64: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

64CONFIDENTIAL

Page Object Model

• We want to describe the logical relationship between pages

• Manipulation methods should reflect these relationships

• We should return a page object class after each method

• Return itself if we stay at the same page (e.g. typing)

• Return next page if we navigate (e.g. submit)

Page Flow

Page 65: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

65CONFIDENTIAL

Page Object Model

• Create base pages to represent common parts

– E.g. same header, footer, sidebar

• Reuse common widgets in each affected pages

• Use your pages to initiate and confirm the success of navigation

• Put your verification methods inside the page object as well

Best practices

Page 66: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

66CONFIDENTIAL

Questions

Page 67: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

67CONFIDENTIAL

Cucumber agenda

Understanding Cucumber1

Syntax2

Best practices3

Page 68: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

68CONFIDENTIAL

Cucumber 1

UNDERSTANDING

CUCUMBER

Page 69: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

69CONFIDENTIAL

• BDD is TDD done right

• Encourages communication between business, QA and dev teams

• Driven by business value

• Extends TDD by using natural language understandable for non

technical people (Given When Then)

• Test cases can even be created by product owners, business

analysts, TPMs.

• Cucumber is the most well known BDD framework.

BDD Quick Recap

Page 70: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

70CONFIDENTIAL

Used technologies

Page 71: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

71CONFIDENTIAL

Advantages

• Provides a form of documentation (feature file)

• Focus on functionality, operation and behavior

• Test cases are understandable for non-tech stakeholders – common language with

business

• New tests are easy to create by reusing exiting steps

• Plays nicely with TDD, BDD

Disadvantages

• More layers for testers

• More time consuming

Pros and Cons

Page 72: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

72CONFIDENTIAL

Cucumber 2

SYNTAX

Page 73: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

73CONFIDENTIAL

Feature: A feature would describe the current test script which has to be executed.

Scenario: Scenario describes the steps and expected outcome for a particular test case.

Scenario Outline: Same scenario can be executed for multiple sets of data using scenario

outline. The data is provided by a tabular structure separated by (I I).

Given: It specifies the context of the text to be executed.

And: use this keyword when multiple steps are of the same type are required

When: "When" specifies the test action that has to performed

Then: The expected outcome of the test can be represented by "Then"

But: another way to start your step

Feature Files

Page 74: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

74CONFIDENTIAL

In the feature file:

Given the following animals: cow, horse, sheep

Translates to the following code:

@Given("the following animals: (.*)")

public void the_following_animals(List<String> animals) {

//do something terrible

}

Step Definitions

Page 75: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

75CONFIDENTIAL

Cucumber in Eclipse

Add JARs to your project

Page 76: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

76CONFIDENTIAL

Cucumber in Eclipse

Help -> Install New Software

Work with: Cucumber

Page 77: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

77CONFIDENTIAL

@basic

Scenario: Create a search between two cities

Given I open Elvira page

When I create a search from

"Székesfehérvár" to "Sopron"

And I submit the search from

Then the search result title should

contain "Székesfehérvár" and "Sopron"

Basic scenario

Page 78: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

78CONFIDENTIAL

Scenario: Create a search between two cities using tables

Given I open Elvira page

When I create a search with the following parameters

| from | Szolnok |

| to | Debrecen |

| via | Hajdúszoboszló |

And I submit the search from

Then the search result title should contain the following city names

| Szolnok |

| Debrecen |

| Hajdúszoboszló |

Tables scenario

Page 79: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

79CONFIDENTIAL

Scenario Outline: Create an advanced search between two cities

Given I open Elvira page

When I create a search with the following parameters

| from | <fromCity> |

| to | <toCity> |

| via | <viaCity> |

And I submit the search from

Then the search result title should contain the following city names

| <fromCity> |

| <toCity> |

| <viaCity> |

@tag1

Examples:

| fromCity | toCity | viaCity |

| Szolnok | Debrecen | Hajdúszoboszló |

@tag2

Examples:

| fromCity | toCity | viacity |

| Budapest | Sopron | Tata |

Advanced tables scenario

Page 80: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

80CONFIDENTIAL

Cucumber 3

BEST PRACTICES

Page 81: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

81CONFIDENTIAL

1. Keep a feature file feature specific

2. Use tags (dependencies, test levels, environments)

Cucumber tips 1

Page 82: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

82CONFIDENTIAL

1. Create independent and deterministic scenarios

2. Don’t forget non-happy paths

Cucumber tips 2

Page 83: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

83CONFIDENTIAL

1. Follow the one step one thing rule

2. Use nested steps sparsely (calling steps from steps)

Cucumber tips 3

Page 84: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

84CONFIDENTIAL

1. Use an object (table) for multiple test data values

– Helps adding, removing test data

2. Use global containers for data used by multiple scenarios

– Helps fast changes (e.g. passwords, ids)

Cucumber tips 4

Page 85: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

85CONFIDENTIAL

1. Refactor and Reuse Step Definitions

2. Look for opportunities to generalize

Cucumber tips 5

Page 86: TEST AUTOMATION PRACTICE WITH SELENIUM WEBDRIVER

86CONFIDENTIAL

Questions