I will explain Robot test cases with Ride with example.
I have directory ClientSearch which has below. I have open directory from RIDE.
Request Folder has all request (JSON files) which we are going to use.
clientSearch_resources.txt has common function which we are going to call from many test cases.
ClientSearch_Transactions.txt has actual test cses.
Env_Variables.py – Python file which give variable as we set.
ClientSearch_Transactions.txt
*** Settings ***
Suite Setup ClientSearch Suite Setup ${HOST} ${CONTENT_TYPE} ${alias}
Suite Teardown ClientSearch Suite Teardown ${alias}
Library String
Library Collections
Library HttpLibrary.HTTP
Library RequestsLibrary
Library OperatingSystem
Resource clientSearch_resources.txt
*** Test Cases ***
Create Delete Should Succeed
Log Create Delete Should Succeed begin.
${UNIQUE_NAME} Unique String
${itemName} Catenate SEPARATOR= IntTestTemplate_ ${UNIQUE_NAME}
${id} ${resp} Create clientSearch ${CURDIR}/Requests/create.json ${itemName} 200
Should Not Be Equal As Strings ${id} ""
Delete clientSearch ${id} 200
Log Create Delete Should Succeed end.
Create Duplicate name Should Fail
Update Should Succeed
Log Update Should Succeed begin.
${UNIQUE_NAME} Unique String
${itemName} Catenate SEPARATOR= IntTestTemplate_ ${UNIQUE_NAME}
${resp} Update clientSearch ${CURDIR}/Requests/update.json ${itemName} ${ITEM_ID} 200
Log Update Should Succeed end.
Update Duplicate Name Should Fail
Log Update Duplicate Name Should Fail begin.
${UNIQUE_NAME} Unique String
${itemName} Catenate SEPARATOR= IntTestTemplate_ ${UNIQUE_NAME}
${id} ${resp} Create clientSearch ${CURDIR}/Requests/create.json ${itemName} 200
Should Not Be Equal As Strings ${id} "
${id} Set variable ${id.strip('"')}
${UNIQUE_NAME} Unique String
${itemName2} Catenate SEPARATOR= IntTestTemplate_ ${UNIQUE_NAME}
${id2} ${resp} Create clientSearch ${CURDIR}/Requests/create.json ${itemName2} 200
Should Not Be Equal As Strings ${id2} "
${id2} Set variable ${id2.strip('"')}
Log Update second template...
${resp} Update clientSearch ${CURDIR}/Requests/update.json ${itemName} ${id2} 500
Delete clientSearch ${id} 200
Delete clientSearch ${id2} 200
log ${resp.content}
${error_code} Get Error Code ${resp}
Should Be Equal As Integers ${error_code} XXXXXXX Invalid error code returned by the transaction.
Log Update Duplicate Name Should Fail end.
Get Should Succeed
Log Get Should Succeed begin.
${resp} Get clientSearch ${ITEM_ID} 200
${id} Get Json Value ${resp.content} /clientSearch/id
Should be Equal As Strings ${ITEM_ID.strip('"')} ${id.strip('"')}
Log Get Should Succeed end.
clientSearch_resources.txt
*** Settings ***
Variables Env_Specific_Variables.py Stg
Library HttpLibrary.HTTP
Library RequestsLibrary
Library OperatingSystem
*** Variables ***
${CONTENT_TYPE} application/json
${ALIAS} RAMapi3
${ITEM_ID} ""
*** Keywords ***
Create clientSearch
[Arguments] ${createJsonFile} ${itemName} ${responce_code}
Log "Create clientSearch begin"
${id} Set variable ""
${headers} Create Dictionary Content-Type ${content_type} CredentialData ${UserCredentialData}
${createRequestJson} Get Binary File ${createJsonFile}
${createRequest} Replace Variables ${createRequestJson}
Should Be Valid JSON ${createRequest}
${resp} RequestsLibrary.Post ${ALIAS} /clientSearch/directoryPlus data=${createRequest}
log ${resp.content}
Should Be Equal As Integers ${resp.status_code} ${responce_code}
Run Keyword If ${resp.status_code} <> 200 Log ${resp.content}
${id} Run Keyword If "${responce_code}" == "200" Get Json Value ${resp.content} /id
Log "Create clientSearch end"
[Return] ${id} ${resp}
Delete clientSearch
[Arguments] ${id} ${responce_code}
Log "Delete clientSearch begin"
${uri} Catenate SEPARATOR= /clientSearch/directoryPlus ${SPURICHAR} id=${id.strip('"')}
${resp} RequestsLibrary.Delete ${ALIAS} ${uri}
Should Be Equal As Integers ${resp.status_code} ${responce_code}
Log "Delete clientSearch end"
[Return] ${resp}
Update clientSearch
[Arguments] ${jsonFile} ${itemName} ${itemID} ${responce_code}
Log "Update clientSearch begin"
${ITEM_ID} Set variable ${itemID.strip('"')}
${headers} Create Dictionary Content-Type ${content_type} CredentialData ${UserCredentialData}
${requestJson} Get Binary File ${jsonFile}
${updateRequest} Replace Variables ${requestJson}
Should Be Valid JSON ${updateRequest}
Log ${updateRequest}
${resp} RequestsLibrary.Put ${ALIAS} /clientSearch/directoryPlus data=${updateRequest}
Should Be Equal As Integers ${resp.status_code} ${responce_code}
Log "Update clientSearch end"
[Return] ${resp}
Get clientSearch
[Arguments] ${id} ${response_code}
Log "Get clientSearch begin"
${uri} Catenate SEPARATOR= /clientSearch/directoryPlus ${SPURICHAR} id=${id.strip('"')}
${resp} RequestsLibrary.Get ${alias} ${uri}
Should Be Equal As Integers ${resp.status_code} ${response_code}
Log "Get clientSearch end"
[Return] ${resp}
Hope it is useful .
No comments:
Post a Comment