def FindObject(objectName, sheetName): PathExcelFile = Path2 rowCount = ExcelFunc.getRowCount(PathExcelFile, sheetName)+1 for i in range (2, rowCount): objectName2 = ExcelFunc.readData(PathExcelFile, sheetName, i, 1) if objectName == objectName2: objectPath = ExcelFunc.readData(PathExcelFile, sheetName, i, 2) return objectPath
def Execute(start, testCount, TCID): for i in range (start, testCount+start): if ExcelFunc.readData(PathExcelFile, sheetName, i, 1) == TCID: keyword = ExcelFunc.readData(PathExcelFile, sheetName, i, 4) objectName = ExcelFunc.readData(PathExcelFile, sheetName, i, 5) object = Locator.FindObject(objectName, sheetName) data = ExcelFunc.readData(PathExcelFile, sheetName, i, 6) print(keyword, objectName) Perform_Keyword.Execute(keyword, object, data)
def FindRow(sheetName, rowCount, TCID): PathExcelFile = Path1 rowCount = ExcelFunc.getRowCount(PathExcelFile, sheetName) + 1 counter = 1 for i in range (1, rowCount): temp_TCID = ExcelFunc.readData(PathExcelFile, sheetName, i, 1) if temp_TCID == TCID: return counter counter += 1
from selenium.common.exceptions import * from selenium import webdriver import PT_Login import PT_Booking import Perform_Keyword import Locator import ExcelFunc import openpyxl import time PathExcelFile = "C:\\Users\\cheqws133-user\\PyCharmProjects\\Data\\PhpTravels Test Case v3.xlsx" sheetName = "Suites" suiteCount = ExcelFunc.getRowCount(PathExcelFile, sheetName) + 1 for i in range(2, suiteCount): if ExcelFunc.readData(PathExcelFile, sheetName, i, 5) == "Yes": TCID = ExcelFunc.readData(PathExcelFile, sheetName, i, 2) sheetName = ExcelFunc.readData(PathExcelFile, sheetName, i, 4) rowCount = ExcelFunc.getRowCount(PathExcelFile, sheetName) testCount = Locator.CountCase(sheetName, rowCount, TCID) start = Locator.FindRow(sheetName, rowCount, TCID) if sheetName == "Login": PT_Login.Execute(start, testCount, TCID) if sheetName == "Booking": PT_Booking.Execute(start, testCount, TCID) sheetName = "Suites"
def AcknwldgPO(): # API URI url = PropertyFile.getValue('URI', 'po_acknowledge') # Read input json file file = open(PropertyFile.getValue('JSON_PATH', 'po_acknowledge_json'), 'r') json_input = file.read() # Convert the string from the input file into Json format request_json = json.loads(json_input) request_json_body = json.dumps(request_json) # Make Post Request with Json Input body response = requests.put(url, request_json_body, auth=('PO', 'PO@pp123'), headers={'content-type': 'application/json'}) Status = response.status_code #print (Status) ExcelFunc.WriteIntoExcel(2, 3, Status) # Extract the comparison values : AckDate, Expected Shipment Date in the Header and Line from the json input file # Extract Acknowledgement Date Json_AckDate = request_json.get('AckDate') Json_Header_AckDate_Val = str(Json_AckDate) # Extract Expected Shipment Dates for both Line 1 and Line 2 yearlist = [] Json_Type = request_json.get('AcknowledgedPoLines') for d in Json_Type: for key, value in d.iteritems(): yearlist.append(value) ExpShipDate_Line_1 = yearlist[0] # Extract values from the Database DB_Header_Val = Database_Query.DB_Connect( "select PoAcknowledgementDate from [PSMIApps].[dbo].[tbl_IssuePurchaseOrderHeader] where PONum = 9998174" ) DB_Line_1_Val = Database_Query.DB_Connect( "select ExpectedShipDate from [PSMIApps].[dbo].[tbl_IssuePurchaseOrderLine] where PONum = 9998174 and LineNum = 1" ) # Format Date values to suite the comparison Formatted_Header_DB_Date = PropertyFile.getDateFormat(DB_Header_Val) Formatted_Line_1_Date = PropertyFile.getDateFormat(DB_Line_1_Val) #Formatted_Line_2_Date = PropertyFile.getDateFormat(DB_Line_2_Val) # Verify if the Response Code is Success # Verify if the Response Code is Success if (Status >= 200 and Status < 300): print("Status is" + " " + str(Status)) else: print("Status is" + " " + str(Status)) ExcelFunc.WriteIntoExcel(2, 4, 'Fail') return ("Fail - Status is" + " " + str(Status)) exit() # Compare Json Input Header Value with DB Header Value if (Json_Header_AckDate_Val == Formatted_Header_DB_Date): print("Acknowledgement Date successfully updated at the header level") else: print("Acknowledgement Date is not updated at the header level") ExcelFunc.WriteIntoExcel(2, 4, 'Fail') exit() # Compare Json Input Line 1 with the DB Line 1 Expected Shipment Date if (ExpShipDate_Line_1 == Formatted_Line_1_Date): #print ("Expected Shipment Date for the Line 1 is updated") ExcelFunc.WriteIntoExcel(2, 4, 'Pass') return ("Pass - Status is" + " " + str(Status)) exit() else: print("Expected Shipment Date for the Line 1 is not updated") ExcelFunc.WriteIntoExcel(2, 4, 'Fail') exit()
def dueDateUpdate() : # API URI url = PropertyFile.getValue('URI','po_update_duedate') # Read input json file file = open(PropertyFile.getValue('JSON_PATH','po_duedate_json'),'r') json_input = file.read() # Convert the string from the input file into Json format request_json = json.loads(json_input) request_json_body = json.dumps(request_json) # Make Post Request with Json Input body response = requests.put(url,request_json_body,auth=('PO','PO@pp123'),headers={'content-type':'application/json'}) Status = response.status_code #print (Status) ExcelFunc.WriteIntoExcel(1,3,Status) # Extract the comparison values : Due Date from the request Json # create a List and append all the Json Array values into the List ( P.S Easy to retrieve values one after the other ) yearlist = [] Json_Type = request_json.get('PoLineItems') for d in Json_Type: for key, value in d.iteritems(): yearlist.append(value) Line_1_DueDate = yearlist[0] # Extract the comparision values : Due Date from DataBase DB_DueDate = Database_Query.DB_Connect("SELECT DueDate FROM [PSMIApps].[dbo].[tbl_IssuePurchaseOrderHeader] where PONum = 9998180") DB_Line_1_DueDate = Database_Query.DB_Connect("SELECT LineDueDate FROM [PSMIApps].[dbo].[tbl_IssuePurchaseOrderLine] where PONum = 9998180 and LineNum = 1") DB_Line_2_DueDate = Database_Query.DB_Connect("SELECT LineDueDate FROM [PSMIApps].[dbo].[tbl_IssuePurchaseOrderLine] where PONum = 9998180 and LineNum = 2") # convert the DB date format to the comparable date value ConCat_Str_Val_Header = PropertyFile.getDateFormat(DB_DueDate) ConCat_Str_Val_One = PropertyFile.getDateFormat(DB_Line_1_DueDate) # Verify if the Response Code is Success if (Status >=200 and Status < 300): print ("Status is"+" "+str(Status)) else: #print ("Status is"+" "+str(Status)) ExcelFunc.WriteIntoExcel(1, 4, 'Fail') exit() #print (Line_1_DueDate) #print (ConCat_Str_Val_Header) # compare DueDate header to see if it is same as the Line Level value if ( Line_1_DueDate == ConCat_Str_Val_Header): #print ("Database Due Date updated in the PO Header level") return ("Pass - Status is" + " " + str(Status)) else: #print ("Database Due Date not updated in the PO Header level") ExcelFunc.WriteIntoExcel(1, 4, 'Fail') return ("Fail - Status is" + " " + str(Status)) exit() #print (Line_1_DueDate) #print (ConCat_Str_Val_One) # compare Line 1 DueDate with the Line 2 Due Date if ( Line_1_DueDate == ConCat_Str_Val_One): #print ("Database Due Date is updated for Line 1") ExcelFunc.WriteIntoExcel(1, 4, 'Pass') exit() else: #print ("Database Due Date is not updated for Line 1") ExcelFunc.WriteIntoExcel(1, 4, 'Fail') exit()
def disputePO(): # API URI url = PropertyFile.getValue('URI', 'po_dispute') # Read input json file file = open(PropertyFile.getValue('JSON_PATH', 'po_dispute_json'), 'r') json_input = file.read() # Convert the string from the input file into Json format request_json = json.loads(json_input) request_json_body = json.dumps(request_json) # Make Post Request with Json Input body response = requests.put(url, request_json_body, auth=('PO', 'PO@pp123'), headers={'content-type': 'application/json'}) Status = response.status_code #print (Status) ExcelFunc.WriteIntoExcel(3, 3, Status) # Extract the comparison values : Dispute Date, Dispute Type, Dispute Revision & Comment from the json input file Json_Date = request_json.get('DisputeDate') Str_Json_Date = str(Json_Date) # create a List and append all the Json Array values into the List ( P.S Easy to retrieve values one after the other ) yearlist = [] Json_Type = request_json.get('DisputeItems') for d in Json_Type: for key, value in d.iteritems(): yearlist.append(value) Str_Json_Type = yearlist[2] Str_Json_Revision = yearlist[0] Str_Json_Comment = yearlist[1] # Validate if the Due Date in the DB is updated to the Input Due Date DB_DisputeDate = Database_Query.DB_Connect( "SELECT AckHoldDate FROM [PSMIApps].[dbo].[tbl_IssuePurchaseOrderHeader] where PONum = 9998183" ) DB_DisputeType = Database_Query.DB_Connect( "SELECT AckHoldType FROM [PSMIApps].[dbo].[tbl_IssuePurchaseOrderHeader] where PONum = 9998183" ) DB_DisputeComment = Database_Query.DB_Connect( "SELECT AckHoldComments FROM [PSMIApps].[dbo].[tbl_IssuePurchaseOrderHeader] where PONum = 9998183" ) # Format Date values to suite the comparison DB_New_DisputeDate = PropertyFile.getDateFormat(DB_DisputeDate) # Verify if the Response Code is Success if (Status >= 200 and Status < 300): print("Status is" + " " + str(Status)) return ("Pass - Status is" + " " + str(Status)) else: print("Status is" + " " + str(Status)) ExcelFunc.WriteIntoExcel(3, 4, 'Fail') return ("Fail - Status is" + " " + str(Status)) exit() # Compare Dispute Date in Json Input File to the Database Value if (Str_Json_Date == DB_New_DisputeDate): print("Dispute Date Update Successful for the PO record") else: print("Dispute Date not updated") ExcelFunc.WriteIntoExcel(3, 4, 'Fail') exit() # Compare Dispute Type in Json Inout File to Database Value if (Str_Json_Type == DB_DisputeType): print("Dispute Type has been successfully updated") else: print("Dispute Type is not updated") ExcelFunc.WriteIntoExcel(3, 4, 'Fail') exit() # Compare Dispute Comments in Json Inout File to Database Value if (Str_Json_Comment == DB_DisputeComment): print("Dispute Comment has been successfully updated") ExcelFunc.WriteIntoExcel(3, 4, 'Pass') exit() else: print("Dispute Comments are not updated") ExcelFunc.WriteIntoExcel(3, 4, 'Fail') exit()