Skip to content

Commit 0213512

Browse files
committed
feat: add template for judging question automatically
1 parent 4aa8ea9 commit 0213512

File tree

6 files changed

+262
-0
lines changed

6 files changed

+262
-0
lines changed

templates/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# 题目验证模板文件
2+
3+
测试题目: https://shimo.im/docs/VMAPVmDZK6c19Mqg/ 《小程序部分验收题目》,可复制链接后用石墨文档 App 或小程序打开
4+
5+
question1.ejs question2.ejs 分别对应其中的题目 1 2
6+
7+
> ejs 需要更改为 js 文件才能运行,将 ejs 中的 `projectPath``questionPage``studentInfo` 替换为有效的 JS 变量或删除

templates/question1.ejs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const automator = require('miniprogram-automator')
2+
3+
const projectPath = '<%= projectPath %>'
4+
const questionPage = '<%= questionPage %>'
5+
const studentInfo = '<%= studentInfo %>'
6+
7+
let openMp = true
8+
9+
describe(`${studentInfo}-${questionPage}-${projectPath}`, () => {
10+
let miniProgram
11+
12+
beforeAll(async () => {
13+
try {
14+
miniProgram = await automator.launch({
15+
cliPath: 'D:\\Software\\wechat_devtools\\Installation\\微信web开发者工具\\cli.bat',
16+
projectPath
17+
})
18+
} catch (err) {
19+
openMp = false
20+
}
21+
}, 300000)
22+
23+
afterAll(async () => {
24+
await miniProgram.close()
25+
})
26+
27+
it('乘法测试', async () => {
28+
expect(openMp).toBe(true) // 验证是否能正常导入项目,即是该小程序开发者
29+
30+
const page = await miniProgram.reLaunch(questionPage)
31+
await page.waitFor(500)
32+
33+
const input1 = await page.$('#input1')
34+
const input2 = await page.$('#input2')
35+
const submit = await page.$('#submit')
36+
37+
await page.waitFor(500)
38+
39+
await input1.input(1)
40+
await input2.input(2)
41+
await submit.tap()
42+
await page.waitFor(500)
43+
let result = await page.$('#result')
44+
45+
expect(Number(await result.text())).toBe(2)
46+
47+
await input1.input(5)
48+
await input2.input(5)
49+
await submit.tap()
50+
await page.waitFor(500)
51+
result = await page.$('#result')
52+
53+
expect(Number(await result.text())).toBe(25)
54+
}, 120000)
55+
})

templates/question2.ejs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const automator = require('miniprogram-automator')
2+
3+
const projectPath = '<%= projectPath %>'
4+
const questionPage = '<%= questionPage %>'
5+
const studentInfo = '<%= studentInfo %>'
6+
7+
let openMp = true
8+
9+
describe(`${studentInfo}-${questionPage}-${projectPath}`, () => {
10+
let miniProgram
11+
12+
beforeAll(async () => {
13+
try {
14+
miniProgram = await automator.launch({
15+
cliPath: 'D:\\Software\\wechat_devtools\\Installation\\微信web开发者工具\\cli.bat',
16+
projectPath
17+
})
18+
} catch (err) {
19+
openMp = false
20+
}
21+
}, 300000)
22+
23+
afterAll(async () => {
24+
await miniProgram.close()
25+
})
26+
27+
it('字符串截取:长度小于3', async () => {
28+
expect(openMp).toBe(true) // 验证是否能正常导入项目,即是该小程序开发者
29+
30+
const page = await miniProgram.reLaunch(questionPage)
31+
await page.waitFor(500)
32+
33+
const input1 = await page.$('#input1')
34+
await input1.input("1")
35+
await page.waitFor(500)
36+
const result = await page.$('#result')
37+
38+
expect(await result.text()).toBe('1')
39+
}, 120000)
40+
41+
it('字符串截取:长度大于3', async () => {
42+
expect(openMp).toBe(true) // 验证是否能正常导入项目,即是该小程序开发者
43+
44+
const page = await miniProgram.reLaunch(questionPage)
45+
await page.waitFor(500)
46+
47+
const input1 = await page.$('#input1')
48+
await input1.input("11111111111")
49+
await page.waitFor(500)
50+
const result = await page.$('#result')
51+
52+
expect(await result.text()).toBe('111')
53+
}, 120000)
54+
})

templates/question3.ejs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const automator = require('miniprogram-automator')
2+
3+
const projectPath = '<%= projectPath %>'
4+
const questionPage = '<%= questionPage %>'
5+
const studentInfo = '<%= studentInfo %>'
6+
7+
let openMp = true
8+
9+
describe(`${studentInfo}-${questionPage}-${projectPath}`, () => {
10+
let miniProgram
11+
12+
beforeAll(async () => {
13+
try {
14+
miniProgram = await automator.launch({
15+
cliPath: 'D:\\Software\\wechat_devtools\\Installation\\微信web开发者工具\\cli.bat',
16+
projectPath
17+
})
18+
} catch (err) {
19+
openMp = false
20+
}
21+
}, 300000)
22+
23+
afterAll(async () => {
24+
await miniProgram.close()
25+
})
26+
27+
it('bupt 循环3次', async () => {
28+
expect(openMp).toBe(true) // 验证是否能正常导入项目,即是该小程序开发者
29+
30+
const page = await miniProgram.reLaunch(questionPage)
31+
await page.waitFor(500)
32+
33+
const input1 = await page.$('#input1')
34+
await input1.input("3")
35+
await page.waitFor(500)
36+
37+
const list = await page.$$('#result')
38+
39+
expect(await list.length).toBe(3)
40+
}, 120000)
41+
})

templates/question4.ejs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const automator = require('miniprogram-automator')
2+
3+
const projectPath = '<%= projectPath %>'
4+
const questionPage = '<%= questionPage %>'
5+
const studentInfo = '<%= studentInfo %>'
6+
7+
let openMp = true
8+
9+
describe(`${studentInfo}-${questionPage}-${projectPath}`, () => {
10+
let miniProgram
11+
12+
beforeAll(async () => {
13+
try {
14+
miniProgram = await automator.launch({
15+
cliPath: 'D:\\Software\\wechat_devtools\\Installation\\微信web开发者工具\\cli.bat',
16+
projectPath
17+
})
18+
} catch (err) {
19+
openMp = false
20+
}
21+
}, 300000)
22+
23+
afterAll(async () => {
24+
await miniProgram.close()
25+
})
26+
27+
it('默认值为3,并可进行加减', async () => {
28+
expect(openMp).toBe(true) // 验证是否能正常导入项目,即是该小程序开发者
29+
30+
const page = await miniProgram.reLaunch(questionPage)
31+
await page.waitFor(500)
32+
33+
const plus = await page.$('#plus')
34+
const minus = await page.$('#minus')
35+
let list = await page.$$('#result')
36+
37+
expect(await list.length).toBe(3)
38+
39+
await plus.tap()
40+
await page.waitFor(500)
41+
list = await page.$$('#result')
42+
43+
expect(await list.length).toBe(4)
44+
45+
await minus.tap()
46+
await page.waitFor(500)
47+
list = await page.$$('#result')
48+
49+
expect(await list.length).toBe(3)
50+
}, 120000)
51+
})

templates/question5.ejs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const automator = require('miniprogram-automator')
2+
3+
const projectPath = '<%= projectPath %>'
4+
const questionPage = '<%= questionPage %>'
5+
const studentInfo = '<%= studentInfo %>'
6+
7+
let openMp = true
8+
9+
describe(`${studentInfo}-${questionPage}-${projectPath}`, () => {
10+
let miniProgram
11+
12+
beforeAll(async () => {
13+
try {
14+
miniProgram = await automator.launch({
15+
cliPath: 'D:\\Software\\wechat_devtools\\Installation\\微信web开发者工具\\cli.bat',
16+
projectPath
17+
})
18+
} catch (err) {
19+
openMp = false
20+
}
21+
}, 300000)
22+
23+
afterAll(async () => {
24+
await miniProgram.close()
25+
})
26+
27+
it('bupt 前缀', async () => {
28+
expect(openMp).toBe(true) // 验证是否能正常导入项目,即是该小程序开发者
29+
30+
const page = await miniProgram.reLaunch(questionPage)
31+
await page.waitFor(500)
32+
33+
const input1 = await page.$('#input1')
34+
await input1.input('bupttest')
35+
await page.waitFor(500)
36+
const result = await page.$('#result')
37+
38+
expect(await result.text()).toBe('success')
39+
}, 120000)
40+
41+
it('非 bupt 前缀', async () => {
42+
expect(openMp).toBe(true) // 验证是否能正常导入项目,即是该小程序开发者
43+
44+
const page = await miniProgram.reLaunch(questionPage)
45+
await page.waitFor(500)
46+
47+
const input1 = await page.$('#input1')
48+
await input1.input('testbupt')
49+
await page.waitFor(500)
50+
const result = await page.$('#result')
51+
52+
expect(await result.text()).toBe('failure')
53+
}, 120000)
54+
})

0 commit comments

Comments
 (0)