An automatic script to update test groups in Polygon automatically

Правка en6, от .o., 2024-02-09 10:32:21

While preparing problems with subtasks using Polygon, it's super annoying that we cannot set test groups using test scripts.

As a workaround, I wrote a simple script.

Test group of each test = the last token of the test generation command


function setPolygonTestGroupAutomatically() { const mapping = {}; $("#testsTable tbody tr code") .each((idx_minus_one, v) => { const tokens = v.innerText.split(" "); // Test generation command const testGroup = tokens[tokens.length - 1]; // Last token of the test generation command if (!mapping[testGroup]) { mapping[testGroup] = []; } mapping[testGroup].push(idx_minus_one + 1); }); const keyToIndices = Object.entries(mapping); function go (idx) { if (idx == keyToIndices.length) { console.log("Changed everything!"); return; } const [groupName, indices] = keyToIndices[idx]; $.post("/data/tests", { action: "setMultipleTestGroup", session: $('#session').text(), testset: Object.fromEntries(new URLSearchParams($("#add-test").attr('href')))['testset'], requestString: indices.map(idx => `testIndex=${idx}`).join('&'), groupName, ccid: $('meta[name="ccid"]').attr('content') }).error((err) => console.error(err)) .then((data) => { console.log(`Done`, groupName, indices, data); setTimeout(go, 1000, idx+1); }); } go(0); } setPolygonTestGroupAutomatically();

Paste the script above to the developer console on the tests page.

UPD: Added 1-second delay between each API call. It seems if we call the API multiple times simultaneously, Polygon will automatically change the dollars of the test script into non-consecutive numbers, making the whole working copy inaccessible.

Теги polygon

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en7 Английский .o. 2024-02-09 10:36:02 166 fix: has more error
en6 Английский .o. 2024-02-09 10:32:21 123 mitigate polygon's testtable change
en5 Английский .o. 2020-11-05 18:39:16 17 Tiny change: 'rything!")\n }\n ' -> 'rything!"); \n return;\n }\n '
en4 Английский .o. 2020-11-05 18:38:27 10
en3 Английский .o. 2020-11-05 18:37:09 517
en2 Английский .o. 2020-11-01 17:50:43 7
en1 Английский .o. 2020-11-01 17:49:12 1759 Initial revision (published)