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: details.md
+30-32Lines changed: 30 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -315,7 +315,6 @@ generated.
315
315
## Include
316
316
317
317
You can include another file in a feature file. e generated. If the file is a `.csv` file, it will be converted to a table.
318
-
319
318
```
320
319
Feature: Include
321
320
@@ -331,14 +330,11 @@ Given a string in base directory
331
330
Include 'string.inc'
332
331
"""
333
332
```
334
-
335
333
You can include any text, including `Data` statements (useful for reusing common data layouts).
336
334
If you surround the filename with single quotes `'string.inc'`, the file will be searched for in the `Configuration` value:
337
-
338
335
```
339
336
public static final String featureSubDirectory = "src/test/java/";
340
337
```
341
-
342
338
The included file might have a `Feature` statement in it. If it does, a warning will begenerated.
343
339
344
340
## Tables
@@ -505,93 +501,95 @@ Scenario: Here are string options
505
501
Three line
506
502
Four line
507
503
"""
508
-
509
504
```
510
505
506
+
## Background and Cleanup
507
+
508
+
You can add a `Background `and a `Cleanup `to a feature file. All steps in the `Background `will be run when the scenario starts. All steps in the `Cleanup `will be run when the scenario ends. `Background `and `Cleanup `use the same glue context as the scenario in which they run
511
509
```
510
+
Feature: Background
511
+
512
+
Background:
513
+
Given Background function sets a value
514
+
| Background Here |
515
+
516
+
Cleanup::
517
+
Given value for cleanup should be set to
518
+
| Cleanup Here |
512
519
520
+
Scenario: Should have Background and Cleanup
521
+
Given a regular function
522
+
Then background should set value to
523
+
| Background Here |
524
+
And set a value for cleanup
525
+
| Cleanup Here |
513
526
527
+
Scenario: Should also have Background and Cleanup
528
+
Given a regular function
529
+
Then background should set value to
530
+
| Background Here |
531
+
And set a value for cleanup
532
+
| Cleanup Here |
514
533
```
515
534
535
+
## JSON
536
+
537
+
Four methods are added to the string version of the data class. These methods convert an object to and from JSON and convert a table to and from JSON. They were added since JSON is a popular way to represent attributes. Methods to and from YAML or XML or some other format can be added.
538
+
516
539
## Define
517
540
518
541
There is one more facet that might have
519
542
some use, depending on your context. With a `define`, you specify
520
543
the value of a constant once, e.g.
521
-
522
544
```
523
545
Define
524
546
| Name | Value | Notes |
525
547
| HIGH_VALUE | 100 | Highest allowed input |
526
548
| LOW_VALUE | 1 | Lowest allowed input |
527
549
```
528
-
529
-
```
530
-
531
-
```
532
-
533
550
Whereever you use these tokens, they will be replaced by the value. For example:
534
-
535
551
```
536
552
Given this data:
537
553
| ID | Value |
538
554
| A | HIGH_DATA |
539
555
| B | LOW_DATA |
540
556
```
541
-
542
557
will be treated as:
543
558
559
+
```
544
560
Given this data:
545
561
| ID | Value |
546
562
| 1 | 100 |
547
563
| B | 1 |
548
-
564
+
```
549
565
This is useful if the Define terms are meaningful to someone reading
550
566
the feature file.
551
567
552
568
### Calculated Values
553
569
554
570
You can use an expression in the replacement, such as:
555
-
556
571
```
557
572
| Name | Value | Notes |
558
573
| AVERAGE_VALUE | (LOW_DATA +HIGH_DATA)/2 |
559
574
```
560
-
561
575
In this case, the computation will be passed, not the result of the computation:
562
-
563
576
```
564
577
Given this data:
565
578
| ID | Value |
566
579
| A | HIGH_DATA |
567
580
| B | LOW_DATA |
568
581
| C | AVERAGE_VALUE |
569
582
```
570
-
571
583
will be treated as:
572
-
573
584
```
574
585
Given this data:
575
586
| ID | Value |
576
587
| 1 | 100 |
577
588
| B | 1 |
578
589
| C | (1 + 100)/2 |
579
590
```
580
-
581
591
You need to create (or find somewhere) a class that computes the result
582
592
Of this calculation. Suppose it was called ComputeInt with a string constructor. The Data statement would have Datatype ComputeInt for this
583
593
Field.
584
594
585
595
For Java, you can check out the ScriptEngineManager and ScriptEngine classes from the javax.script package:
0 commit comments