gpt4 book ai didi

c# - 提供超过 1 行的示例 Specflow

转载 作者:行者123 更新时间:2023-11-30 21:57:08 24 4
gpt4 key购买 nike

当我在一行中提供示例时,它工作正常。当我连续提供多个示例时,我遇到了绑定(bind)参数异常。如果我在一行中提供所有示例,那么它不容易阅读。

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 |

然后您的基础文件夹可以相对于您的项目创建并作为测试构建的一部分进行部署,或者可以保存在配置中。

关于c# - 提供超过 1 行的示例 Specflow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30893972/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com