Marc Kupietz | 490b053 | 2024-09-05 09:36:21 +0200 | [diff] [blame^] | 1 | const puppeteer = require('puppeteer-extra'); |
| 2 | puppeteer.use(require('puppeteer-extra-plugin-user-preferences')({ |
| 3 | userPrefs: { |
| 4 | safebrowsing: { |
| 5 | enabled: false, |
| 6 | enhanced: false |
| 7 | } |
| 8 | } |
| 9 | })); |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 10 | const chai = require('chai'); |
Marc Kupietz | 4c5a7a5 | 2022-12-04 16:56:30 +0100 | [diff] [blame] | 11 | const { afterEach } = require('mocha'); |
| 12 | const { doesNotMatch } = require('assert'); |
Marc Kupietz | 4d335a3 | 2024-09-04 16:13:48 +0200 | [diff] [blame] | 13 | const { log } = require('console'); |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 14 | const assert = chai.assert; |
| 15 | const should = chai.should(); |
Marc Kupietz | 7f1666a | 2024-07-12 18:35:31 +0200 | [diff] [blame] | 16 | var slack = null; |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 17 | |
Marc Kupietz | 0f6c54d | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 18 | const KORAP_URL = process.env.KORAP_URL || "http://localhost:64543"; |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 19 | 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] | 20 | const KORAP_PWD = process.env.KORAP_PWD || "password2"; |
Marc Kupietz | 2698238 | 2022-12-04 19:02:57 +0100 | [diff] [blame] | 21 | 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] | 22 | const korap_rc = require('../lib/korap_rc.js').new(KORAP_URL) |
| 23 | |
Marc Kupietz | 7f1666a | 2024-07-12 18:35:31 +0200 | [diff] [blame] | 24 | const slack_webhook = process.env.SLACK_WEBHOOK_URL; |
Marc Kupietz | 4d335a3 | 2024-09-04 16:13:48 +0200 | [diff] [blame] | 25 | |
Marc Kupietz | 7f1666a | 2024-07-12 18:35:31 +0200 | [diff] [blame] | 26 | if (slack_webhook) { |
| 27 | slack = require('slack-notify')(slack_webhook); |
| 28 | } |
| 29 | |
Marc Kupietz | 5a73a4d | 2022-12-04 14:09:58 +0100 | [diff] [blame] | 30 | function ifConditionIt(title, condition, test) { |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 31 | return condition ? it(title, test) : it.skip(title + " (skipped)", test) |
Marc Kupietz | 5a73a4d | 2022-12-04 14:09:58 +0100 | [diff] [blame] | 32 | } |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 33 | |
Marc Kupietz | 0f6c54d | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 34 | describe('Running KorAP UI end-to-end tests on ' + KORAP_URL, () => { |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 35 | |
| 36 | before(async () => { |
Marc Kupietz | 69e0280 | 2023-11-08 14:37:22 +0100 | [diff] [blame] | 37 | browser = await puppeteer.launch({ |
| 38 | headless: "new", |
| 39 | }) |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 40 | page = await browser.newPage() |
Marc Kupietz | 4c5a7a5 | 2022-12-04 16:56:30 +0100 | [diff] [blame] | 41 | await page.setViewport({ |
| 42 | width: 1280, |
| 43 | height: 768, |
| 44 | deviceScaleFactor: 1, |
| 45 | }); |
Marc Kupietz | 4d335a3 | 2024-09-04 16:13:48 +0200 | [diff] [blame] | 46 | console.log("Browser version: " + await browser.version() + " started") |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 47 | }) |
| 48 | |
| 49 | after(async () => { |
| 50 | await browser.close() |
| 51 | }) |
| 52 | |
Marc Kupietz | 4c5a7a5 | 2022-12-04 16:56:30 +0100 | [diff] [blame] | 53 | afterEach(async function () { |
| 54 | if (this.currentTest.state == "failed") { |
Marc Kupietz | f838f8b | 2022-12-04 19:02:57 +0100 | [diff] [blame] | 55 | await page.screenshot({path: "failed_" + this.currentTest.title.replaceAll(/[ &\/]/g, "_") + '.png'}); |
Marc Kupietz | 7f1666a | 2024-07-12 18:35:31 +0200 | [diff] [blame] | 56 | if (slack) { |
| 57 | slack.alert({ |
| 58 | text: 'Test on ' + KORAP_URL + ' failed: ' + this.currentTest.title, |
| 59 | }) |
| 60 | } |
Marc Kupietz | 4c5a7a5 | 2022-12-04 16:56:30 +0100 | [diff] [blame] | 61 | } |
| 62 | }) |
| 63 | |
Marc Kupietz | 5a73a4d | 2022-12-04 14:09:58 +0100 | [diff] [blame] | 64 | 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 Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 69 | })) |
Marc Kupietz | 5a73a4d | 2022-12-04 14:09:58 +0100 | [diff] [blame] | 70 | |
| 71 | |
| 72 | ifConditionIt('Login into KorAP with incorrect credentials fails', |
| 73 | KORAP_LOGIN != "", |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 74 | (async () => { |
Marc Kupietz | 0f6c54d | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 75 | const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD + "*") |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 76 | login_result.should.be.false |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 77 | })) |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 78 | |
Marc Kupietz | 5a73a4d | 2022-12-04 14:09:58 +0100 | [diff] [blame] | 79 | ifConditionIt('Login into KorAP with correct credentials succeeds', |
| 80 | KORAP_LOGIN != "", |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 81 | (async () => { |
Marc Kupietz | 5e45a2f | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 82 | const login_result = await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD) |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 83 | login_result.should.be.true |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 84 | })) |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 85 | |
Marc Kupietz | 0f6c54d | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 86 | it('Can turn glimpse off', |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 87 | (async () => { |
Marc Kupietz | 5e45a2f | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 88 | await korap_rc.assure_glimpse_off(page) |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 89 | })) |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 90 | |
Marc Kupietz | 0f6c54d | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 91 | describe('Running searches that should have hits', () => { |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 92 | |
| 93 | before(async () => { await korap_rc.login(page, KORAP_LOGIN, KORAP_PWD) }) |
| 94 | |
Marc Kupietz | 0f6c54d | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 95 | 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 Kupietz | 5a73a4d | 2022-12-04 14:09:58 +0100 | [diff] [blame] | 104 | |
| 105 | ifConditionIt('Logout works', |
| 106 | KORAP_LOGIN != "", |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 107 | (async () => { |
Marc Kupietz | 5e45a2f | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 108 | const logout_result = await korap_rc.logout(page) |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 109 | logout_result.should.be.true |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 110 | })) |
Marc Kupietz | c407782 | 2022-12-03 15:32:40 +0100 | [diff] [blame] | 111 | |
Marc Kupietz | 55fc316 | 2022-12-04 16:25:49 +0100 | [diff] [blame] | 112 | }) |