blob: 708d0120f149cff5206fcfc5c26637712b3c9aff [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');
Marc Kupietz55fc3162022-12-04 16:25:49 +010012const assert = chai.assert;
13const should = chai.should();
Marc Kupietz7f1666a2024-07-12 18:35:31 +020014var slack = null;
Marc Kupietz55fc3162022-12-04 16:25:49 +010015
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010016const KORAP_URL = process.env.KORAP_URL || "http://localhost:64543";
Marc Kupietzbfb23012025-06-03 15:47:10 +020017const KORAP_LOGIN = 'KORAP_USERNAME' in process.env ? process.env.KORAP_USERNAME : 'KORAP_LOGIN' in process.env ? process.env.KORAP_LOGIN : "user2"
18const KORAP_PWD = process.env.KORAP_PWD || process.env.KORAP_PASSWORD || "password2";
Marc Kupietz26982382022-12-04 19:02:57 +010019const KORAP_QUERIES = process.env.KORAP_QUERIES || 'geht, [orth=geht & cmc/pos=VVFIN]'
Marc Kupietzc8ffb2b2025-06-12 16:44:23 +020020const KORAP_MIN_TOKENS_IN_CORPUS = parseInt(process.env.KORAP_MIN_TOKENS_IN_CORPUS || "100000", 10);
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010021const korap_rc = require('../lib/korap_rc.js').new(KORAP_URL)
22
Marc Kupietz7f1666a2024-07-12 18:35:31 +020023const slack_webhook = process.env.SLACK_WEBHOOK_URL;
Marc Kupietz4d335a32024-09-04 16:13:48 +020024
Marc Kupietz7f1666a2024-07-12 18:35:31 +020025if (slack_webhook) {
26 slack = require('slack-notify')(slack_webhook);
27}
28
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010029function ifConditionIt(title, condition, test) {
Marc Kupietz55fc3162022-12-04 16:25:49 +010030 return condition ? it(title, test) : it.skip(title + " (skipped)", test)
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010031}
Marc Kupietzc4077822022-12-03 15:32:40 +010032
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010033describe('Running KorAP UI end-to-end tests on ' + KORAP_URL, () => {
Marc Kupietzc4077822022-12-03 15:32:40 +010034
35 before(async () => {
Marc Kupietz69e02802023-11-08 14:37:22 +010036 browser = await puppeteer.launch({
Marc Kupietzbfb23012025-06-03 15:47:10 +020037 headless: "shell",
38 args: [
39 '--no-sandbox',
40 '--disable-setuid-sandbox',
41 '--disable-dev-shm-usage',
42 '--disable-accelerated-2d-canvas',
43 '--no-first-run',
44 '--no-zygote',
45 '--disable-gpu'
46 ]
Marc Kupietz69e02802023-11-08 14:37:22 +010047 })
Marc Kupietzc4077822022-12-03 15:32:40 +010048 page = await browser.newPage()
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010049 await page.setViewport({
Marc Kupietz9e0f5192025-03-09 12:12:16 +010050 width: 1980,
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010051 height: 768,
52 deviceScaleFactor: 1,
Marc Kupietz964e7772025-06-03 15:02:30 +020053 });
Marc Kupietz4d335a32024-09-04 16:13:48 +020054 console.log("Browser version: " + await browser.version() + " started")
Marc Kupietzc4077822022-12-03 15:32:40 +010055 })
56
57 after(async () => {
58 await browser.close()
59 })
60
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010061 afterEach(async function () {
62 if (this.currentTest.state == "failed") {
Marc Kupietz964e7772025-06-03 15:02:30 +020063 await page.screenshot({ path: "failed_" + this.currentTest.title.replaceAll(/[ &\/]/g, "_") + '.png' });
Marc Kupietz7f1666a2024-07-12 18:35:31 +020064 if (slack) {
65 slack.alert({
66 text: 'Test on ' + KORAP_URL + ' failed: ' + this.currentTest.title,
67 })
68 }
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010069 }
Marc Kupietz964e7772025-06-03 15:02:30 +020070 })
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010071
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010072 it('KorAP UI is up and running',
73 (async () => {
Marc Kupietz9e0f5192025-03-09 12:12:16 +010074 page.goto(KORAP_URL);
75 await page.waitForNavigation({ waitUntil: 'networkidle2' });
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010076 const query_field = await page.$("#q-field")
77 assert.isNotNull(query_field, "#q-field not found. Kalamar not running?");
Marc Kupietz55fc3162022-12-04 16:25:49 +010078 }))
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010079
80
81 ifConditionIt('Login into KorAP with incorrect credentials fails',
82 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010083 (async () => {
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010084 const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD + "*")
Marc Kupietzc4077822022-12-03 15:32:40 +010085 login_result.should.be.false
Marc Kupietz55fc3162022-12-04 16:25:49 +010086 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010087
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010088 ifConditionIt('Login into KorAP with correct credentials succeeds',
89 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010090 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010091 const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD)
Marc Kupietzc4077822022-12-03 15:32:40 +010092 login_result.should.be.true
Marc Kupietz55fc3162022-12-04 16:25:49 +010093 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010094
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010095 it('Can turn glimpse off',
Marc Kupietzc4077822022-12-03 15:32:40 +010096 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010097 await korap_rc.assure_glimpse_off(page)
Marc Kupietz55fc3162022-12-04 16:25:49 +010098 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010099
Marc Kupietzc8ffb2b2025-06-12 16:44:23 +0200100 it('Corpus statistics show sufficient tokens',
101 (async () => {
102 const tokenCount = await korap_rc.check_corpus_statistics(page, KORAP_MIN_TOKENS_IN_CORPUS);
103 console.log(`Found ${tokenCount} tokens in corpus, minimum required: ${KORAP_MIN_TOKENS_IN_CORPUS}`);
104 tokenCount.should.be.above(KORAP_MIN_TOKENS_IN_CORPUS - 1,
105 `Corpus should have at least ${KORAP_MIN_TOKENS_IN_CORPUS} tokens, but found ${tokenCount}`);
106 })).timeout(25000)
107
Marc Kupietz0f6c54d2022-12-03 15:32:40 +0100108 describe('Running searches that should have hits', () => {
Marc Kupietz55fc3162022-12-04 16:25:49 +0100109
110 before(async () => { await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD) })
111
Marc Kupietz0f6c54d2022-12-03 15:32:40 +0100112 KORAP_QUERIES.split(/[;,] */).forEach((query, i) => {
113 it('Search for "' + query + '" has hits',
114 (async () => {
115 await korap_rc.assure_glimpse_off(page)
116 const hits = await korap_rc.search(page, query)
117 hits.should.be.above(0)
118 })).timeout(20000)
119 })
120 })
Marc Kupietz5a73a4d2022-12-04 14:09:58 +0100121
122 ifConditionIt('Logout works',
123 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +0100124 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +0100125 const logout_result = await korap_rc.logout(page)
Marc Kupietzc4077822022-12-03 15:32:40 +0100126 logout_result.should.be.true
Marc Kupietz964e7772025-06-03 15:02:30 +0200127 })).timeout(15000)
Marc Kupietzc4077822022-12-03 15:32:40 +0100128
Marc Kupietz55fc3162022-12-04 16:25:49 +0100129})