声明一个Json对象

时间:2018-10-15 21:12:26

标签: json selenium assert assertion

我有一个应用程序,其中有一个表单,其中包含所有控件,例如(文本框,下拉列表,列表,文本区域,复选框,表格) 并且所有数据在保存时都保存为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#中使用硒

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

通过从UI创建一个Dictionary对象,然后在Dictionary对象中转换json对象,找到了解决方案。