在多行规范流中提供示例
本文关键字:范流中 行规 | 更新日期: 2023-09-27 17:56:41
当我在一行中提供示例时,它工作正常。当我在多行中提供示例时,我得到绑定参数异常。如果我在一行中提供所有示例,则不容易阅读。
Feature: ConversionUnencrypted Pdf-Pdf
@mytag
Scenario Outline: ConversionUnencrypted Pdf-Pdf
Given I get Inputs Folder and list of Files <inputFolder> then <getInputTokens>
Given I get '<outputDirectory>'
Given I get directory to save Images '<ImagesOutputDirectory>'
Examples:
| inputFolder | getInputTokens | outputDirectory | ImagesOutputDirectory |
| D:'SVN_Projects'XDoc.Net'SpecFlow'Conversion'ConvertToPdf'Inputs'2files | Input1.pdf,Input2.pdf | D:'SVN_Projects'XDoc.Net'SpecFlow'Conversion'ConvertToPdf'AfterConvertingToPdf'2files | D:'SVN_Projects'XDoc.Net'SpecFlow'Conversion'ConvertToPdf'Actual'2files |
Given I set saving Mode <ConversionMode>
Given I convert pdf using Conversion
Given I convert to Image '<convertToFile>'
Then I compare Images '<getActualImagePath>' and '<getExpectedImagePath>' and '<pageCount>'
| ConversionMode | convertToFile | getActualImagePath | getExpectedImagePath | pageCount |
| ConvertToSingleFile | D:'SVN_Projects'XDoc.Net'SpecFlow'Conversion'ConvertToPdf'AfterConvertingToPdf'2files | D:'SVN_Projects'XDoc.Net'SpecFlow'Conversion'ConvertToPdf'Actual'2files | D:'SVN_Projects'XDoc.Net'SpecFlow'Conversion'ConvertToPdf'Expected'2files | 82 |
如果示例如下所示,则工作正常:
Examples:
| inputFolder | getInputTokens | outputDirectory | ImagesOutputDirectory | ConversionMode | convertToFile | getActualImagePath | getExpectedImagePath | pageCount |
| D:'SVN_Projects'XDoc.Net'SpecFlow'Conversion'ConvertToPdf'Inputs'2files | Input1.pdf,Input2.pdf | D:'SVN_Projects'XDoc.Net'SpecFlow'Conversion'ConvertToPdf'AfterConvertingToPdf'2files' | D:'SVN_Projects'XDoc.Net'SpecFlow'Conversion'ConvertToPdf'Actual'2files'| ConvertToSingleFile | D:'SVN_Projects'XDoc.Net'SpecFlow'Conversion'ConvertToPdf'AfterConvertingToPdf'2files' | D:'SVN_Projects'XDoc.Net'SpecFlow'Conversion'ConvertToPdf'Actual'2files |D:'SVN_Projects'XDoc.Net'SpecFlow'Conversion'ConvertToPdf'Expected'2files | 82 |
您的第一个方案有几个问题。你已经把你的步骤和你的例子混为一谈了。这些步骤必须位于方案大纲中,不能在示例中。
鉴于此,如果您使用大纲中的步骤重新编写方案,则它看起来像这样:
Feature: ConversionUnencrypted Pdf-Pdf
@mytag
Scenario Outline: ConversionUnencrypted Pdf-Pdf
Given I get Inputs Folder and list of Files <inputFolder> then <getInputTokens>
Given I get '<outputDirectory>'
Given I get directory to save Images '<ImagesOutputDirectory>'
Given I set saving Mode <ConversionMode>
Given I convert pdf using Conversion
Given I convert to Image '<convertToFile>'
Then I compare Images '<getActualImagePath>' and '<getExpectedImagePath>' and '<pageCount>'
Examples:
| inputFolder | getInputTokens | outputDirectory | ImagesOutputDirectory |
| D:'SVN_Projects'XDoc.Net'SpecFlow'Conversion'ConvertToPdf'Inputs'2files | Input1.pdf,Input2.pdf | D:'SVN_Projects'XDoc.Net'SpecFlow'Conversion'ConvertToPdf'AfterConvertingToPdf'2files | D:'SVN_Projects'XDoc.Net'SpecFlow'Conversion'ConvertToPdf'Actual'2files |
| ConversionMode | convertToFile | getActualImagePath | getExpectedImagePath | pageCount |
| ConvertToSingleFile | D:'SVN_Projects'XDoc.Net'SpecFlow'Conversion'ConvertToPdf'AfterConvertingToPdf'2files | D:'SVN_Projects'XDoc.Net'SpecFlow'Conversion'ConvertToPdf'Actual'2files | D:'SVN_Projects'XDoc.Net'SpecFlow'Conversion'ConvertToPdf'Expected'2files | 82 |
现在更明显的是为什么你不能在不同的行上有两组示例,因为看起来inputFolder
的值为 ConversionMode
,而实际上ConversionMode
是一个标题。
这里的主要问题是您的示例中有完整的文件路径。这是一个实现细节,恕我直言,最好删除这些路径并改用名字对象。 毕竟,所有这些完整的文件路径不会在其他人的机器上工作,而不是在构建服务器上。我会考虑这样重写它们:
Examples:
| inputFolder | getInputTokens | outputDirectory | ImagesOutputDirectory | ConversionMode | convertToFile | getActualImagePath | getExpectedImagePath | pageCount |
| 2files | Input1.pdf,Input2.pdf | 2files | 2files | ConvertToSingleFile | 2files | 2files | 2files | 82 |
虽然即使这样也有很多重复的信息,但现在它已经减少了,所以你的整个场景可以像这样重写
Feature: ConversionUnencrypted Pdf-Pdf
@mytag
Scenario Outline: ConversionUnencrypted Pdf-Pdf
Given I am processing files in the subdirectory <workingFolder> of the input folder then <getInputTokens>
And I save file to the subdirectory <workingFolder> of the output folder
And I save Images to the subdirectory <workingFolder> of the images folder
And I set saving Mode <ConversionMode>
And I convert pdf using Conversion
And I convert to Image the files in the subdirectory <workingFolder> of the output folder
When I compare Images of page '<pageCount>' in the subdirectory <workingFolder> of the actual image folder and subdirectory <workingFolder> of the expected image folder
Then the images should be the same
Examples:
| workingFolder | getInputTokens | ConversionMode | pageCount |
| 2files | Input1.pdf,Input2.pdf | ConvertToSingleFile | 82 |
然后,可以将基文件夹相对于项目创建并作为测试生成的一部分进行部署,也可以保存在配置中。