Browse Source

Added paypal_secondfor2.xlsx for testing. Added singleton class AddressCreate

Munish Kumar 4 years ago
parent
commit
b870e83b3c

+ 133 - 0
baangt/TestSteps/AddressCreation.py

@@ -0,0 +1,133 @@
+class AddressCreate:
+    """
+    This file Define a Singleton Class AddressCreate which will have static
+        method returnAddress to return the address in format.
+
+
+        CountryCode**
+        PostlCode**
+        CityName
+        StreetName
+        HouseNumber
+        AdditionalData1
+        AdditionalData2
+
+        Input: value1 = {'CountryCode':"IN",'CityName':"Mohali"} [optional]
+               value2 = "sales_"
+
+        Output: {'sales_CountryCode':"IN","sales_PostalCode":"19883",
+              "sales_CityName":"Mohali","sales_StreeName":"32HB",
+               "sales_AdditionalData1":"Near Hospital",
+               "sales_AdditionData2":"Ajanta Mandis Park"}
+
+
+        Sample Usage:
+                Default Value
+                >> AddressCreate.returnAddress()
+
+                Pass value of ('HouseNumber', 'AdditionalData1',
+                 'AdditionalData2', 'StreetName', 'CityName', 'PostalCode',
+                 'CountryCode' ) to change.
+
+               For example:
+                >> Update City Name
+                  AddressCreate(value1={"CityName":"Something"})
+
+                  or
+                  AddressCreate({"CityName":"Something"})
+
+                >> Update Country Name
+                  AddressCreate({"CountryCode":"US"})
+
+
+
+    """
+
+    __instance = None
+
+    class __AddressCreate:
+        """ Inner class   """
+
+        def __init__(self, value1={}, value2=""):
+            addressData = {"HouseNumber": "6",
+                           "AdditionalData1": "Near MahavirChowk",
+                           "AdditionalData2": "Opposite St. Marish Church",
+                           "StreetName": "GoreGaon",
+                           "CityName": "Ambala",
+                           "PostalCode": "160055",
+                           "CountryCode": "India",
+                           }
+            prefixData = ""  # empty initially
+            
+            self.value1 = addressData
+            self.value2 = prefixData
+
+            # Now update the value
+            self.updateValue(value1, value2)
+
+        def updateValue(self, value1, value2):
+            """ This function will process value1,value2 and
+                prepare dictionary data
+            """
+            # value1
+            try:
+                value1 = dict(value1)
+                value2 = str(value2)
+
+            except Exception as e:
+                print("Error Occured :  ", e)
+            # process only dictionary data, ignore everything else
+            if isinstance(value1, type({})):
+                for key, value in value1.items():
+                    if key in self.value1:
+                        self.value1[key] = value
+
+            if value2.strip():
+                self.value2 = value2.strip()
+
+        def __str__(self):
+            """ AddressCreation print information"""
+            return "AddressCreate Instance id :{} ".format(id(self))
+
+        def __repr__(self):
+            return "AddressCreate Instance id:{}\nvalue1: {}\nvalue2: {}".format(
+                id(self), self.value1, self.value2)
+
+    @staticmethod
+    def getInstance():
+        if AddressCreate.__instance is None:
+            AddressCreate.__instance = AddressCreate.__AddressCreate()
+        return AddressCreate.__instance
+
+    def __new__(cls, value1={}, value2=""):
+        """ Get the instance and update the value """
+        if not AddressCreate.__instance:
+            # Create new instance
+            AddressCreate.__instance = AddressCreate.__AddressCreate(
+                value1, value2)
+        else:
+            # Update old instance
+            AddressCreate.__instance.updateValue(value1, value2)
+        return AddressCreate.__instance
+
+    @staticmethod
+    def returnAddress():
+        """This function will use value1 and value2 to prepare structured
+            Address Data
+        """
+        # get the instance
+        a = AddressCreate.getInstance()
+        data = {}
+
+        for key, val in a.value1.items():
+            # prefix_value + addresskey = addresskey_value
+            # if prefix = "Sales" and "CountryCode" = "India"
+            # then final data will be data['Sales_CountryCode'] = India
+            if a.value2:
+                # prefix is given
+                data[a.value2 + key] = val
+            else:
+                data[key] = val
+        # finally return the processed dataDict
+
+        return data

+ 7 - 0
baangt/TestSteps/TestStepMaster.py

@@ -5,6 +5,7 @@ from baangt.base.ApiHandling import ApiHandling
 import sys
 from pkg_resources import parse_version
 import logging
+from baangt.TestSteps.AddressCreation import AddressCreate
 
 logger = logging.getLogger("pyC")
 
@@ -114,6 +115,12 @@ class TestStepMaster:
                 self.apiSession.setHeaders(setHeaderData=lValue)
             elif lActivity == 'SAVE':
                 self.doSaveData(lValue, lValue2)
+            elif lActivity == "ADDRESS_CREATE":
+                # Create Address with option lValue and lValue2
+                AddressCreate(lValue,lValue2)
+                # Update testcaseDataDict with addressDict returned from
+                AddressCreate.returnAddress()
+                self.testcaseDataDict.update(AddressCreate.returnAddress())
             else:
                 raise BaseException(f"Unknown command in TestStep {lActivity}")
 

+ 3 - 0
baangt/ui/ImportKatalonRecorder.py

@@ -261,6 +261,9 @@ click | //div[@id='main']/div[2]/div/div[2]/div/div[5]/button/div[2] |
         # loop through line and process if 'Value' column there
         for line in lines:
             # Check for GOTOURL activity
+            # skip if lines == NONE
+            if not line:
+                continue
             if line['Activity'] == "GOTOURL":
                 # we should make variable for url
                 line['Value'] = ImportKatalonRecorder.prepareKeyValue(outputData, 'url', line['Value'])

+ 30 - 0
docs/SimpleAPI.rst

@@ -63,6 +63,36 @@ Activities for API-Tests:
        ``value2`` is the source (e.g. ``$(ANSWER_CONTENT.imdbRating)`` would retrieve the value "imdbRating" of the
        answer of your API-Call.
 
+   * - ``ASSERT``
+     - This  will retrieve value of element specified by `locator`
+       And compare with expected_value specified in `value`
+      
+       if expected_value not matches with output_value it will raise TestStepExecution and result in FAILED.
+
+   * - ``ADDRESS_CREATE``
+     - Create  Address Data for various test cases  and save in testDataDict
+       The following field variable can be used via $(field_name).
+       
+       ['HouseNumber', 'AdditionalData1', 'AdditionalData2', 'StreetName', 'CityName', 'PostalCode', 'CountryCode']
+    
+       Example:
+        Default Data: (value=<blank> and value2=<blank>)
+        'HouseNumber': '6', 'AdditionalData1': 'Near MahavirChowk', 'AdditionalData2': 'Opposite St. Marish Church', 'StreetName': 'GoreGaon', 'CityName': 'Ambala', 'PostalCode': '160055', 'CountryCode': 'India'
+
+       `value` optional
+        if provided : (value= {"CountryCode":"US","CityName":"Athens"} value2=<blank>)
+         FieldValue updated to:
+         {'HouseNumber': '6', 'AdditionalData1': 'Near MahavirChowk',
+         'AdditionalData2': 'Opposite St. Marish Church',
+         'StreetName': 'GoreGaon', 'CityName': 'Athens',
+         'PostalCode': '160055', 'CountryCode': 'US'}
+ 
+
+       `value2` optional
+
+        Field will be prefixed with "office_<field_name>". Ex. "office_CountryCode"
+
+
 Special data fields in API-Tests:
 ---------------------------------
 

+ 30 - 0
docs/simpleExample.rst

@@ -212,3 +212,33 @@ More details on Activities
 
        Another use of the If-Statement is with ``LocatorType`` and ``Locator`` and comparison. You'd use that, when you
        want conditional execution of a larger block of statements depending on an element present or not present.
+
+   * - assert
+     - Will retrieve value of element specified by ``locator`` and compare with reference value from ``value``.
+      
+       
+   * - address_create
+     - provide an easy and easily extendable way to generate address data for a test case
+       The following fields variable are stored in testcaseDataDict:
+
+       CountryCode
+       PostalCode
+       CityName
+       StreetName
+       HouseNumber
+       AdditionalData1
+       AdditionalData2
+       
+       `value`  optional
+         Default field-value: {'HouseNumber': '6', 'AdditionalData1': 'Near MahavirChowk', 'AdditionalData2': 'Opposite St. Marish Church', 'StreetName': 'GoreGaon', 'CityName': 'Ambala', 'PostalCode': '160055', 'CountryCode': 'India'} 
+
+       These fields can be used as filter criteria in field value.
+       Example value= `{CountryCode:CY, PostlCode: 7}`. 
+
+
+       Resulted field-value :{'HouseNumber': '6', 'AdditionalData1': 'Near MahavirChowk', 'AdditionalData2': 'Opposite St. Marish Church', 'StreetName': 'GoreGaon', 'CityName': 'Ambala', 'PostalCode': '7', 'CountryCode': 'CY'}
+
+       `value2` optional
+       If a prefix was povided in field Value2, the fieldnames will be concatenated with this prefix,
+       e.g.if value2=`PremiumPayer_`, then the resulting field for CountryCode in testDataDict would become PremiumPayer_CountryCode.
+

BIN
examples/paypal_secondform2.xlsx