How to compare responses of two methods in SoapUI - soap

I am executing a SOPA method on two environments(Dev and UAT) in SopaUI free version and want to compare the responses to check data mismatch, please suggest any solution for the same.
Response Format-
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetAccountsResponse xmlns="http://services.multichoice.co.za/SelfCare">
<GetAccountsResult xmlns:a="http://datacontracts.multichoice.co.za/SelfCare" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:Account>
<a:afterDue121To150>0</a:afterDue121To150>
<a:afterDue151To180>0</a:afterDue151To180>
<a:afterDue180UpField>0</a:afterDue180UpField>
<a:afterDue1To30Field>0</a:afterDue1To30Field>
<a:afterDue31To60Field>0</a:afterDue31To60Field>
<a:afterDue61To90Field>0</a:afterDue61To90Field>
<a:afterDue91To120Field>0</a:afterDue91To120Field>
<a:currency>NGN</a:currency>
<a:currentAmount>0</a:currentAmount>
<a:defaultCurrencytotalBalance>0</a:defaultCurrencytotalBalance>
<a:defaultCuurencyCode>NGN</a:defaultCuurencyCode>
<a:invoicePeriod>1</a:invoicePeriod>
<a:isPrimary>true</a:isPrimary>
<a:lastInvoiceAmount>0</a:lastInvoiceAmount>
<a:lastInvoiceDate>2017-02-19T15:52:54</a:lastInvoiceDate>
<a:methodOfPayment>Cash</a:methodOfPayment>
<a:number>3112</a:number>
<a:paymentDueDate>2016-11-10T00:00:00</a:paymentDueDate>
<a:segmentation>Customer Segment N</a:segmentation>
<a:status>Suspended</a:status>
<a:totalBalance>0</a:totalBalance>
<a:type>Ges</a:type>
</a:Account>
</GetAccountsResult>
</GetAccountsResponse>
</s:Body>
</s:Envelope>

//Step 1: Set DEV environment in your soap request using ReqProps = testRunner.testCase.getTestStepByName("stepname as in soapui suite"
ReqProps.setPropertyValue("Endpoint","https://dev:endpoint")
//Step 2: Run the DEV step and save response in some variable testRunner.runTestStepByName("stepname as in soapui suite")
DEvResponse = ReqProps.getPropertyValue("Response")
// Step 3: Repeat Same step for UAT environment and take response in variable UATResponse
// Step 4: Compare 2 responses using `DetailedDiff diffInRes = new DetailedDiff(new Diff(DEVRes, UATRes))
List differencesArray = diffInRes.getAllDifferences()`
// Step 5 . Take array size to verify if XMLs match. If XMLs does not match you can print differences and get all mismatches from array "differencesArray"

Related

Convert XML like String to PySpark Dataframe

I'm using azure.storage.queue's receive_messages() function in databricks to pull messages from a azure queue. The response looks like xml but it is really just a string:
<?xml version="1.0" encoding="utf-16"?>
<root>
<col1>123</col1>
<col2>1</col2>
<col3>Unknown</col3>
<col4>Dog</col4>
<col5>Owner</col5>
<col6>-1</col6>
<col7>Owner</col7>
<col8></col8>
</root>
When I write the response to a list, it looks like:
'<root>\r\n <col1>123</col1>\r\n <col2>1</col2>\r\n <col3>Unknown</col3>\r\n <col4>Dog</col4>\r\n <col5>Owner</col5>\r\n <col6>-1</col6>\r\n <col7>Owner</col7>\r\n <col8></col8>\r\n</root>'
I know that I can split on \r\n with something like:
l = [x.strip().split(' ') for x in a[0].split('\r\n')]
l
This gives:
['root'],
['<col1>123</col1>'],
['<col2>1</col2>'],
['<col3>Unknown</col3>'],
['<col4>Dog</col4>'],
['<col5>Owner</col5>'],
['<col6>-1</col6>'],
['<col7>Owner</col7>'],
['<col8></col8'],
['</root>']]
I'm not sure if this is the best route and I don't want to hard code each value into the spark dataframe, because I need to iterate through all messages in the queue. Looking for a solution that converts each 'col' into a header and then grabs the value between 'tags'.
Here is an answer:
data=[]
for message in response:
#print(message.content)
soup = BeautifulSoup(message.content, "xml")
c=soup.find_all('col1')
c1=soup.find_all('col2')
c2=soup.find_all('col3')
c3=soup.find_all('col4')
c4=soup.find_all('col5')
c5=soup.find_all('col6')
c6=soup.find_all('col7')
c7=soup.find_all('col8')
for i in range(0,len(c)):
rows=[c[i].get_text(),
c1[i].get_text(),
c2[i].get_text(),
c3[i].get_text(),
c4[i].get_text(),
c5[i].get_text(),
c6[i].get_text(),
c7[i].get_text()]
data.append(rows)
#print(data)
out_df = spark.createDataFrame(data,schema = ['c','c1','c2','c3','c4',
'c5','c6','c7'])
This was faster, but requires the response to always be in the same order, which mine is.
data=[]
for message in response:
#print(message.content)
root=etree.fromstring(message.content.encode('utf-16'))
arr=[]
for child in root:
r=child.text
arr.append(r)
data.append(arr)
out_df = spark.createDataFrame(data,schema = ['c','c1','c2','c3','c4',
'c5','c6','c7'])
display(out_df)

How to add random integer for each case in Schemathesis?

I'm trying to test an API endpoint with random input for mid and cids (code below). However, whenever I run the test it says missing required positional arguments. Can anyone please help?
#schema.parametrize()
#schema.given(mid=st.integers(), cids=st.lists(st.integers()))
#settings(max_examples=1)
def test_api_customised(mid, cids, case):
case.headers = case.headers or {}
case.headers['Authorization'] = "apiKey " + str(base64_composer)
case.headers['Content-Type'] = "application/json"
# CREATE JOB
if case.method == "POST":
if isinstance(case.body, dict):
case.body['moduleId'] = mid
case.body['clientIds'] = cids
print(case.body)
response = case.call()
case.validate_response(response)
And I got this error:
TypeError: test_api_customised() missing 2 required positional arguments: 'mid' and 'cids'
It is likely caused by the presence of explicit examples in the API schema. See this issue.
A temporary solution would be to exclude the explicit phase:
... # Skipped for brevity
from hypothesis import settings, Phase
# Used in `#settings`
PHASES = phases=set(Phase) - {Phase.explicit}
#schema.parametrize()
#schema.given(mid=st.integers(), cids=st.lists(st.integers()))
#settings(max_examples=1, phases=PHASES)
def test_api_customised(mid, cids, case):
... # the rest of the test
A more comprehensive solution requires changes in Schemathesis (see this issue)
You could check whether it is the case for you by removing examples / example / x-examples / x-example keywords (depending on your API spec version) from the API schema. If it is not the case, I encourage you to report this issue with more details (preferably including your API schema).

Use excel file variables in SOAP request in SoapUI

I've faced with a problem. I'm new in SoapUI.
I must read excel file and then put some variables in the soap request. This is what I've done:
I've add a groovy script to get the excel file data:
import jxl.*
Workbook workbook = Workbook.getWorkbook(new File("C:\\PATH\\TestData.xls"))
Sheet sheet1 = workbook.getSheet("Sheet1")
def rows = sheet1.getRows()
def cols = sheet1.getColumns()
log.info "Row Count =" + rows
log.info "Column Count =" + cols
def array = []
for(i=1;i<rows;i++) {
for(j=0;j<cols;j++) {
Cell cell = sheet1.getCell(j,i)
def variable = cell.getContents()
log.info cell.getContents()
array << variable
}
}
return array
array returns: 10 and 20.
And this is a soap request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:Add>
<tem:intA>10</tem:intA>
<tem:intB>10</tem:intB>
</tem:Add>
</soapenv:Body>
</soapenv:Envelope>
Can I somehow call a groovy script and put variables in
<tem:intA>10</tem:intA>
<tem:intB>20</tem:intB>
Instead of 10 and 20, I should call a groovy script method and put data, which I've taken from excel file.
Since your use-case is trivial: just two variables to be substituted, you can just use two properties.
Change the return array in your script to something like:
testCase.setPropertyValue("intA", array[0].toString())
testCase.setPropertyValue("intB", array[1].toString())
And then your request to:
<tem:intA>${#TestCase#intA}</tem:intA>
<tem:intB>${#TestCase#intB}</tem:intB>

I need to add multiple contains assertion in my REST API test Steps using Groovy Script

I have to check ever parameter of my response using Contains Assertion, there are approx 20 parameter. I added few using setToken(), but it's difficult to write this for 20 times. Is there any other method using which I can add all parameter in few lines of code?
I have written below code for adding few assertions
def addassert = testSteps.addassertion("Contains")
addassert.setToken("totalCases")
addassert.setName("Total Cases")
addassert = testSteps.addassertion("Contains")
addassert.setToken("numberofChains")
addassert.setName("No Of Chains")
addassert = testSteps.addassertion("Contains")
addassert.setToken("numberofOutlets")
addassert.setName("No Of Outlets")
addassert = testSteps.addassertion("Contains")
addassert.setToken("expiringToday")
addassert.setName("Exp Today")

Count redirects in jmeter

At the moment im usig HTTP request sampler with 'Follow Redirects' enabled and want to keep it that way. As a secondary check besides assertion i want to count the number of redirects as well, but i dont want to implement this solution.
Is there a way when i can use only 1 HTTP sampler and a postprocessor (beanshell for now) and fetch this information? Im checking SamplerResult documentation , but cant find any method which would give back this information for me.
I heard Groovy is new black moreover users are encouraged to use JSR223 Test Elements and __groovy() function since JMeter 3.1 as Beanshell performs not that well so you can count the redirects as follows:
Add JSR223 PostProcessor as a child of your HTTP Request sampler
Put the following code into "Script" area:
int redirects = 0;
def range = new IntRange(false, 299, 400)
prev.getSubResults().each {
if (range.contains(it.getResponseCode() as int)) {
redirects++;
}
}
log.info('Redirects: ' + redirects)
Once you run your test you will be able to see the number of occurred redirects in jmeter.log file:
Add the following Regular Expression Extractor as a child of your sampler:
Apply to: Main sample and sub-samples
Field to check: Response code
Regular Expression: (\d+)
Template: $1$
Match No.: -1
Then add a BeanShell Post Processor also as a child of the sampler and add the following to the script area:
int matchNr = Integer.parseInt(vars.get("MyVar_matchNr"));// MyVar is the name of the variable of the above regular expression extractor
int counter = 0;
for(i=1; i <= matchNr; i++){
String x = vars.get("MyVar_"+i);
if(x.equals("302")){
counter = counter + 1;
}}
log.info(Label + ": Number of redirects = " + String.valueOf(counter));// The output will be printed in the log like this(BeanShell PostProcessor: Number of redirects = 3 ) so you might want to change the name of the beanshell post processor to the same name of your sampler.
Then you can see the number of redirects for the sampler in the log.