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 NameTypeField TypeValuesDescription
<project-name>String, Single valueMandatoryProject name
<report-name>String, Single valueMandatoryName displayed on the report after execution
<email-to>String, Comma separated valuesOptionalEmail IdsEmail Ids to mail the report
<email-cc>String,Comma separated valuesOptionalEmail IdsEmail Ids in cc of the email that contain report.
<email-bcc>String,Comma separated valuesOptionalEmail IdsEmail Ids in bcc of the email that contain report.
<mode>String, Single valueOptionalSequence, optimize(default)Defines whether the testcases will run serially or parallelly.
<environment>String, Single valueOptionalDefines the environment to run the suite.
<threads>Integer, Single valueOptionalAny Integer (default is 8)Number of testcases to run in parallel.
<jewel-user>String, Single valueOptionalSubscribed user can provide their Jewel Username
<jewel-bridge-token>String, Single valueOptionalSubscribed user can provide their Jewel bridge token.
<report-location>String, Single valueOptionalPath 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 valueOptionalSubscribed user can integrate GemPyp with JIRA. This would create a JIRA ticket in the test suite fails.
<jira-access-token>String, Single valueMandatory if jira_email is passedJira Access Token to authenticate JIRA user.
<jira-project-id>Integer, Single valueMandatory if jira_email is passedProject ID on of project on JIRA under which ticket will be created
<jira-title>String, Single valueOptionalTitle for Jira Creation. Default will be the name of suite
<jira-workflow>String, comma separatedOptionalJira transition from one stage to another.
<enter-point>String, URLOptionalAPI to fetch all the APIs of an organization
<testcase-list>String, Comma Separated valuesOptionalContains name of testcases that needs to be executed.
<category>String, Comma Separated valuesOptionalRuns all the testcases with the provided category present in the suite
<properties-file>String, Comma Separated pathsOptionalPath, by default reads from “Resource folder” in the project directoryPath to read external properties file. The property names can be used in XML config
<env-vars>Child TagsOptionalAdd 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>[email protected]</email-to>
	<email-cc>[email protected]</email-cc>
	<email-bcc>[email protected]</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>[email protected]</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 NameTypeField TypeValuesDescription
<name>StringMandatoryDefines the name of the testcase
<run_flag>StringMandatoryY,N
<type>StringOptional, default is GemPypGemPyp, Pyprest, DVDefines the testcase to be ran by which submodule of GemPyp
<category>StringOptional, Single ValueDefines the category of the testcase.
<dependency>StringOptional, Multiple ValuesIt sets the dependency of testcase on other testcases
<global-vars>StringOptional, Mutliple ValuesIt 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