Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 1 | const puppeteer = require('puppeteer') |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 2 | const chai = require('chai'); |
Marc Kupietz | 4c5a7a5 | 2022-12-04 16:56:30 +0100 | [diff] [blame] | 3 | const { afterEach } = require('mocha'); |
| 4 | const { doesNotMatch } = require('assert'); |
Marc Kupietz | 4d335a3 | 2024-09-04 16:13:48 +0200 | [diff] [blame] | 5 | const { log } = require('console'); |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 6 | const assert = chai.assert; |
| 7 | const should = chai.should(); |
Marc Kupietz | 7f1666a | 2024-07-12 18:35:31 +0200 | [diff] [blame] | 8 | var slack = null; |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 9 | |
Marc Kupietz | 0f6c54d | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 10 | const KORAP_URL = process.env.KORAP_URL || "http://localhost:64543"; |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 11 | const KORAP_LOGIN = 'KORAP_LOGIN' in process.env ? process.env.KORAP_LOGIN : "user2" |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 12 | const KORAP_PWD = process.env.KORAP_PWD || "password2"; |
Marc Kupietz | 2698238 | 2022-12-04 19:02:57 +0100 | [diff] [blame] | 13 | const KORAP_QUERIES = process.env.KORAP_QUERIES || 'geht, [orth=geht & cmc/pos=VVFIN]' |
Marc Kupietz | 5a73a4d | 2022-12-04 14:09:58 +0100 | [diff] [blame] | 14 | const korap_rc = require('../lib/korap_rc.js').new(KORAP_URL) |
| 15 | |
Marc Kupietz | 7f1666a | 2024-07-12 18:35:31 +0200 | [diff] [blame] | 16 | const slack_webhook = process.env.SLACK_WEBHOOK_URL; |
Marc Kupietz | 4d335a3 | 2024-09-04 16:13:48 +0200 | [diff] [blame] | 17 | |
Marc Kupietz | 7f1666a | 2024-07-12 18:35:31 +0200 | [diff] [blame] | 18 | if (slack_webhook) { |
| 19 | slack = require('slack-notify')(slack_webhook); |
| 20 | } |
| 21 | |
Marc Kupietz | 5a73a4d | 2022-12-04 14:09:58 +0100 | [diff] [blame] | 22 | function ifConditionIt(title, condition, test) { |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 23 | return condition ? it(title, test) : it.skip(title + " (skipped)", test) |
Marc Kupietz | 5a73a4d | 2022-12-04 14:09:58 +0100 | [diff] [blame] | 24 | } |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 25 | |
Marc Kupietz | 0f6c54d | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 26 | describe('Running KorAP UI end-to-end tests on ' + KORAP_URL, () => { |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 27 | |
| 28 | before(async () => { |
Marc Kupietz | 69e0280 | 2023-11-08 14:37:22 +0100 | [diff] [blame] | 29 | browser = await puppeteer.launch({ |
| 30 | headless: "new", |
| 31 | }) |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 32 | page = await browser.newPage() |
Marc Kupietz | 4c5a7a5 | 2022-12-04 16:56:30 +0100 | [diff] [blame] | 33 | await page.setViewport({ |
| 34 | width: 1280, |
| 35 | height: 768, |
| 36 | deviceScaleFactor: 1, |
| 37 | }); |
Marc Kupietz | 4d335a3 | 2024-09-04 16:13:48 +0200 | [diff] [blame] | 38 | console.log("Browser version: " + await browser.version() + " started") |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 39 | }) |
| 40 | |
| 41 | after(async () => { |
| 42 | await browser.close() |
| 43 | }) |
| 44 | |
Marc Kupietz | 4c5a7a5 | 2022-12-04 16:56:30 +0100 | [diff] [blame] | 45 | afterEach(async function () { |
| 46 | if (this.currentTest.state == "failed") { |
Marc Kupietz | f838f8b | 2022-12-04 19:02:57 +0100 | [diff] [blame] | 47 | await page.screenshot({path: "failed_" + this.currentTest.title.replaceAll(/[ &\/]/g, "_") + '.png'}); |
Marc Kupietz | 7f1666a | 2024-07-12 18:35:31 +0200 | [diff] [blame] | 48 | if (slack) { |
| 49 | slack.alert({ |
| 50 | text: 'Test on ' + KORAP_URL + ' failed: ' + this.currentTest.title, |
| 51 | }) |
| 52 | } |
Marc Kupietz | 4c5a7a5 | 2022-12-04 16:56:30 +0100 | [diff] [blame] | 53 | } |
| 54 | }) |
| 55 | |
Marc Kupietz | 5a73a4d | 2022-12-04 14:09:58 +0100 | [diff] [blame] | 56 | it('KorAP UI is up and running', |
| 57 | (async () => { |
| 58 | await await page.goto(KORAP_URL); |
| 59 | const query_field = await page.$("#q-field") |
| 60 | assert.isNotNull(query_field, "#q-field not found. Kalamar not running?"); |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 61 | })) |
Marc Kupietz | 5a73a4d | 2022-12-04 14:09:58 +0100 | [diff] [blame] | 62 | |
| 63 | |
| 64 | ifConditionIt('Login into KorAP with incorrect credentials fails', |
| 65 | KORAP_LOGIN != "", |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 66 | (async () => { |
Marc Kupietz | 0f6c54d | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 67 | const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD + "*") |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 68 | login_result.should.be.false |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 69 | })) |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 70 | |
Marc Kupietz | 5a73a4d | 2022-12-04 14:09:58 +0100 | [diff] [blame] | 71 | ifConditionIt('Login into KorAP with correct credentials succeeds', |
| 72 | KORAP_LOGIN != "", |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 73 | (async () => { |
Marc Kupietz | 5e45a2f | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 74 | const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD) |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 75 | login_result.should.be.true |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 76 | })) |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 77 | |
Marc Kupietz | 0f6c54d | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 78 | it('Can turn glimpse off', |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 79 | (async () => { |
Marc Kupietz | 5e45a2f | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 80 | await korap_rc.assure_glimpse_off(page) |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 81 | })) |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 82 | |
Marc Kupietz | 0f6c54d | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 83 | describe('Running searches that should have hits', () => { |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 84 | |
| 85 | before(async () => { await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD) }) |
| 86 | |
Marc Kupietz | 0f6c54d | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 87 | KORAP_QUERIES.split(/[;,] */).forEach((query, i) => { |
| 88 | it('Search for "' + query + '" has hits', |
| 89 | (async () => { |
| 90 | await korap_rc.assure_glimpse_off(page) |
| 91 | const hits = await korap_rc.search(page, query) |
| 92 | hits.should.be.above(0) |
| 93 | })).timeout(20000) |
| 94 | }) |
| 95 | }) |
Marc Kupietz | 5a73a4d | 2022-12-04 14:09:58 +0100 | [diff] [blame] | 96 | |
| 97 | ifConditionIt('Logout works', |
| 98 | KORAP_LOGIN != "", |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 99 | (async () => { |
Marc Kupietz | 5e45a2f | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 100 | const logout_result = await korap_rc.logout(page) |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 101 | logout_result.should.be.true |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 102 | })) |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 103 | |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 104 | }) |