嘿,伙计们,我需要你们的帮助。我在柏树公司工作,我想在每次选择之后自动完成并验证一个下拉列表,现在我正在为它使用一个数组
var report= [ "Alarm","Alarm Trends","Analytics","Asset","Audit",
"Cross Sectional Benchmarking","Degree Days",
"Longitudinal Benchmarking"
]; //this array但是,我想直接加载一个.json文件,其中包含从夹具到给定数组的值数组,名为report,然后是iterate.PS:我确实尝试了,但是它给了我一个引用错误,它阻止了代码:
describe('Test Scenario DatePickers and Dropdowns', () => {
before(function() {
cy
.get('#addReportButton')
.click()
cy
.fixture('report_types').as('report')
})
it('Report Type dropdown is working', function() {
var report= ["Alarm","Alarm Trends","Analytics","Asset","Audit",
"Cross Sectional Benchmarking","Degree Days","Longitudinal Benchmarking"
];
var report_length=report.length;
cy
.log("Pre condition: Should have Alarm as a default value")
cy
.get('#selectReportType')
.should('have.value', 'Alarm');
for (let index = 0; index < report_length; index++) {
const element = report[index];
cy
.get('#selectReportType')
.select(element)
.should('contain.text',element)
}
});
});JSON文件:
[
{
"reportname":["Alarm","Alarm Trends","Analytics"]
}
]请帮帮我
发布于 2022-11-21 07:47:39
可以用json文件中的值替换硬编码的值,如下所示:
it('Report Type dropdown is working', () => {
cy.fixture('AllesReportType.json').then((data) => {
const reportTypes = data[0].reportname;
reportTypes.forEach((reportType) => {
cy.get('#selectReportType')
.select(reportType)
.should('contain.text', reportType)
})
})https://stackoverflow.com/questions/74515360
复制相似问题