-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest
More file actions
74 lines (64 loc) · 2.35 KB
/
Copy pathtest
File metadata and controls
74 lines (64 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Path to the CSV file
def csvFilePath = 'C:/bo/input.csv'
// Verify if the CSV file exists
def csvFile = new File(csvFilePath)
if (!csvFile.exists()) {
log.error "CSV file not found: $csvFilePath"
return
}
// Parse the CSV file manually
def csvData = []
csvFile.eachLine { line, index ->
if (index == 0) {
// Skip the header row if present
return
}
def columns = line.split(',')
if (columns.size() >= 2) {
csvData << [input: columns[0].trim(), expected: columns[1].trim()]
} else {
log.warn "Skipping malformed line ${index + 1}: $line"
}
}
// Validate if there is data in the CSV
if (csvData.isEmpty()) {
log.error "No data found in the CSV file."
return
}
// Name of the SOAP Request TestStep in your TestCase
def soapRequestStepName = "CapitalCity"
// Get the TestStep object
def requestStep = context.testCase.testSteps[soapRequestStepName]
if (requestStep == null) {
log.error "TestStep '${soapRequestStepName}' not found in the TestCase."
return
}
// Iterate over each row in the CSV data
csvData.each { row ->
def inputValue = row.input
def expectedValue = row.expected
log.info "Testing input: '${inputValue}' against expected: '${expectedValue}'"
try {
// Set the request content dynamically
requestStep.testRequest.setRequestContent("""
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.oorsprong.org/websamples.countryinfo">
<soapenv:Header/>
<soapenv:Body>
<web:CapitalCity>
<web:sCountryISOCode>${inputValue}</web:sCountryISOCode>
</web:CapitalCity>
</soapenv:Body>
</soapenv:Envelope>
""")
// Run the request and get the response
def response = requestStep.run(testRunner, context).response
// Check if the response matches the expected value
if (response && response.contentAsString.contains(expectedValue)) {
log.info "Input '${inputValue}' returned the expected result: '${expectedValue}'"
} else {
log.warn "Input '${inputValue}' did not return the expected result. Expected: '${expectedValue}', Actual: ${response?.contentAsString ?: 'No response received'}"
}
} catch (Exception e) {
log.error "Error while processing input '${inputValue}': ${e.message}"
}
}