Last active
October 26, 2020 08:28
-
-
Save zzNuAzz/e808b20ebe3dcaf3c4324f0f938dc4a1 to your computer and use it in GitHub Desktop.
kiểm thử tool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function get() { | |
return new Promise((resolve, reject) => { | |
fetch('https://gist.githubusercontent.com/zzNuAzz/645bc20f12d7a04bd593bc14fc01be42/raw/e4ad40db0d6c1dac9315588f92699e17c2e0e7c4/kiemthu.json') // Call the fetch function passing the url of the API as a parameter | |
.then(data => data.json()) | |
.then(data => resolve(data)) | |
.catch(() => reject()); | |
}); | |
} | |
function sleep(ms) { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => resolve(), ms); | |
}); | |
} | |
let db = null; | |
let selectorCheck = [ | |
'#main-app > question > div > div.main.main-open > div > app-list-question > div:nth-child(1) > div.container > practice-question > div > div > div.card-body.practice-scroll > div.content > div > div > div > div:nth-child(1) > div.select-check', | |
'#main-app > question > div > div.main.main-open > div > app-list-question > div:nth-child(1) > div.container > practice-question > div > div > div.card-body.practice-scroll > div.content > div > div > div > div:nth-child(2) > div.select-check', | |
'#main-app > question > div > div.main.main-open > div > app-list-question > div:nth-child(1) > div.container > practice-question > div > div > div.card-body.practice-scroll > div.content > div > div > div > div:nth-child(3) > div.select-check', | |
'#main-app > question > div > div.main.main-open > div > app-list-question > div:nth-child(1) > div.container > practice-question > div > div > div.card-body.practice-scroll > div.content > div > div > div > div:nth-child(4) > div.select-check', | |
]; | |
let selectorText = [ | |
'#main-app > question > div > div.main.main-open > div > app-list-question > div:nth-child(1) > div.container > practice-question > div > div > div.card-body.practice-scroll > div.content > div > div > div > div:nth-child(1) > div.text-wrap.answer', | |
'#main-app > question > div > div.main.main-open > div > app-list-question > div:nth-child(1) > div.container > practice-question > div > div > div.card-body.practice-scroll > div.content > div > div > div > div:nth-child(2) > div.text-wrap.answer', | |
'#main-app > question > div > div.main.main-open > div > app-list-question > div:nth-child(1) > div.container > practice-question > div > div > div.card-body.practice-scroll > div.content > div > div > div > div:nth-child(3) > div.text-wrap.answer', | |
'#main-app > question > div > div.main.main-open > div > app-list-question > div:nth-child(1) > div.container > practice-question > div > div > div.card-body.practice-scroll > div.content > div > div > div > div:nth-child(4) > div.text-wrap.answer', | |
]; | |
let btn = | |
'#main-app > question > div > div.main.main-open > div > app-list-question > div:nth-child(1) > div.container > practice-question > div > div > div.card-footer.d-flex > div.m-auto > button.btn.btn-outline-warning'; | |
let next = | |
'#main-app > question > div > div.main.main-open > div > app-list-question > div:nth-child(1) > div.container > practice-question > div > div > div.card-footer.d-flex > div:nth-child(4) > button.btn.btn-outline-secondary.position-relative.border-0'; | |
let txtfield = | |
'#main-app > question > div > div.main.main-open > div > app-list-question > div:nth-child(1) > div.container > practice-question > div > div > div.card-body.practice-scroll > div.content > div > div > span > div'; | |
let multiple_question = | |
'#main-app > question > div > div.main.main-open > div > app-list-question > div:nth-child(1) > div.container > practice-question > div > div > div.card-header > div'; | |
let fill_question = | |
'#main-app > question > div > div.main.main-open > div > app-list-question > div:nth-child(1) > div.container > practice-question > div > div > div.card-body.practice-scroll > div.content > div'; | |
let fill_box = | |
'#main-app > question > div > div.main.main-open > div > app-list-question > div:nth-child(1) > div.container > practice-question > div > div > div.card-body.practice-scroll > div.content > div > div > span > div'; | |
async function fill() { | |
if (db === null) { | |
db = await get(); | |
} | |
let writes = $('.write-square'); | |
let multiple = true; | |
if (writes.length > 0) { | |
multiple = false; | |
} | |
if (multiple) { | |
let qtext = $(multiple_question); | |
const text = qtext.text(); | |
console.log(text); | |
const q = db.find(element => { | |
if (element.question === null) return false; | |
return element.question.replace(/[\"]/g, '') === text; | |
}); | |
let right = -1; | |
console.log(q); | |
if (!q) { | |
$(next).click(); | |
return null; | |
} | |
selectorText.forEach((selector, id) => { | |
const txt = $(selector).text(); | |
if (txt === q.right) { | |
right = id; | |
} | |
}); | |
if (right !== -1) { | |
$(selectorCheck[right]).click(); | |
await sleep(1000); | |
$(btn).click(); | |
} | |
await sleep(3000); | |
$(next).click(); | |
} else { | |
// let qtext = $(fill_question).html().split(/<.*>/); | |
// const regex = new RegExp(qtext.join('{{.*}}')); | |
// const q = db.find(element => { | |
// if (element.question === null) return false; | |
// return regex.test(element.question.replace(/[\"]/g, '')); | |
// }); | |
// if (!q) return; | |
// to_fill = q.question | |
// .match(/{{.*}}/)[0] | |
// .replace(/{{/, '') | |
// .replace(/}}/, ''); | |
// $(fill_box).text(to_fill); | |
await sleep(3000); | |
$(next).click(); | |
} | |
} | |
let task = 0; | |
let s = false; | |
let NUMBER_LOOP = 0; | |
async function run() { | |
for (let i = 0; i < NUMBER_LOOP; i++) { | |
if (s) return; | |
await fill(); | |
await sleep(3000); | |
} | |
return task; | |
} | |
NUMBER_LOOP = 10; | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment