신원형

improved test code

1 +{
2 + "env": {
3 + "browser": true,
4 + "es2021": true
5 + },
6 + "extends": "eslint:recommended",
7 + "parserOptions": {
8 + "ecmaVersion": "latest",
9 + "sourceType": "module"
10 + },
11 + "rules": {
12 + }
13 +}
...@@ -40,10 +40,10 @@ ex) ...@@ -40,10 +40,10 @@ ex)
40 */ 40 */
41 41
42 export async function get_schedule(id, pw, target_date) { 42 export async function get_schedule(id, pw, target_date) {
43 - return using_selenium((driver) => { 43 + return await using_selenium( async (driver) => {
44 - return login(driver, id, pw) 44 + return await login(driver, id, pw)
45 - .then(() => { 45 + .then(async () => {
46 - return load(driver, target_date) 46 + return await load(driver, target_date)
47 .then((data) => { 47 .then((data) => {
48 //logout(driver) 48 //logout(driver)
49 console.log(data) 49 console.log(data)
...@@ -99,7 +99,7 @@ export async function load(driver, until) { ...@@ -99,7 +99,7 @@ export async function load(driver, until) {
99 export async function logout(driver) { 99 export async function logout(driver) {
100 await driver.get("https://khcanvas.khu.ac.kr/") 100 await driver.get("https://khcanvas.khu.ac.kr/")
101 101
102 - const logoutPanel = await driver.findElement(selenium.By.xpath('html/body/div[2]/header[2]/div[1]/ul/li[1]/button/div[1]')).click(); 102 + await driver.findElement(selenium.By.xpath('html/body/div[2]/header[2]/div[1]/ul/li[1]/button/div[1]')).click();
103 await sleep(1000) 103 await sleep(1000)
104 const logout = await driver.findElement(selenium.By.xpath('html/body/div[3]/span/span/div/div/div/div/div/span/form/button')); 104 const logout = await driver.findElement(selenium.By.xpath('html/body/div[3]/span/span/div/div/div/div/div/span/form/button'));
105 logout.click() 105 logout.click()
......
This diff is collapsed. Click to expand it.
...@@ -14,12 +14,12 @@ ...@@ -14,12 +14,12 @@
14 "license": "", 14 "license": "",
15 "dependencies": { 15 "dependencies": {
16 "@types/selenium-webdriver": "^4.1.0", 16 "@types/selenium-webdriver": "^4.1.0",
17 - "eslint": "^8.16.0",
18 "mocha": "^10.0.0", 17 "mocha": "^10.0.0",
19 "selenium-webdriver": "^4.1.2" 18 "selenium-webdriver": "^4.1.2"
20 }, 19 },
21 "type": "module", 20 "type": "module",
22 "devDependencies": { 21 "devDependencies": {
23 - "@types/node": "^17.0.35" 22 + "@types/node": "^17.0.35",
23 + "eslint": "^8.16.0"
24 } 24 }
25 } 25 }
......
...@@ -2,14 +2,17 @@ ...@@ -2,14 +2,17 @@
2 //https://github.com/gatoona/AWS-Selenium 2 //https://github.com/gatoona/AWS-Selenium
3 import * as canvas from '../khcanvas.js' 3 import * as canvas from '../khcanvas.js'
4 import * as rd from 'readline' 4 import * as rd from 'readline'
5 -import { assert } from 'console'; 5 +import * as mocha from 'mocha'
6 +import process from 'node:process';
7 +import util from 'util'
8 +import { rejects } from 'assert';
6 9
7 -describe('khcanvas', () => { 10 +
8 - it('opening selenium', () => { 11 +mocha.describe('khcanvas', () => {
9 - //this.timeout(1000); 12 + mocha.it('opening selenium', async () => {
10 - canvas.using_selenium(async (driver) => { 13 + await canvas.using_selenium(async (driver) => {
11 await driver.get("http://khuhub.khu.ac.kr"); 14 await driver.get("http://khuhub.khu.ac.kr");
12 - await driver.getTitle().then(function (title) { 15 + await driver.getTitle().then( (title) => {
13 console.log(title); 16 console.log(title);
14 }); 17 });
15 }); 18 });
...@@ -17,24 +20,23 @@ describe('khcanvas', () => { ...@@ -17,24 +20,23 @@ describe('khcanvas', () => {
17 }); 20 });
18 21
19 22
20 -describe('khcanvas', () => { 23 +mocha.describe('khcanvas', () => {
21 - it('get schedule', async () => { 24 + mocha.it('get schedule', async () => {
22 const rl = rd.createInterface({ 25 const rl = rd.createInterface({
23 input: process.stdin, 26 input: process.stdin,
24 output: process.stdout 27 output: process.stdout
25 }) 28 })
26 29
27 - rl.question('a', async (a) => { 30 + const question = util.promisify(rl.question).bind(rl);
28 - rl.question('b', async (b) => { 31 +
29 - await canvas.get_schedule(a, b, new Date()) 32 + const a = await question('a');
30 - .then(it => { 33 + const b = await question('b');
31 - console.log(it) 34 +
32 - }) 35 + return await canvas.get_schedule(a, b, new Date())
36 + .then(it => console.log(it))
33 .catch(it => { 37 .catch(it => {
34 console.log(it) 38 console.log(it)
35 - throw new Error(); 39 + rejects(it)
36 - })
37 - })
38 }) 40 })
39 }) 41 })
40 }); 42 });
...\ No newline at end of file ...\ No newline at end of file
......