目前,我在自动化框架中有一组 json 文件。每个 json 文件中都有一个包含一组相似 json 对象的数组。我需要使用这些文件从使用 java 中的 cucumber 和 selenium 的 Web 应用程序进行验证。以下是每个 json 文件中存在的 json 数组的示例:
[
{
"Status": "Active",
"Company": "XYZ",
"PackageId": "551819",
"ProductCode": "BACC"
},
{
"Status": "Active",
"Company": "ABC",
"PackageId": "551829",
"ProductCode": "IRE7"
},
{
"Status": "Active",
"Company": "MAU",
"PackageId": "551009",
"ProductCode": "BACC"
},
{
"Status": "Active",
"Company": "XYZ",
"PackageId": "551073",
"ProductCode": "AXM"
}
]
所有文件都包含类似的 json 数组。我的框架需要获取所有这些文件,并从每个文件的每个数组的每个 json 对象中获取数据,并使用 Cucumber Step 定义文件的单个场景使用 Web 应用程序中反射(reflect)的数据对其进行验证。任何人都可以建议我如何完成,因为我从未在 Cucumber 框架中为数据提供程序运行一组文件?
最佳答案
这可以帮助你吗?
使用 JSON 和 Cucumber 进行数据驱动测试
我们必须在本章中的项目中进行大量修改才能使用 JSON 文件实现数据驱动技术:
1.Decide what data needs to pass through JSON files
2.Create JSON Data set
3.Write a Java POJO class to represent JSON data
4.Pass JSON data file location to Properties file and Write a method to read the same
5.Create a JSON Data Reader class
6.Modify FileReaderManager to accommodate JSON Data Reader
7.Modify Checkout Steps file to pass Test Data to Checkout Page Objects
8.Modify Checkout Page object to use Test Data object
https://www.toolsqa.com/selenium-cucumber-framework/data-driven-testing-using-json-with-cucumber/
关于java - 如何通过Cucumber从多个json文件中获取数据进行验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62299037/