blob: a71ebf49d8d4e45d90f61d285b8518a7038feddf [file] [log] [blame]
Marc Kupietz490b0532024-09-05 09:36:21 +02001const puppeteer = require('puppeteer-extra');
2puppeteer.use(require('puppeteer-extra-plugin-user-preferences')({
3 userPrefs: {
4 safebrowsing: {
5 enabled: false,
6 enhanced: false
7 }
8 }
9}));
Marc Kupietz55fc3162022-12-04 16:25:49 +010010const chai = require('chai');
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010011const { afterEach } = require('mocha');
12const { doesNotMatch } = require('assert');
Marc Kupietz4d335a32024-09-04 16:13:48 +020013const { log } = require('console');
Marc Kupietz55fc3162022-12-04 16:25:49 +010014const assert = chai.assert;
15const should = chai.should();
Marc Kupietz7f1666a2024-07-12 18:35:31 +020016var slack = null;
Marc Kupietz55fc3162022-12-04 16:25:49 +010017
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010018const KORAP_URL = process.env.KORAP_URL || "http://localhost:64543";
Marc Kupietz55fc3162022-12-04 16:25:49 +010019const KORAP_LOGIN = 'KORAP_LOGIN' in process.env ? process.env.KORAP_LOGIN : "user2"
Marc Kupietzc4077822022-12-03 15:32:40 +010020const KORAP_PWD = process.env.KORAP_PWD || "password2";
Marc Kupietz26982382022-12-04 19:02:57 +010021const KORAP_QUERIES = process.env.KORAP_QUERIES || 'geht, [orth=geht & cmc/pos=VVFIN]'
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010022const korap_rc = require('../lib/korap_rc.js').new(KORAP_URL)
23
Marc Kupietz7f1666a2024-07-12 18:35:31 +020024const slack_webhook = process.env.SLACK_WEBHOOK_URL;
Marc Kupietz4d335a32024-09-04 16:13:48 +020025
Marc Kupietz7f1666a2024-07-12 18:35:31 +020026if (slack_webhook) {
27 slack = require('slack-notify')(slack_webhook);
28}
29
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010030function ifConditionIt(title, condition, test) {
Marc Kupietz55fc3162022-12-04 16:25:49 +010031 return condition ? it(title, test) : it.skip(title + " (skipped)", test)
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010032}
Marc Kupietzc4077822022-12-03 15:32:40 +010033
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010034describe('Running KorAP UI end-to-end tests on ' + KORAP_URL, () => {
Marc Kupietzc4077822022-12-03 15:32:40 +010035
36 before(async () => {
Marc Kupietz69e02802023-11-08 14:37:22 +010037 browser = await puppeteer.launch({
38 headless: "new",
39 })
Marc Kupietzc4077822022-12-03 15:32:40 +010040 page = await browser.newPage()
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010041 await page.setViewport({
42 width: 1280,
43 height: 768,
44 deviceScaleFactor: 1,
45 });
Marc Kupietz4d335a32024-09-04 16:13:48 +020046 console.log("Browser version: " + await browser.version() + " started")
Marc Kupietzc4077822022-12-03 15:32:40 +010047 })
48
49 after(async () => {
50 await browser.close()
51 })
52
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010053 afterEach(async function () {
54 if (this.currentTest.state == "failed") {
Marc Kupietzf838f8b2022-12-04 19:02:57 +010055 await page.screenshot({path: "failed_" + this.currentTest.title.replaceAll(/[ &\/]/g, "_") + '.png'});
Marc Kupietz7f1666a2024-07-12 18:35:31 +020056 if (slack) {
57 slack.alert({
58 text: 'Test on ' + KORAP_URL + ' failed: ' + this.currentTest.title,
59 })
60 }
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010061 }
62 })
63
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010064 it('KorAP UI is up and running',
65 (async () => {
66 await await page.goto(KORAP_URL);
67 const query_field = await page.$("#q-field")
68 assert.isNotNull(query_field, "#q-field not found. Kalamar not running?");
Marc Kupietz55fc3162022-12-04 16:25:49 +010069 }))
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010070
71
72 ifConditionIt('Login into KorAP with incorrect credentials fails',
73 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010074 (async () => {
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010075 const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD + "*")
Marc Kupietzc4077822022-12-03 15:32:40 +010076 login_result.should.be.false
Marc Kupietz55fc3162022-12-04 16:25:49 +010077 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010078
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010079 ifConditionIt('Login into KorAP with correct credentials succeeds',
80 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010081 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010082 const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD)
Marc Kupietzc4077822022-12-03 15:32:40 +010083 login_result.should.be.true
Marc Kupietz55fc3162022-12-04 16:25:49 +010084 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010085
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010086 it('Can turn glimpse off',
Marc Kupietzc4077822022-12-03 15:32:40 +010087 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010088 await korap_rc.assure_glimpse_off(page)
Marc Kupietz55fc3162022-12-04 16:25:49 +010089 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010090
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010091 describe('Running searches that should have hits', () => {
Marc Kupietz55fc3162022-12-04 16:25:49 +010092
93 before(async () => { await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD) })
94
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010095 KORAP_QUERIES.split(/[;,] */).forEach((query, i) => {
96 it('Search for "' + query + '" has hits',
97 (async () => {
98 await korap_rc.assure_glimpse_off(page)
99 const hits = await korap_rc.search(page, query)
100 hits.should.be.above(0)
101 })).timeout(20000)
102 })
103 })
Marc Kupietz5a73a4d2022-12-04 14:09:58 +0100104
105 ifConditionIt('Logout works',
106 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +0100107 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +0100108 const logout_result = await korap_rc.logout(page)
Marc Kupietzc4077822022-12-03 15:32:40 +0100109 logout_result.should.be.true
Marc Kupietz55fc3162022-12-04 16:25:49 +0100110 }))
Marc Kupietzc4077822022-12-03 15:32:40 +0100111
Marc Kupietz55fc3162022-12-04 16:25:49 +0100112})