Skip to content

Objects

Ziridis edited this page Oct 4, 2018 · 5 revisions

DATA DRIVEN TEST FRAMEWORK

INTRODUCTION

This project is putting in place a test factory that will allow to drive test based on data input. The data will be on Gherkins format and the implementation should require less technical skills. But python knowledge is still required. For the first version we will focus on tests using Selenium. Then we could add Appium, RestAssured and other technology.

GHERKINS

For the sake of this architecture document here is an example of Gherkins file.

Feature: User searches for article 

   This is a description of the feature file

   @id=100.1 @browser=firefox @custom-tag=tag   
   Scenario: User is searching from the home page
    Given the user is on the home page
    When the user enters the keyword "pycon"
    Then the user does not see the error message "No results found."

PYTHON SCRIPTING

This framework written in Java will be able to generate Python file with Python instructions to run test.

import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

class PythonOrgSearch(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Remote(
            command_executor='http://localhost:4444/wd/hub',
            desired_capabilities={'browserName': 'firefox',
                         'version': '3',
                        'javascriptEnabled': True})

    def test_search_in_python_org(self):
        driver = self.driver
        driver.get("http://www.python.org")
        self.assertIn("Python", driver.title)
        elem = driver.find_element_by_name("q")
        elem.send_keys("pycon")
        elem.send_keys(Keys.RETURN)
        assert "No results found." not in driver.page_source


    def tearDown(self):
        self.driver.close()

if __name__ == "__main__":
    unittest.main()

THE OBJECTS

“FEATURE”

This object is linked to the feature file. It contains:

  • Title (ie:“User login”)
  • Description (ie:” This is a description of the feature file”)
  • 0 to N Scenarios object
Feature: User searches for article 

   This is a description of the feature file

“SCENARIO”

This object is linked to the feature file. It contains:

  • Defined tags (ie: “@id=100.1”, “@browser=firefox”, “@webdriver-url=…”).
  • Title (ie:” User is logging with a wrong password”)
  • 0 to N Steps object (Given, When, Then, And)
  • Remote webdriver url based on the tag “@webdriver-url” and it will be used in the test setup
  • Browser name based on “@browser=” and it will be used in the test setup
  • Test id based on “@id=” and it will be used in the test teardown
  • Step screenshot url and it will be used in the test setup. This is a project constant. The names of the screenshots should have a unique but easy to link to a scenario run.
  • (!) For the first version let’s ignore “Example” that will handle test data.
  • (!) For the first version let’s ignore custom tags.
   @id=100.1 @browser=firefox @custom-tag=tag   
   Scenario: User is searching from the home page
    Given the user is on the home page
    When the user enters the keyword "pycon"
    Then the user does not see the error message "No results found."

From scenario, we will generate a Python file that will contain the test scripting, based on Steps and Modules objects (see below). Each Python file will be a test class containing:

  • “setup” function will handle the actions before the test. => Specific object?
  • “teardown” function will handle the action after the end of the test. In this section a report is sent back to the report service (ref to report object). => Specific object?
  • “scenario” function will handle the modules for the test. (ie:” test_search_in_python_org based on the figure above). It will always start with the instruction driver = self.driver Also, a “main” function required for the Python file. And a “dependencies” part required for the Python file. The list of dependencies are managed in a config file.
class PythonOrgSearch(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Remote(
            command_executor='http://localhost:4444/wd/hub',
            desired_capabilities={'browserName': 'firefox',
                         'version': '3',
                        'javascriptEnabled': True})

    def test_search_in_python_org(self):
        driver = self.driver
        driver.get("http://www.python.org")
        self.assertIn("Python", driver.title)
        elem = driver.find_element_by_name("q")
        elem.send_keys("pycon")
        elem.send_keys(Keys.RETURN)
        assert "No results found." not in driver.page_source


    def tearDown(self):
        self.driver.close()

"SETUP"

This object will generate the initial phase of the test. Example:

    def setUp(self):
        self.driver = webdriver.Remote(
            command_executor='http://localhost:4444/wd/hub',
            desired_capabilities={'browserName': 'firefox',
                         'version': '3',
                        'javascriptEnabled': True})

It contains:

  • Setup Id
  • Setup name
  • Setup description
  • List of modules that build the Setup

"TEARDOWN"

This object will generate the final phase of the test. Example:

    def tearDown(self):
        self.driver.close()

It contains:

  • TearDown Id
  • TearDown name
  • TearDown description
  • List of modules that build the TearDown

“STEP”

This object is linked to the feature file. It contains:

  • One of these keywords at the beginning of the phrase (Given, When, Then, And)
  • One string phrase.
  • O to N parameters in the phrase between quotes (ie=When the user enters the keyword "pycon"). No specific action is required to implement it. When one or several parameters are present, it will help to identify the data for the Module.
  • Each step could have 0 to N Module linked to one Step

When an Example (like a datasheet for the Gherkins file) will be implemented later, the Example will be handled as a step containing data for the other steps, in other word it will instantiate an array in Python usable for the other modules.

3 sample steps

    Given the user is on the home page
    When the user enters the keyword "pycon"
    Then the user does not see the error message "No results found."

Gherkins Keyword enum

Implemented

Step class

Implemented

“MODULE”

Implemented

Usually from a Gherkins file, each step needs an implementation of test actions. The QA usually writes the feature file, the developer implements the feature file by scripting the test on each step. This object will handle the step implementation of a test. A module represents actions scripted to achieve the step. In a step we could have 0 to N modules. A module contains:

  • Module id
  • Module name
  • Module comment (comment about the implementation)
  • Python snippet
  • List of Module Parameters if parameters are required in the snippet (see more in ModuleParameters Object section)
  • Module order to allow to order the module sequence between them. When several module are linked to a Step, a TearDown, a Setup or anything else and order need to be assigned to have the right sequence of snippet.

Snippet example

This example is the implementation for When the user enters the keyword "pycon":

        elem = driver.find_element_by_name("q")
        elem.send_keys("pycon")
        elem.send_keys(Keys.RETURN)

"MODULE PARAMETERS"

Implemented

The snippet object contains:

  • Module parameter id
  • Name of the parameter
  • Value of the parameter

A snippet could require parameters like:

        %%var%% = driver.find_element_by_name("%%id_element%%")
        %%var%%.send_keys("%%search_value%%")
        %%var%%.send_keys(Keys.RETURN)

The parameter in the snippet will be identified before and after by "%%".

“SNIPPET”

It is a predefined Python snippet that allow to be used for Module. It has the same structure as Module.

  • Snippet id
  • Snippet name
  • Snippet description (explain how to use the snippet)
  • Python snippet

“REPORT”

A report is the result generated in the teardown phase of Python script. It is also a service called at each teardown. It contains:

  • Scenario id comes from Scenario object
  • Browser name comes from Scenario object
  • Webdriver url comes from Scenario object
  • List of screenshots for each step comes from Scenario object. Maybe
  • Failed screenshot comes from Scenario object
  • Execution date
  • Logs comes from Scenario object