我正在尝试创建一个将评估标记输入系统的工具。我目前可以使用它,但是代码非常重复。我有一个带有学生分数的 JSON 文件。然后我遍历数据的长度并将值输入到相应的输入中。完成后,我提交并进入下一个评估。我怎样才能减少重复的数量?
const data = require('data.json')
module.exports = {
'@tags': ['Assessment'],
'Enter data for each page'(browser) {
const courseActionLink =
'#DataModel_DataLinks_YourAssessments__Data_1__Items_READYTOMARK__Value'
const submitBtn = '[aria-label="Submit Results"]'
const nextAssessmentBtn = '[aria-label="Next Assessment"]'
const alertBtn = '#alert-close'
for (let d = 0; d < data.length; d++) {
// Mark Assessment Results
const personCode = `#DataModel_DataLinks_LearnerAssessments__Data_${d}__Items_RESULT_MARKSOUTOF__Value`
browser
.clearValue(personCode)
.setValue(personCode, data[d].a1total)
.pause(5000)
}
browser
.click(submitBtn)
.pause(5000)
.click(alertBtn)
.pause(5000)
.click(nextAssessmentBtn)
.pause(5000)
for (let d = 0; d < data.length; d++) {
// Mark Assessment Results
const personCode = `#DataModel_DataLinks_LearnerAssessments__Data_${d}__Items_RESULT_MARKSOUTOF__Value`
browser
.clearValue(personCode)
.setValue(personCode, data[d].sbatotal)
.pause(5000)
}
browser
.click(submitBtn)
.pause(5000)
.click(alertBtn)
.pause(5000)
.click(nextAssessmentBtn)
.pause(5000)
for (let d = 0; d < data.length; d++) {
// Mark Assessment Results
const personCode = `#DataModel_DataLinks_LearnerAssessments__Data_${d}__Items_RESULT_MARKSOUTOF__Value`
browser
.clearValue(personCode)
.setValue(personCode, data[d].practicalstotal)
.pause(5000)
}
browser
.click(submitBtn)
.pause(5000)
.click(alertBtn)
.pause(5000)
.click(nextAssessmentBtn)
.pause(5000)
for (let d = 0; d < data.length; d++) {
// Mark Assessment Results
const personCode = `#DataModel_DataLinks_LearnerAssessments__Data_${d}__Items_RESULT_MARKSOUTOF__Value`
browser
.clearValue(personCode)
.setValue(personCode, data[d].a2total)
.pause(5000)
}
browser
.click(submitBtn)
.pause(5000)
.click(alertBtn)
.pause(5000)
}
}