-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile IO-JSON.jmx
More file actions
118 lines (104 loc) · 4.3 KB
/
File IO-JSON.jmx
File metadata and controls
118 lines (104 loc) · 4.3 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.4.1">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true">
<stringProp name="TestPlan.comments"></stringProp>
<boolProp name="TestPlan.functional_mode">false</boolProp>
<boolProp name="TestPlan.tearDown_on_shutdown">true</boolProp>
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
<stringProp name="TestPlan.user_define_classpath"></stringProp>
</TestPlan>
<hashTree>
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true">
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
<boolProp name="LoopController.continue_forever">false</boolProp>
<stringProp name="LoopController.loops">1</stringProp>
</elementProp>
<stringProp name="ThreadGroup.num_threads">1</stringProp>
<stringProp name="ThreadGroup.ramp_time">1</stringProp>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
<stringProp name="ThreadGroup.duration"></stringProp>
<stringProp name="ThreadGroup.delay"></stringProp>
<boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp>
</ThreadGroup>
<hashTree>
<JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="JSR223 Sampler - File I/O" enabled="true">
<stringProp name="scriptLanguage">groovy</stringProp>
<stringProp name="parameters"></stringProp>
<stringProp name="filename"></stringProp>
<stringProp name="cacheKey">true</stringProp>
<stringProp name="script">File file = new File ("demo.txt")
// create
file.createNewFile()
// read
def lines = file.readLines()
println lines
def content = "This is my new content.\n"
// write
file << content
def newLines = file.readLines()
println newLines
// delete
file.delete()</stringProp>
</JSR223Sampler>
<hashTree/>
<JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="JSR223 Sampler - JSON" enabled="true">
<stringProp name="scriptLanguage">groovy</stringProp>
<stringProp name="parameters"></stringProp>
<stringProp name="filename"></stringProp>
<stringProp name="cacheKey">true</stringProp>
<stringProp name="script">import groovy.json.JsonOutput
import groovy.json.JsonSlurper
def jsonSlurper = new JsonSlurper()
def json = '''
{
"firstName": "John",
"lastName": "Doe",
"age": 26,
"address": {
"streetAddress": "Naist Street",
"city": "Nara",
"postalCode": "630-0192",
},
"phoneNumbers": [
{
"type": "iPhone",
"number": "0123-4567-8888",
},
{
"type": "home",
"number": "0123-4567-8910",
}
]
}
'''
println '*************************************************'
def obj = jsonSlurper.parseText(json)
println "First Name: ${obj.firstName}"
println "Last Name: ${obj.lastName}"
println "Phone Numbers found: ${obj.phoneNumbers.size()}"
// address
def address = obj.address
address.each {
line -> line.each {
println "${line.key}: ${line.value}"
}
}
// all phone numbers
def phoneNumbers = obj.phoneNumbers
phoneNumbers.each {
phoneNumber -> phoneNumber.each {
type, number -> println "${type}: ${number}"
}
}
println '*************************************************'</stringProp>
</JSR223Sampler>
<hashTree/>
</hashTree>
</hashTree>
</hashTree>
</jmeterTestPlan>