声明一个 Json 对象
Asserting a Json Object
我有一个应用程序,其中有一个表单,其中包含所有控件,例如(文本框、下拉列表、列表、文本区域、复选框、表格)
并且所有数据在保存时都保存为 json 对象,并且该对象存储在数据库的列之一中。
现在我正在自动化这个表单,我想断言这个页面。
目前采取的方法:
从 UI 页面中,捕获 Dictionary 对象中的所有数据,然后在 json 对象中进行相同的转换。
这是它的样子
{
"AtRiskSchoolName": "11!!!!@@@@@@@@@@@@@",
"PercentFreeReduced": "11.00",
"IsAtRiskSite": "Yes",
"Associated": "Non-Profit Center or Public Institution: Children or Adults",
"FacilityType": "Rented/Leased",
"SiteTypes": "Child",
"ParticipantXIXX": "1",
"ParticipantFree": "8",
"ParticipantReduced": "8",
"ParticipantPaid": "99",
"TraditionalMeals[0].Value1": "6:00am",
"TraditionalMeals[0].Value2": "6:30am",
"TraditionalMeals[0].Value3": "7:00am",
"TraditionalMeals[0].Value4": "7:30am",
"TraditionalMeals[1].Value1": "8:00am",
"TraditionalMeals[1].Value2": "8:30am",
"TraditionalMeals[1].Value3": "9:00am",
"TraditionalMeals[1].Value4": "9:30am",
"TraditionalMeals[2].Value1": "11:00am",
"TraditionalMeals[2].Value2": "11:30am",
"TraditionalMeals[2].Value3": "12:00pm",
"TraditionalMeals[2].Value4": "12:30pm"
}
并从数据库中捕获了整个json对象,然后将其解析为json对象。
Json 数据库中的对象看起来像:-
{
"AlwaysOptional": false,
"Associated": "Non-Profit",
"AtRiskAreaEligibilityExpiryDate": "0001-01-01T00:00:00",
"AtRiskMeals": [{
"Address": null,
"Type": "Breakfast",
"Value1": "7:00am",
"Value2": "7:30am",
"Value3": null,
"Value4": null
}, {
"Address": null,
"Type": "Morning Snack",
"Value1": null,
"Value2": null,
"Value3": null,
"Value4": null
}, {
"Address": null,
"Type": "Lunch",
"Value1": null,
"Value2": null,
"Value3": null,
"Value4": null
}, {
"Address": null,
"Type": "Afternoon Snack",
"Value1": null,
"Value2": null,
"Value3": null,
"Value4": null
}, {
"Address": null,
"Type": "Supper",
"Value1": null,
"Value2": null,
"Value3": null,
"Value4": null
}, {
"Address": null,
"Type": "Evening Snack",
"Value1": null,
"Value2": null,
"Value3": null,
"Value4": null
}
],
"AtRiskSchoolName": "11!!!!@@@@@@@@@@@@@",
"Ethnic": [{
"Address": null,
"Type": "Hispanic or Latino (Cuban, Mexican, Puerto Rican, South or Central American, or other Spanish culture or origin regardless of race.)",
"Value1": "1",
"Value2": "50.00",
"Value3": "50",
"Value4": null
}, {
"Address": null,
"Type": "Non-Hispanic or Non-Latino (All others, Irish, French, German, etc.)",
"Value1": "1",
"Value2": "50.00",
"Value3": "50",
"Value4": null
}, {
"Address": null,
"Type": "Total",
"Value1": "2",
"Value2": "100.00",
"Value3": "100.00",
"Value4": null
}
],
"FacilityType": "sitelease",
"IsAtRiskSite": true,
"ParticipantFree": 8,
"ParticipantPaid": 99,
"ParticipantReduced": 8,
"ParticipantXIXX": 1,
"PercentFreeReduced": 11.0,
"Racial": [{
"Address": null,
"Type": "White",
"Value1": "1",
"Value2": "14.29",
"Value3": "10",
"Value4": null
}, {
"Address": null,
"Type": "Black or African American",
"Value1": "1",
"Value2": "14.29",
"Value3": "10",
"Value4": null
}, {
"Address": null,
"Type": "American Indian or Alaskan Native",
"Value1": "1",
"Value2": "14.29",
"Value3": "10",
"Value4": null
}, {
"Address": null,
"Type": "Asian",
"Value1": "1",
"Value2": "14.29",
"Value3": "10",
"Value4": null
}, {
"Address": null,
"Type": "Native Hawaiian",
"Value1": "1",
"Value2": "14.29",
"Value3": "40",
"Value4": null
}, {
"Address": null,
"Type": "Some Other Race",
"Value1": "1",
"Value2": "14.29",
"Value3": "10",
"Value4": null
}, {
"Address": null,
"Type": "Two or More Races",
"Value1": "1",
"Value2": "14.29",
"Value3": "10",
"Value4": null
}, {
"Address": null,
"Type": "Total",
"Value1": "7",
"Value2": "100.00",
"Value3": "100.00",
"Value4": null
}
],
"SiteIsRemoved": false,
"SiteName": "Beaver",
"SiteType": "Child",
"TotalEnrolled": 115,
"TraditionalMeals": [{
"Address": null,
"Type": "Breakfast",
"Value1": "6:00am",
"Value2": "6:30am",
"Value3": "7:00am",
"Value4": "7:30am"
}, {
"Address": null,
"Type": "Morning Snack",
"Value1": "8:00am",
"Value2": "8:30am",
"Value3": "9:00am",
"Value4": "9:30am"
}, {
"Address": null,
"Type": "Lunch",
"Value1": "11:00am",
"Value2": "11:30am",
"Value3": "12:00pm",
"Value4": "12:30pm"
}, {
"Address": null,
"Type": "Afternoon Snack",
"Value1": null,
"Value2": null,
"Value3": null,
"Value4": null
}, {
"Address": null,
"Type": "Supper",
"Value1": null,
"Value2": null,
"Value3": null,
"Value4": null
}, {
"Address": null,
"Type": "Evening Snack",
"Value1": null,
"Value2": null,
"Value3": null,
"Value4": null
}
]
}
当我尝试断言这两个对象时出现问题,它失败了,因为数据库中的对象只有很少的元素作为数组,这意味着您可以在单个 json 对象中包含多个对象。
当我尝试从 UI 元素构造我的 Json 对象时,我无法构造元素数组。
请告知这样做是否正确。
我在 C# 中使用 selenium
感谢您的帮助。
通过从 UI 创建一个 Dictionary 对象然后在 Dictionary 对象中转换 json 对象找到解决方案。
我有一个应用程序,其中有一个表单,其中包含所有控件,例如(文本框、下拉列表、列表、文本区域、复选框、表格) 并且所有数据在保存时都保存为 json 对象,并且该对象存储在数据库的列之一中。 现在我正在自动化这个表单,我想断言这个页面。
目前采取的方法:
从 UI 页面中,捕获 Dictionary 对象中的所有数据,然后在 json 对象中进行相同的转换。 这是它的样子
{
"AtRiskSchoolName": "11!!!!@@@@@@@@@@@@@",
"PercentFreeReduced": "11.00",
"IsAtRiskSite": "Yes",
"Associated": "Non-Profit Center or Public Institution: Children or Adults",
"FacilityType": "Rented/Leased",
"SiteTypes": "Child",
"ParticipantXIXX": "1",
"ParticipantFree": "8",
"ParticipantReduced": "8",
"ParticipantPaid": "99",
"TraditionalMeals[0].Value1": "6:00am",
"TraditionalMeals[0].Value2": "6:30am",
"TraditionalMeals[0].Value3": "7:00am",
"TraditionalMeals[0].Value4": "7:30am",
"TraditionalMeals[1].Value1": "8:00am",
"TraditionalMeals[1].Value2": "8:30am",
"TraditionalMeals[1].Value3": "9:00am",
"TraditionalMeals[1].Value4": "9:30am",
"TraditionalMeals[2].Value1": "11:00am",
"TraditionalMeals[2].Value2": "11:30am",
"TraditionalMeals[2].Value3": "12:00pm",
"TraditionalMeals[2].Value4": "12:30pm"
}
并从数据库中捕获了整个json对象,然后将其解析为json对象。 Json 数据库中的对象看起来像:-
{
"AlwaysOptional": false,
"Associated": "Non-Profit",
"AtRiskAreaEligibilityExpiryDate": "0001-01-01T00:00:00",
"AtRiskMeals": [{
"Address": null,
"Type": "Breakfast",
"Value1": "7:00am",
"Value2": "7:30am",
"Value3": null,
"Value4": null
}, {
"Address": null,
"Type": "Morning Snack",
"Value1": null,
"Value2": null,
"Value3": null,
"Value4": null
}, {
"Address": null,
"Type": "Lunch",
"Value1": null,
"Value2": null,
"Value3": null,
"Value4": null
}, {
"Address": null,
"Type": "Afternoon Snack",
"Value1": null,
"Value2": null,
"Value3": null,
"Value4": null
}, {
"Address": null,
"Type": "Supper",
"Value1": null,
"Value2": null,
"Value3": null,
"Value4": null
}, {
"Address": null,
"Type": "Evening Snack",
"Value1": null,
"Value2": null,
"Value3": null,
"Value4": null
}
],
"AtRiskSchoolName": "11!!!!@@@@@@@@@@@@@",
"Ethnic": [{
"Address": null,
"Type": "Hispanic or Latino (Cuban, Mexican, Puerto Rican, South or Central American, or other Spanish culture or origin regardless of race.)",
"Value1": "1",
"Value2": "50.00",
"Value3": "50",
"Value4": null
}, {
"Address": null,
"Type": "Non-Hispanic or Non-Latino (All others, Irish, French, German, etc.)",
"Value1": "1",
"Value2": "50.00",
"Value3": "50",
"Value4": null
}, {
"Address": null,
"Type": "Total",
"Value1": "2",
"Value2": "100.00",
"Value3": "100.00",
"Value4": null
}
],
"FacilityType": "sitelease",
"IsAtRiskSite": true,
"ParticipantFree": 8,
"ParticipantPaid": 99,
"ParticipantReduced": 8,
"ParticipantXIXX": 1,
"PercentFreeReduced": 11.0,
"Racial": [{
"Address": null,
"Type": "White",
"Value1": "1",
"Value2": "14.29",
"Value3": "10",
"Value4": null
}, {
"Address": null,
"Type": "Black or African American",
"Value1": "1",
"Value2": "14.29",
"Value3": "10",
"Value4": null
}, {
"Address": null,
"Type": "American Indian or Alaskan Native",
"Value1": "1",
"Value2": "14.29",
"Value3": "10",
"Value4": null
}, {
"Address": null,
"Type": "Asian",
"Value1": "1",
"Value2": "14.29",
"Value3": "10",
"Value4": null
}, {
"Address": null,
"Type": "Native Hawaiian",
"Value1": "1",
"Value2": "14.29",
"Value3": "40",
"Value4": null
}, {
"Address": null,
"Type": "Some Other Race",
"Value1": "1",
"Value2": "14.29",
"Value3": "10",
"Value4": null
}, {
"Address": null,
"Type": "Two or More Races",
"Value1": "1",
"Value2": "14.29",
"Value3": "10",
"Value4": null
}, {
"Address": null,
"Type": "Total",
"Value1": "7",
"Value2": "100.00",
"Value3": "100.00",
"Value4": null
}
],
"SiteIsRemoved": false,
"SiteName": "Beaver",
"SiteType": "Child",
"TotalEnrolled": 115,
"TraditionalMeals": [{
"Address": null,
"Type": "Breakfast",
"Value1": "6:00am",
"Value2": "6:30am",
"Value3": "7:00am",
"Value4": "7:30am"
}, {
"Address": null,
"Type": "Morning Snack",
"Value1": "8:00am",
"Value2": "8:30am",
"Value3": "9:00am",
"Value4": "9:30am"
}, {
"Address": null,
"Type": "Lunch",
"Value1": "11:00am",
"Value2": "11:30am",
"Value3": "12:00pm",
"Value4": "12:30pm"
}, {
"Address": null,
"Type": "Afternoon Snack",
"Value1": null,
"Value2": null,
"Value3": null,
"Value4": null
}, {
"Address": null,
"Type": "Supper",
"Value1": null,
"Value2": null,
"Value3": null,
"Value4": null
}, {
"Address": null,
"Type": "Evening Snack",
"Value1": null,
"Value2": null,
"Value3": null,
"Value4": null
}
]
}
当我尝试断言这两个对象时出现问题,它失败了,因为数据库中的对象只有很少的元素作为数组,这意味着您可以在单个 json 对象中包含多个对象。 当我尝试从 UI 元素构造我的 Json 对象时,我无法构造元素数组。
请告知这样做是否正确。
我在 C# 中使用 selenium
感谢您的帮助。
通过从 UI 创建一个 Dictionary 对象然后在 Dictionary 对象中转换 json 对象找到解决方案。