blob: 2c428586da8157f12320a3b7929e49dbf706c488 [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 Kupietz5a73a4d2022-12-04 14:09:58 +010020const korap_rc = require('../lib/korap_rc.js').new(KORAP_URL)
21
Marc Kupietz7f1666a2024-07-12 18:35:31 +020022const slack_webhook = process.env.SLACK_WEBHOOK_URL;
Marc Kupietz4d335a32024-09-04 16:13:48 +020023
Marc Kupietz7f1666a2024-07-12 18:35:31 +020024if (slack_webhook) {
25 slack = require('slack-notify')(slack_webhook);
26}
27
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010028function ifConditionIt(title, condition, test) {
Marc Kupietz55fc3162022-12-04 16:25:49 +010029 return condition ? it(title, test) : it.skip(title + " (skipped)", test)
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010030}
Marc Kupietzc4077822022-12-03 15:32:40 +010031
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010032describe('Running KorAP UI end-to-end tests on ' + KORAP_URL, () => {
Marc Kupietzc4077822022-12-03 15:32:40 +010033
34 before(async () => {
Marc Kupietz69e02802023-11-08 14:37:22 +010035 browser = await puppeteer.launch({
Marc Kupietzbfb23012025-06-03 15:47:10 +020036 headless: "shell",
37 args: [
38 '--no-sandbox',
39 '--disable-setuid-sandbox',
40 '--disable-dev-shm-usage',
41 '--disable-accelerated-2d-canvas',
42 '--no-first-run',
43 '--no-zygote',
44 '--disable-gpu'
45 ]
Marc Kupietz69e02802023-11-08 14:37:22 +010046 })
Marc Kupietzc4077822022-12-03 15:32:40 +010047 page = await browser.newPage()
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010048 await page.setViewport({
Marc Kupietz9e0f5192025-03-09 12:12:16 +010049 width: 1980,
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010050 height: 768,
51 deviceScaleFactor: 1,
Marc Kupietz964e7772025-06-03 15:02:30 +020052 });
Marc Kupietz4d335a32024-09-04 16:13:48 +020053 console.log("Browser version: " + await browser.version() + " started")
Marc Kupietzc4077822022-12-03 15:32:40 +010054 })
55
56 after(async () => {
57 await browser.close()
58 })
59
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010060 afterEach(async function () {
61 if (this.currentTest.state == "failed") {
Marc Kupietz964e7772025-06-03 15:02:30 +020062 await page.screenshot({ path: "failed_" + this.currentTest.title.replaceAll(/[ &\/]/g, "_") + '.png' });
Marc Kupietz7f1666a2024-07-12 18:35:31 +020063 if (slack) {
64 slack.alert({
65 text: 'Test on ' + KORAP_URL + ' failed: ' + this.currentTest.title,
66 })
67 }
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010068 }
Marc Kupietz964e7772025-06-03 15:02:30 +020069 })
Marc Kupietz4c5a7a52022-12-04 16:56:30 +010070
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010071 it('KorAP UI is up and running',
72 (async () => {
Marc Kupietz9e0f5192025-03-09 12:12:16 +010073 page.goto(KORAP_URL);
74 await page.waitForNavigation({ waitUntil: 'networkidle2' });
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010075 const query_field = await page.$("#q-field")
76 assert.isNotNull(query_field, "#q-field not found. Kalamar not running?");
Marc Kupietz55fc3162022-12-04 16:25:49 +010077 }))
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010078
79
80 ifConditionIt('Login into KorAP with incorrect credentials fails',
81 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010082 (async () => {
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010083 const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD + "*")
Marc Kupietzc4077822022-12-03 15:32:40 +010084 login_result.should.be.false
Marc Kupietz55fc3162022-12-04 16:25:49 +010085 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010086
Marc Kupietz5a73a4d2022-12-04 14:09:58 +010087 ifConditionIt('Login into KorAP with correct credentials succeeds',
88 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +010089 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010090 const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD)
Marc Kupietzc4077822022-12-03 15:32:40 +010091 login_result.should.be.true
Marc Kupietz55fc3162022-12-04 16:25:49 +010092 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010093
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010094 it('Can turn glimpse off',
Marc Kupietzc4077822022-12-03 15:32:40 +010095 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +010096 await korap_rc.assure_glimpse_off(page)
Marc Kupietz55fc3162022-12-04 16:25:49 +010097 }))
Marc Kupietzc4077822022-12-03 15:32:40 +010098
Marc Kupietz0f6c54d2022-12-03 15:32:40 +010099 describe('Running searches that should have hits', () => {
Marc Kupietz55fc3162022-12-04 16:25:49 +0100100
101 before(async () => { await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD) })
102
Marc Kupietz0f6c54d2022-12-03 15:32:40 +0100103 KORAP_QUERIES.split(/[;,] */).forEach((query, i) => {
104 it('Search for "' + query + '" has hits',
105 (async () => {
106 await korap_rc.assure_glimpse_off(page)
107 const hits = await korap_rc.search(page, query)
108 hits.should.be.above(0)
109 })).timeout(20000)
110 })
111 })
Marc Kupietz5a73a4d2022-12-04 14:09:58 +0100112
113 ifConditionIt('Logout works',
114 KORAP_LOGIN != "",
Marc Kupietzc4077822022-12-03 15:32:40 +0100115 (async () => {
Marc Kupietz5e45a2f2022-12-03 15:32:40 +0100116 const logout_result = await korap_rc.logout(page)
Marc Kupietzc4077822022-12-03 15:32:40 +0100117 logout_result.should.be.true
Marc Kupietz964e7772025-06-03 15:02:30 +0200118 })).timeout(15000)
Marc Kupietzc4077822022-12-03 15:32:40 +0100119
Marc Kupietz55fc3162022-12-04 16:25:49 +0100120})