BDD

Behat Mink: 000 - Blocking Issues in Mink for Drupal

  • Mink is probably a great tool for basic websites that don't implement a heavy back-end system.
  • Mink COULD be a winner IF
    • migrates to selenium3 webdriver
    • exposes the entire selenium3 api
    • provides a means to send XPATH directly to selenium api
      • currently catches, parses, translates, THEN sends to api
    • provides a means to send CSS directly to selenium api
      • currently catches, parses, translates, THEN sends to api

Behat front end is a solid Cucumber BDD Engine

  • Still requires a sensible & well-designed test framework to hook into
  • Design the framework around PHPUnit
  • Use Behat to provide BDD translation for feature files
  • BDD isn't test...

Drupal Testing: CucumberJVM Workflow

Create Gherkin Feature File

  • Add BDD feature & scenario data

 

 

Create Test Runner File

  • glue = StepDefs
  • DryRun=true
  •  

 

Create StepDefs File under /StepDefs

  • Add Step Definitions to code files under StepDefs
  • Best to organize StepDefs into subfolders for 'feature', 'sprints', 'macros', navigation, testID
  • Duplicate method names CAN NOT exist in this StepDefs package
    • So... BDD language should be carefully planned out for maximizing re-use & avoiding redundancy of actions
    • if 5 stepdefs are created for login and the login routine changes....
      • will have to update the same routine 5 times.
  • Macros are helpful for multi-step routines that are commonly used across tests

 

 

Drupal Testing: BDD Considerations

 

Feature Files

  • The Gherkin feature files should be treated like software & managed with great care
  • In doing so, not only will the framework be more concise & maintainable, but the BDD feature files essentially will write the framework themselves.
  • Shared Step Definition files can act as reusable macros, making scenarios shorter while reducing the size of the framework and time to maintain them.
  • Come up with a standard language and syntax for ALL feature files
  • Create templates in Excel that have available test steps to choose from
    • this will significantly reduce the amount of coding required for each scenario through REUSE
    • and thereby reduce the time it takes to automate them
    • and thereby avoid duplication of code & the cost of maintaining it

 

Tags

SpecFlow: 02 - Gherkin Wiring

SpecFlow Feature File

  • The Feature file uses common Gherkin language
  • In a given project, normally this would be placed in a dedicated Features folder
Feature: LogIn_Feature
    In order to access my account
    As a user of the website
    I want to log into the website

@mytag
Scenario: Successful Login with Valid Credentials
    Given User is at the Home Page
    And Navigate to LogIn Page
    When User enter 'UnityAdmin' and 'UnityAdmin@2017'
    And Click on the LogIn button
    Then Successful LogIN message should display

Scenario: Successful LogOut
    When User LogOut from the Application
    Then Successful LogOut message should display

SpecFlow Test Definitions Generation

  • Once Feature file is created, the SpeckFlow 'Generate Definitions' option will auto-generate the required methods & open a dialog to save the newly created class file.
  • In a given project, normall

SpecFlow: 01 - Stand up Selenium WebDriver Script

Create Feature Folder

 

Add LogIn_Feature.feature file

Feature: LogIn_Feature
    In order to access my account
    As a user of the website
    I want to log into the website

@mytag
Scenario: Successful Login with Valid Credentials
    Given User is at the Home Page
    And Navigate to LogIn Page
    When User enter UserName and Password
    And Click on the LogIn button
    Then Successful LogIN message should display

Scenario: Successful LogOut
    When User LogOut from the Application
    Then Successful LogOut message should display

NuGet Selenium.WebDriver ( 3.12.1 )

 

Create Steps Folder

 

Tags

CucumberJVM: 00 - Gherkin Language

Basic Gherkin Feature Model

Feature: User can create an article

Scenario: user logs in
Given user is on HomePage
When user navigates to LoginPage
And user enters UserName and Password
Then message displayed Login Successful

Scenario: user creates a new article
Given user is logged in and on HomePage
When user clicks CreateArticleLink
And user enters ArticleTitle
And user enters ArticleBody
And user neters ArticleTags
And user clicks NewArticleSubmitButton
Then message is displayed Article Created Successfully
And NewArticlePage title is MyNewArticle

Feature Keyword

  • Defines the functionality the test targets
  • Multiple scenarios can be created to cover this functionality
Feature: User can create an article
Feature: User can create an article

This feature will ensure a user can login and the product handles invalid credentials correctly
Feature: User can create an

CucumberJVM: 09 - Cucumber Hooks: @before & @after

 

 


@Before

public void setup(){}

 


@After

public void teardown(){}

 


Global

@Before()

 

@After()


Tagged Scenarios

@First

Scenario: first scenario

@Second

Scenario: second scenario

@Third

Scenario: third scenario

 


For @First ONLY ( NOT GLOBAL )

@Before("@First")

@After("@First")

 


Tagged Hooks

@Before() //Global

@Before("@First") //Specific

@After("@First") //Specific

@After() //Global


Ordered Hooks

@Before(order=0) //Global

@After(order=0) //Global

@Before(order=1) //Global

@After(order=1) //Global


 

 

 

 

 

 

 

 

 

CucumberJVM: 07 - DataDriven with Maps

 


Feature

Feature: Deal data creation

Scenario: Free CRM Create a new deal scenario

    #Using a HashMap
    Given user is already on Login Page
    When title of login page is Free CRM
    Then user enters username and password
        | username | password |
        | naveenk | test@123 |
    Then user clicks on login button
    Then user is on home page
    Then user moves to new deal page
    Then user enters contact details
    #FORMAT = ctrl-shift-f
        | title      | amount | probability | commission |
        | test deal1 | 1000 | 50 | 10 |
        | test deal2 | 2000 | 60 | 20 |
        | test deal3 | 3000 | 70 | 30 |
    Then close the browser

 

 

 

Subscribe to BDD