신원형

improved test code

{
"env": {
"browser": true,
"es2021": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
}
}
......@@ -40,10 +40,10 @@ ex)
*/
export async function get_schedule(id, pw, target_date) {
return using_selenium((driver) => {
return login(driver, id, pw)
.then(() => {
return load(driver, target_date)
return await using_selenium( async (driver) => {
return await login(driver, id, pw)
.then(async () => {
return await load(driver, target_date)
.then((data) => {
//logout(driver)
console.log(data)
......@@ -99,7 +99,7 @@ export async function load(driver, until) {
export async function logout(driver) {
await driver.get("https://khcanvas.khu.ac.kr/")
const logoutPanel = await driver.findElement(selenium.By.xpath('html/body/div[2]/header[2]/div[1]/ul/li[1]/button/div[1]')).click();
await driver.findElement(selenium.By.xpath('html/body/div[2]/header[2]/div[1]/ul/li[1]/button/div[1]')).click();
await sleep(1000)
const logout = await driver.findElement(selenium.By.xpath('html/body/div[3]/span/span/div/div/div/div/div/span/form/button'));
logout.click()
......
This diff is collapsed. Click to expand it.
......@@ -14,12 +14,12 @@
"license": "",
"dependencies": {
"@types/selenium-webdriver": "^4.1.0",
"eslint": "^8.16.0",
"mocha": "^10.0.0",
"selenium-webdriver": "^4.1.2"
},
"type": "module",
"devDependencies": {
"@types/node": "^17.0.35"
"@types/node": "^17.0.35",
"eslint": "^8.16.0"
}
}
......
......@@ -2,14 +2,17 @@
//https://github.com/gatoona/AWS-Selenium
import * as canvas from '../khcanvas.js'
import * as rd from 'readline'
import { assert } from 'console';
import * as mocha from 'mocha'
import process from 'node:process';
import util from 'util'
import { rejects } from 'assert';
describe('khcanvas', () => {
it('opening selenium', () => {
//this.timeout(1000);
canvas.using_selenium(async (driver) => {
mocha.describe('khcanvas', () => {
mocha.it('opening selenium', async () => {
await canvas.using_selenium(async (driver) => {
await driver.get("http://khuhub.khu.ac.kr");
await driver.getTitle().then(function (title) {
await driver.getTitle().then( (title) => {
console.log(title);
});
});
......@@ -17,24 +20,23 @@ describe('khcanvas', () => {
});
describe('khcanvas', () => {
it('get schedule', async () => {
mocha.describe('khcanvas', () => {
mocha.it('get schedule', async () => {
const rl = rd.createInterface({
input: process.stdin,
output: process.stdout
})
rl.question('a', async (a) => {
rl.question('b', async (b) => {
await canvas.get_schedule(a, b, new Date())
.then(it => {
console.log(it)
})
.catch(it => {
console.log(it)
throw new Error();
})
const question = util.promisify(rl.question).bind(rl);
const a = await question('a');
const b = await question('b');
return await canvas.get_schedule(a, b, new Date())
.then(it => console.log(it))
.catch(it => {
console.log(it)
rejects(it)
})
})
})
});
\ No newline at end of file
......