You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/PTFUserGuide.md
+79Lines changed: 79 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -143,6 +143,10 @@ The configuration allows an adapter to be created in various ways:
143
143
144
144
PowerShell adapter maps interface methods to PowerShell scripts. Users are able to pass objects between their managed test code and PowerShell scripts directly. This avoids the parameter and return value parsing issue.
145
145
146
+
* Shell adapter
147
+
148
+
The Shell adapter, which leverages Windows Subsystem for Linux (WSL), allows users to map interface methods to shell scripts and use the scripts to perform operations during the test. Users must specify the location of the scripts and have a .sh script with a name corresponding to each API call in the test suit. When the API is called, the script will be invoked and its stdout and stderr are recorded in the test log as LogEntryType.Comment.
149
+
146
150
* Managed adapter
147
151
148
152
The managed adapter allows users to use managed code to implement the interface methods.
@@ -212,6 +216,81 @@ public void TestPowerShellAdapter()
212
216
}
213
217
```
214
218
219
+
### Shell Adapter
220
+
221
+
Shell Adapter leverages bash in Windows Subsystem for Linux (WSL) to run shell scripts. Users can bind their adapter interfaces to a shell adapter by defining them as "shell" in the PTF configuration files. The implementation will run the corresponding shell script file when one of the adapter's methods is called.
222
+
223
+
__Benefits__
224
+
225
+
Shell adapters are easy to use. For example, they are suitable for service setup/shutdown jobs. Users can write a Stop.sh to login a Linux machine via SSH and stop a service.
226
+
227
+
__Limitation__
228
+
229
+
1. WSL must be running on Windows 10 version 1607 (the Anniversary update) or later.
230
+
2. Do not encode the shell script using UTF-8 with Byte Order Mark.
231
+
232
+
__Usage__
233
+
234
+
Configure `<Adapters>` section of the ptfconfig file:
Subsequently, users can invoke `IMyScriptAdapter.AMethod(parameters)`. PTF will look up a script named `AMethod.sh` in the scriptdir directory and execute it with the parameters.
241
+
242
+
__Parameters__
243
+
244
+
PTF invokes a shell script using the following parameters:
245
+
246
+
__Parameter name__ | __Value__
247
+
-------------------|----------
248
+
$1 |First input parameter.
249
+
$2 |Second input parameter.
250
+
... |
251
+
252
+
__Return values__
253
+
254
+
To pass a return value back to PTF, print the return value at the last line of stdout.
255
+
256
+
To pass an exception message back to PTF, print the message to stderr and exit the script with a non-zero exit code.
257
+
258
+
```
259
+
echo "<failure message>" >&2
260
+
exit 1
261
+
```
262
+
263
+
Provide the `ToString()` method and the `Parse()` method in a custom type to pass custom type values as parameters to script adapter, e.g.:
264
+
265
+
```
266
+
static public String ToString()
267
+
static public CustomType.Parse(String str)
268
+
```
269
+
270
+
__Exception__
271
+
272
+
If the shell script execution fails, PTF will raise an `InvalidOperationException`.
273
+
274
+
If the shell script file is not found, PTF will raise an `AssertInconclusiveException`.
275
+
276
+
__PTF Properties__
277
+
278
+
PTF properties are provided to shell adapters by environment variables with PTFProp_ as prefix, and dot in property name replaced by underline(_).
279
+
For example, if a user has the following configuration in the PTFconfig
280
+
281
+
```
282
+
<Properties>
283
+
<Property name="ServerName" value="MS-Server" />
284
+
<Property name="SSH.Port" value="4242" />
285
+
</Properties>
286
+
```
287
+
288
+
To initiate an SSH connection to the server. You can use the following command in shell script.
289
+
290
+
```
291
+
ssh -p $PTFProp_SSH_Port $PTFProp_ServerName
292
+
```
293
+
215
294
## <aname="4.4"> Extensive Logging Support
216
295
217
296
PTF provides problem-oriented logging capabilities (begin/end test group, verification pass/failure, requirement capture, debugging). Most of the logging is done automatically so that the test suite developer does not have to write them manually.
0 commit comments