Getting Started with Gempyp

Requirements

Python ≥ 3.6

pip

Installation

Steps to install python on Windows

  • Go to the official Python download page for Windows .
  • Find a stable Python 3 release.
  • Click the appropriate link for your system to download the executable file: Windows installer (64-bit) or Windows installer (32-bit).
  • Open command prompt
  • Check python version - python --version
  • Install PIP using command - python -m pip install pip
  • Check pip version - pip --version

Steps to install python on Linux

  • Most of the Linux OS has Python pre-installed.
  • Check python version - python --version
  • If Python is not installed then go to the official Python download page for Linux
  • Find a stable Python 3 release.
  • Download a source tarball.
  • Open the terminal and Navigate to the directory where python tar file is downloaded.
  • Extract the tar file - tar -xf python-file-name.tar.xz
  • Check python version - python --version
  • Install PIP using command - python -m pip install pip
  • Check pip version - pip --version

Virtual Environment Setup (Optional)

  • Create virtual environment - python -m venv destinationFolder
  • Go to desination folder and then Scripts - cd destinationFolder\Scripts
  • Activate virtual environment - activate

Steps to install Gempyp

  • pip install gempyp
  • pip show gempyp

Introduction

GemPYP is a testing and reporting framework that allows automatic execution of testcases along with generation of the report, that enables effortless analysis and monitoring of the set.

Modules of GemPYP

Configuration File

XML is the configuration file written by the user. The other way to create a config file is through the JEWEL - Test Tool. This screen provides a UI to fill in the key and value without maintaining any configuration file.

XML Format

<data>
      <suite>
	Different Suite Tags
      </suite>

      <testcases>
	    <testcase>
		Mulitple Testcase Tags
	    </testcase>

	    <testcase>
		Multiple Testcase Tags
	    </testcase>
      </testcases>
</data>

Suite Tags

Suite is the collective details that user provides for all of the testcases present in that configuration file.

Tag Name Type Field Type Values Description
<project-name> String, Single value Mandatory Project name
<report-name> String, Single value Mandatory Name displayed on the report after execution
<email-to> String, Comma separated values Optional Email Ids Email Ids to mail the report
<email-cc> String,Comma separated values Optional Email Ids Email Ids in cc of the email that contain report.
<email-bcc> String,Comma separated values Optional Email Ids Email Ids in bcc of the email that contain report.
<mode> String, Single value Optional Sequence, optimize(default) Defines whether the testcases will run serially or parallelly.
<environment> String, Single value Optional Defines the environment to run the suite.
<threads> Integer, Single value Optional Any Integer (default is 8) Number of testcases to run in parallel.
<jewel-user> String, Single value Optional Subscribed user can provide their Jewel Username
<jewel-bridge-token> String, Single value Optional Subscribed user can provide their Jewel bridge token.
<report-location> String, Single value Optional Path where the HTML reports could be stored locally. Default path is gempyp_reports folder created in user’s AppData for windows and home directory for linux and mac.
<jira-email> String, Single value Optional Subscribed user can integrate GemPYP with JIRA. This would create a JIRA ticket in the test suite fails.
<jira-access-token> String, Single value Mandatory if jira_email is passed Jira Access Token to authenticate JIRA user.
<jira-project-id> Integer, Single value Mandatory if jira_email is passed Project ID on of project on JIRA under which ticket will be created
<jira-title> String, Single value Optional Title for Jira Creation. Default will be the name of suite
<jira-workflow> String, comma separated Optional Jira transition from one stage to another.
<enter-point> String, URL Optional API to fetch all the APIs of an organization
<testcase-list> String, Comma Separated values Optional Contains name of testcases that needs to be executed.
<category> String, Comma Separated values Optional Runs all the testcases with the provided category present in the suite
<properties-file> String, Comma Separated paths Optional Path, by default reads from "Resource folder" in the project directory Path to read external properties file. The property names can be used in XML config
<env-vars> Child Tags Optional Add the child tags in the environment variables and the values in the tags as the value of that environment variable.
env-vars
It has child tags where tag names are the environment variables and values are their respective environment value. This is used to define environment variables at runtime.
  • mode - string type, single value

    • sequence - runs testcases serially and same order as in suite.

    • optimize - runs testcases parallelly with some optimizations.

<data>
    <suite>
        <project-name>Test Project</project-name>
        <report-name>Smoke Test</report-name>
        <email-to>dummy@gmail.com</email-to>
	<email-cc>dummyUser@gmail.com</email-cc>
	<email-bcc>dummyUser1@gmail.com</email-bcc>
        <mode>optimize</mode>
        <environment>beta</environment>  
        <threads>12</threads>
        <jewel-user>dummyuser</jewel-user>
        <jewel-bridge-token>dummybridgetoken</jewel-bridge-token> 
        <report-location>C:\Users\dummyuser\gempyp_reports</report-location>
        <jira-email>dummy@gmail.com</jira-email>
        <jira-access-token>dummyjiratoken</jira-access-token>
        <jira-title>Title of Jira</jira-title>
        <jira-workflow>in dev, in qa, in prod</jira-workflow>
        <enter-point>https://dummybaseurl/</enter-point>
        <testcase-list>Test Project1, Test Project2</testcase-list>
	<env-vars>
                 <variable1>value_of_var1</variable1>
                 <variable2>value_of_var2</variable2>
        </env-vars>
     </suite>
</data>

Common Tags for GemPYP, PypRest and DV

Tag Name Type Field Type Values Description
<name> String Mandatory Defines the name of the testcase
<run_flag> String Mandatory Y,N
<type> String Optional, default is Gempyp Gempyp, Pyprest, DV Defines the testcase to be ran by which submodule of GEMPYP
<category> String Optional, Single Value Defines the category of the testcase.
<dependency> String Optional, Multiple Values It sets the dependency of testcase on other testcases
<global-vars> String Optional, Mutliple Values It can be used to set values to global variables.
Syntax: set $[#GLOBAL.Variable_1]=value1; set $[#GLOBAL.Variable_2]=value2

Dependency in detail

Scenario 1:
First Testcase Name: Insert Data
Second Testcase Name: Fetch Data
Order of Execution: Insert Data should be executed first and then Fetch Data.
Resolution: In Fetch Data, define <dependency> tag with value P:Insert Data

<testcase>
    <name>Fetch Data</name>
    <run-flag>Y</run-flag>
    <method>get</method>
    <api></api>
    <dependency>P:Insert Data</dependency>
</testcase>

<testcase>
    <name>Insert Data</name>
    <run-flag>Y</run-flag>
    <method>post</method>
    <api></api>
</testcase>

Scenario 2:
First Testcase Name: Insert Data
Second Testcase Name: Fetch Data
Third Testcase Name: Delete Data
Business Requirement: Insert Data should not be deleted, then only Fetch Data will execute.
Resolution: In Fetch Data, define <dependency> tag with value P:Insert Data

<testcase>
    <name>Delete Data</name>
    <run-flag>Y</run-flag>
    <method>delete</method>
    <api></api>
    <dependency>P:Insert Data</dependency>
</testcase>

<testcase>
    <name>Fetch Data</name>
    <run-flag>Y</run-flag>
    <method>get</method>
    <api></api>
    <dependency>P:Insert Data,F:Delete Data</dependency>
</testcase>

<testcase>
    <name>Insert Data</name>
    <run-flag>Y</run-flag>
    <method>post</method>
    <api></api>
</testcase>

Writing your first testcase

Gempyp Testcase

Step 1: Install Gempyp
Step 2: Create a Python File to write testcase with name testcase_file.py

from gempyp.engine.simpleTestcase import AbstractSimpleTestcase

"""_summary_
    To use GemPyp Framework for Functional Automation
    Import AbstractSimpleTestcase from gempyp.engine.simpleTestcase
    Extend AbstractSimpleTestcase in the class
    In a method, receive gempyp reporter. 
    To add a step, use addRow method from reporter.
    To add a miscellaneous data, use addMisc method from reporter.
    To use gempyp's log, use reporter's logger.
    To define each step's status, use self.Status
"""

class GempypTest(AbstractSimpleTestcase):
    
    def method(self, gempyp_reporter):
        gempyp_reporter.addRow("Step Title", "Step Description", self.Status.INFO)
        gempyp_reporter.addMisc("Reason of Failure", "Reason")
        gempyp_reporter.logger.info("Writing a testcases using gempyp framework")

Step 3: Create a XML.

<data>
    <suite>
        <project-name>Project Name</project-name>
        <report-name>Smoke Test</report-name>
        <environment>prod</environment>
        <mode>optimize</mode>
        <enter-point>EnterPointUrl</enter-point>
        <threads>4</threads>
        <jewel-user>jewelUserName</jewel-user>
        <jewel-bridge-token>JewelBridgeToken</jewel-bridge-token>
        <jira-email>jiraEmailID</jira-email>
        <jira_access_token>JiraAccessToken</jira_access_token>
        <jira_workflow>JiraWorkFlowForTicket</jira_workflow>
        <jira-project-id>JiraPRojectID</jira-project-id>
        <jira-title>Jira Creation Usecase</jira-title>
    </suite>

    <testcases>
        <testcase>
            <name>Demo Gempyp Testcase</name>
            <run-flag>Y</run-flag>
            <method>gempyp_demo</method>
            <path>.\testcase_file.py</path>
            <type>gempyp</type>
        </testcase>
    </testcases>

</data>

Step 4: Execute the xml suite

gempyp -c path_of_xml