You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

json_formatter.feature 22 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. Feature: JSON output formatter
  2. In order to simplify processing of Cucumber features and results
  3. Developers should be able to consume features as JSON
  4. Background:
  5. Given the standard step definitions
  6. And a file named "features/one_passing_one_failing.feature" with:
  7. """
  8. @a
  9. Feature: One passing scenario, one failing scenario
  10. @b
  11. Scenario: Passing
  12. Given this step passes
  13. @c
  14. Scenario: Failing
  15. Given this step fails
  16. """
  17. And a file named "features/step_definitions/json_steps.rb" with:
  18. """
  19. Given /^I attach a screenshot/ do
  20. File.open("screenshot.png", "w") { |file| file << "foo" }
  21. attach "screenshot.png", "image/png"
  22. end
  23. Given /^I print from step definition/ do
  24. log "from step definition"
  25. end
  26. Given /^I attach data directly/ do
  27. data = "YWJj"
  28. attach data, "mime-type;base64"
  29. end
  30. """
  31. And a file named "features/attachments.feature" with:
  32. """
  33. Feature: A screenshot feature
  34. Scenario:
  35. Given I attach a screenshot
  36. """
  37. And a file named "features/outline.feature" with:
  38. """
  39. Feature: An outline feature
  40. Scenario Outline: outline
  41. Given this step <status>
  42. Examples: examples1
  43. | status |
  44. | passes |
  45. | fails |
  46. Examples: examples2
  47. | status |
  48. | passes |
  49. """
  50. And a file named "features/print_from_step_definition.feature" with:
  51. """
  52. Feature: A print from step definition feature
  53. Scenario:
  54. Given I print from step definition
  55. And I print from step definition
  56. """
  57. And a file named "features/print_from_step_definition.feature" with:
  58. """
  59. Feature: A print from step definition feature
  60. Scenario:
  61. Given I print from step definition
  62. And I print from step definition
  63. """
  64. And a file named "features/attach_data_directly.feature" with:
  65. """
  66. Feature: An embed data directly feature
  67. Scenario:
  68. Given I attach data directly
  69. Scenario Outline:
  70. Given I attach data directly
  71. Examples:
  72. | dummy |
  73. | 1 |
  74. | 2 |
  75. """
  76. And a file named "features/out_scenario_out_scenario_outline.feature" with:
  77. """
  78. Feature:
  79. Scenario:
  80. Given this step passes
  81. Scenario Outline:
  82. Given this step <status>
  83. Examples:
  84. | status |
  85. | passes |
  86. """
  87. # Need to investigate why this won't pass in-process. error_message doesn't get det?
  88. Scenario: one feature, one passing scenario, one failing scenario
  89. When I run `cucumber --format json features/one_passing_one_failing.feature`
  90. Then it should fail with JSON:
  91. """
  92. [
  93. {
  94. "uri": "features/one_passing_one_failing.feature",
  95. "keyword": "Feature",
  96. "id": "one-passing-scenario,-one-failing-scenario",
  97. "name": "One passing scenario, one failing scenario",
  98. "line": 2,
  99. "description": "",
  100. "tags": [
  101. {
  102. "name": "@a",
  103. "line": 1
  104. }
  105. ],
  106. "elements": [
  107. {
  108. "keyword": "Scenario",
  109. "id": "one-passing-scenario,-one-failing-scenario;passing",
  110. "name": "Passing",
  111. "line": 5,
  112. "description": "",
  113. "tags": [
  114. {
  115. "name": "@a",
  116. "line": 1
  117. },
  118. {
  119. "name": "@b",
  120. "line": 4
  121. }
  122. ],
  123. "type": "scenario",
  124. "steps": [
  125. {
  126. "keyword": "Given ",
  127. "name": "this step passes",
  128. "line": 6,
  129. "match": {
  130. "location": "features/step_definitions/steps.rb:1"
  131. },
  132. "result": {
  133. "status": "passed",
  134. "duration": 1
  135. }
  136. }
  137. ]
  138. },
  139. {
  140. "keyword": "Scenario",
  141. "id": "one-passing-scenario,-one-failing-scenario;failing",
  142. "name": "Failing",
  143. "line": 9,
  144. "description": "",
  145. "tags": [
  146. {
  147. "name": "@a",
  148. "line": 1
  149. },
  150. {
  151. "name": "@c",
  152. "line": 8
  153. }
  154. ],
  155. "type": "scenario",
  156. "steps": [
  157. {
  158. "keyword": "Given ",
  159. "name": "this step fails",
  160. "line": 10,
  161. "match": {
  162. "location": "features/step_definitions/steps.rb:4"
  163. },
  164. "result": {
  165. "status": "failed",
  166. "error_message": " (RuntimeError)\n./features/step_definitions/steps.rb:4:in `/^this step fails$/'\nfeatures/one_passing_one_failing.feature:10:in `this step fails'",
  167. "duration": 1
  168. }
  169. }
  170. ]
  171. }
  172. ]
  173. }
  174. ]
  175. """
  176. Scenario: DocString
  177. Given a file named "features/doc_string.feature" with:
  178. """
  179. Feature: A DocString feature
  180. Scenario:
  181. Then I should fail with
  182. \"\"\"
  183. a string
  184. \"\"\"
  185. """
  186. And a file named "features/step_definitions/steps.rb" with:
  187. """
  188. Then /I should fail with/ do |s|
  189. raise RuntimeError, s
  190. end
  191. """
  192. When I run `cucumber --format json features/doc_string.feature`
  193. Then it should fail with JSON:
  194. """
  195. [
  196. {
  197. "id": "a-docstring-feature",
  198. "uri": "features/doc_string.feature",
  199. "keyword": "Feature",
  200. "name": "A DocString feature",
  201. "line": 1,
  202. "description": "",
  203. "elements": [
  204. {
  205. "id": "a-docstring-feature;",
  206. "keyword": "Scenario",
  207. "name": "",
  208. "line": 3,
  209. "description": "",
  210. "type": "scenario",
  211. "steps": [
  212. {
  213. "keyword": "Then ",
  214. "name": "I should fail with",
  215. "line": 4,
  216. "doc_string": {
  217. "content_type": "",
  218. "value": "a string",
  219. "line": 5
  220. },
  221. "match": {
  222. "location": "features/step_definitions/steps.rb:1"
  223. },
  224. "result": {
  225. "status": "failed",
  226. "error_message": "a string (RuntimeError)\n./features/step_definitions/steps.rb:2:in `/I should fail with/'\nfeatures/doc_string.feature:4:in `I should fail with'",
  227. "duration": 1
  228. }
  229. }
  230. ]
  231. }
  232. ]
  233. }
  234. ]
  235. """
  236. Scenario: Attaching screenshot
  237. When I run `cucumber --format json features/attachments.feature`
  238. Then it should pass with JSON:
  239. """
  240. [
  241. {
  242. "uri": "features/attachments.feature",
  243. "id": "a-screenshot-feature",
  244. "keyword": "Feature",
  245. "name": "A screenshot feature",
  246. "line": 1,
  247. "description": "",
  248. "elements": [
  249. {
  250. "id": "a-screenshot-feature;",
  251. "keyword": "Scenario",
  252. "name": "",
  253. "line": 3,
  254. "description": "",
  255. "type": "scenario",
  256. "steps": [
  257. {
  258. "keyword": "Given ",
  259. "name": "I attach a screenshot",
  260. "line": 4,
  261. "embeddings": [
  262. {
  263. "mime_type": "image/png",
  264. "data": "Zm9v"
  265. }
  266. ],
  267. "match": {
  268. "location": "features/step_definitions/json_steps.rb:1"
  269. },
  270. "result": {
  271. "status": "passed",
  272. "duration": 1
  273. }
  274. }
  275. ]
  276. }
  277. ]
  278. }
  279. ]
  280. """
  281. Scenario: scenario outline
  282. When I run `cucumber --format json features/outline.feature`
  283. Then it should fail with JSON:
  284. """
  285. [
  286. {
  287. "uri": "features/outline.feature",
  288. "id": "an-outline-feature",
  289. "keyword": "Feature",
  290. "name": "An outline feature",
  291. "line": 1,
  292. "description": "",
  293. "elements": [
  294. {
  295. "id": "an-outline-feature;outline;examples1;2",
  296. "keyword": "Scenario Outline",
  297. "name": "outline",
  298. "description": "",
  299. "line": 8,
  300. "type": "scenario",
  301. "steps": [
  302. {
  303. "keyword": "Given ",
  304. "name": "this step passes",
  305. "line": 4,
  306. "match": {
  307. "location": "features/step_definitions/steps.rb:1"
  308. },
  309. "result": {
  310. "status": "passed",
  311. "duration": 1
  312. }
  313. }
  314. ]
  315. },
  316. {
  317. "id": "an-outline-feature;outline;examples1;3",
  318. "keyword": "Scenario Outline",
  319. "name": "outline",
  320. "description": "",
  321. "line": 9,
  322. "type": "scenario",
  323. "steps": [
  324. {
  325. "keyword": "Given ",
  326. "name": "this step fails",
  327. "line": 4,
  328. "match": {
  329. "location": "features/step_definitions/steps.rb:4"
  330. },
  331. "result": {
  332. "status": "failed",
  333. "error_message": " (RuntimeError)\n./features/step_definitions/steps.rb:4:in `/^this step fails$/'\nfeatures/outline.feature:9:4:in `this step fails'",
  334. "duration": 1
  335. }
  336. }
  337. ]
  338. },
  339. {
  340. "id": "an-outline-feature;outline;examples2;2",
  341. "keyword": "Scenario Outline",
  342. "name": "outline",
  343. "description": "",
  344. "line": 13,
  345. "type": "scenario",
  346. "steps": [
  347. {
  348. "keyword": "Given ",
  349. "name": "this step passes",
  350. "line": 4,
  351. "match": {
  352. "location": "features/step_definitions/steps.rb:1"
  353. },
  354. "result": {
  355. "status": "passed",
  356. "duration": 1
  357. }
  358. }
  359. ]
  360. }
  361. ]
  362. }
  363. ]
  364. """
  365. Scenario: scenario outline with docstring
  366. Given a file named "features/outline_doc_string.feature" with:
  367. """
  368. Feature: An outline feature with a DocString
  369. Scenario Outline: outline
  370. Then I should fail with
  371. \"\"\"
  372. <status>
  373. \"\"\"
  374. Examples: examples1
  375. | status |
  376. | passes |
  377. | fails |
  378. """
  379. And a file named "features/step_definitions/steps.rb" with:
  380. """
  381. Then /I should fail with/ do |s|
  382. raise RuntimeError, s
  383. end
  384. """
  385. When I run `cucumber --format json features/outline_doc_string.feature`
  386. Then it should fail with JSON:
  387. """
  388. [
  389. {
  390. "id": "an-outline-feature-with-a-docstring",
  391. "uri": "features/outline_doc_string.feature",
  392. "keyword": "Feature",
  393. "name": "An outline feature with a DocString",
  394. "line": 1,
  395. "description": "",
  396. "elements": [
  397. {
  398. "id": "an-outline-feature-with-a-docstring;outline;examples1;2",
  399. "keyword": "Scenario Outline",
  400. "name": "outline",
  401. "line": 11,
  402. "description": "",
  403. "type": "scenario",
  404. "steps": [
  405. {
  406. "keyword": "Then ",
  407. "name": "I should fail with",
  408. "line": 4,
  409. "doc_string": {
  410. "content_type": "",
  411. "value": "passes",
  412. "line": 5
  413. },
  414. "match": {
  415. "location": "features/step_definitions/steps.rb:1"
  416. },
  417. "result": {
  418. "status": "failed",
  419. "error_message": "passes (RuntimeError)\n./features/step_definitions/steps.rb:2:in `/I should fail with/'\nfeatures/outline_doc_string.feature:11:4:in `I should fail with'",
  420. "duration": 1
  421. }
  422. }
  423. ]
  424. },
  425. {
  426. "id": "an-outline-feature-with-a-docstring;outline;examples1;3",
  427. "keyword": "Scenario Outline",
  428. "name": "outline",
  429. "line": 12,
  430. "description": "",
  431. "type": "scenario",
  432. "steps": [
  433. {
  434. "keyword": "Then ",
  435. "name": "I should fail with",
  436. "line": 4,
  437. "doc_string": {
  438. "content_type": "",
  439. "value": "fails",
  440. "line": 5
  441. },
  442. "match": {
  443. "location": "features/step_definitions/steps.rb:1"
  444. },
  445. "result": {
  446. "status": "failed",
  447. "error_message": "fails (RuntimeError)\n./features/step_definitions/steps.rb:2:in `/I should fail with/'\nfeatures/outline_doc_string.feature:12:4:in `I should fail with'",
  448. "duration": 1
  449. }
  450. }
  451. ]
  452. }
  453. ]
  454. }
  455. ]
  456. """
  457. Scenario: print from step definition
  458. When I run `cucumber --format json features/print_from_step_definition.feature`
  459. Then it should pass with JSON:
  460. """
  461. [
  462. {
  463. "uri": "features/print_from_step_definition.feature",
  464. "id": "a-print-from-step-definition-feature",
  465. "keyword": "Feature",
  466. "name": "A print from step definition feature",
  467. "line": 1,
  468. "description": "",
  469. "elements": [
  470. {
  471. "id": "a-print-from-step-definition-feature;",
  472. "keyword": "Scenario",
  473. "name": "",
  474. "line": 3,
  475. "description": "",
  476. "type": "scenario",
  477. "steps": [
  478. {
  479. "keyword": "Given ",
  480. "name": "I print from step definition",
  481. "line": 4,
  482. "output": [
  483. "from step definition"
  484. ],
  485. "match": {
  486. "location": "features/step_definitions/json_steps.rb:6"
  487. },
  488. "result": {
  489. "status": "passed",
  490. "duration": 1
  491. }
  492. },
  493. {
  494. "keyword": "And ",
  495. "name": "I print from step definition",
  496. "line": 5,
  497. "output": [
  498. "from step definition"
  499. ],
  500. "match": {
  501. "location": "features/step_definitions/json_steps.rb:6"
  502. },
  503. "result": {
  504. "status": "passed",
  505. "duration": 1
  506. }
  507. }
  508. ]
  509. }
  510. ]
  511. }
  512. ]
  513. """
  514. Scenario: scenario outline expanded
  515. When I run `cucumber --expand --format json features/outline.feature`
  516. Then it should fail with JSON:
  517. """
  518. [
  519. {
  520. "uri": "features/outline.feature",
  521. "id": "an-outline-feature",
  522. "keyword": "Feature",
  523. "name": "An outline feature",
  524. "line": 1,
  525. "description": "",
  526. "elements": [
  527. {
  528. "id": "an-outline-feature;outline;examples1;2",
  529. "keyword": "Scenario Outline",
  530. "name": "outline",
  531. "line": 8,
  532. "description": "",
  533. "type": "scenario",
  534. "steps": [
  535. {
  536. "keyword": "Given ",
  537. "name": "this step passes",
  538. "line": 4,
  539. "match": {
  540. "location": "features/step_definitions/steps.rb:1"
  541. },
  542. "result": {
  543. "status": "passed",
  544. "duration": 1
  545. }
  546. }
  547. ]
  548. },
  549. {
  550. "id": "an-outline-feature;outline;examples1;3",
  551. "keyword": "Scenario Outline",
  552. "name": "outline",
  553. "line": 9,
  554. "description": "",
  555. "type": "scenario",
  556. "steps": [
  557. {
  558. "keyword": "Given ",
  559. "name": "this step fails",
  560. "line": 4,
  561. "match": {
  562. "location": "features/step_definitions/steps.rb:4"
  563. },
  564. "result": {
  565. "status": "failed",
  566. "error_message" : " (RuntimeError)\n./features/step_definitions/steps.rb:4:in `/^this step fails$/'\nfeatures/outline.feature:9:4:in `this step fails'",
  567. "duration": 1
  568. }
  569. }
  570. ]
  571. },
  572. {
  573. "id": "an-outline-feature;outline;examples2;2",
  574. "keyword": "Scenario Outline",
  575. "name": "outline",
  576. "line": 13,
  577. "description": "",
  578. "type": "scenario",
  579. "steps": [
  580. {
  581. "keyword": "Given ",
  582. "name": "this step passes",
  583. "line": 4,
  584. "match": {
  585. "location": "features/step_definitions/steps.rb:1"
  586. },
  587. "result": {
  588. "status": "passed",
  589. "duration": 1
  590. }
  591. }
  592. ]
  593. }
  594. ]
  595. }
  596. ]
  597. """
  598. Scenario: Attaching data directly
  599. When I run `cucumber --format json -x features/attach_data_directly.feature`
  600. Then it should pass with JSON:
  601. """
  602. [
  603. {
  604. "uri": "features/attach_data_directly.feature",
  605. "id": "an-embed-data-directly-feature",
  606. "keyword": "Feature",
  607. "name": "An embed data directly feature",
  608. "line": 1,
  609. "description": "",
  610. "elements": [
  611. {
  612. "id": "an-embed-data-directly-feature;",
  613. "keyword": "Scenario",
  614. "name": "",
  615. "line": 3,
  616. "description": "",
  617. "type": "scenario",
  618. "steps": [
  619. {
  620. "keyword": "Given ",
  621. "name": "I attach data directly",
  622. "line": 4,
  623. "embeddings": [
  624. {
  625. "mime_type": "mime-type",
  626. "data": "YWJj"
  627. }
  628. ],
  629. "match": {
  630. "location": "features/step_definitions/json_steps.rb:10"
  631. },
  632. "result": {
  633. "status": "passed",
  634. "duration": 1
  635. }
  636. }
  637. ]
  638. },
  639. {
  640. "keyword": "Scenario Outline",
  641. "name": "",
  642. "line": 11,
  643. "description": "",
  644. "id": "an-embed-data-directly-feature;;;2",
  645. "type": "scenario",
  646. "steps": [
  647. {
  648. "keyword": "Given ",
  649. "name": "I attach data directly",
  650. "line": 7,
  651. "embeddings": [
  652. {
  653. "mime_type": "mime-type",
  654. "data": "YWJj"
  655. }
  656. ],
  657. "match": {
  658. "location": "features/step_definitions/json_steps.rb:10"
  659. },
  660. "result": {
  661. "status": "passed",
  662. "duration": 1
  663. }
  664. }
  665. ]
  666. },
  667. {
  668. "keyword": "Scenario Outline",
  669. "name": "",
  670. "line": 12,
  671. "description": "",
  672. "id": "an-embed-data-directly-feature;;;3",
  673. "type": "scenario",
  674. "steps": [
  675. {
  676. "keyword": "Given ",
  677. "name": "I attach data directly",
  678. "line": 7,
  679. "embeddings": [
  680. {
  681. "mime_type": "mime-type",
  682. "data": "YWJj"
  683. }
  684. ],
  685. "match": {
  686. "location": "features/step_definitions/json_steps.rb:10"
  687. },
  688. "result": {
  689. "status": "passed",
  690. "duration": 1
  691. }
  692. }
  693. ]
  694. }
  695. ]
  696. }
  697. ]
  698. """
  699. Scenario: handle output from hooks
  700. Given a file named "features/step_definitions/output_steps.rb" with:
  701. """
  702. Before do
  703. log "Before hook 1"
  704. attach "src", "mime_type"
  705. end
  706. Before do
  707. log "Before hook 2"
  708. attach "src", "mime_type"
  709. end
  710. AfterStep do
  711. log "AfterStep hook 1"
  712. attach "src", "mime_type"
  713. end
  714. AfterStep do
  715. log "AfterStep hook 2"
  716. attach "src", "mime_type"
  717. end
  718. After do
  719. log "After hook 1"
  720. attach "src", "mime_type"
  721. end
  722. After do
  723. log "After hook 2"
  724. attach "src", "mime_type"
  725. end
  726. """
  727. When I run `cucumber --format json features/out_scenario_out_scenario_outline.feature`
  728. Then it should pass

No Description

Contributors (1)