Skip to content
Snippets Groups Projects
apps.js 7.4 KiB
Newer Older
(async () => {
Varac's avatar
Varac committed
  try {
Varac's avatar
Varac committed
    async function sso_login_if_needed (button_text) {
      try {
        await text(button_text).exists()
        // await console.log('Logging in...')
        await click(button_text)
        await write(sso_username, into(textBox('E-mail address')))
        await write(sso_user_pw, into(textBox('Password')))
        await click('Go!')
      } catch (error) {
        await console.error(error)
        console.log('Looks like we dont need to login, continuing')
      }
    }
    const { openBrowser, goto, textBox, into, write, click, toRightOf, below, link, press, image, waitFor, closeBrowser, screenshot } = require('taiko');
    const assert = require('assert');
    const globalTimeout = 60000
Varac's avatar
Varac committed
    const taikoTests = process.env.TAIKO_TESTS || 'all'
    const domain = process.env.DOMAIN
Varac's avatar
Varac committed
    const sso_username = process.env.SSO_USERNAME
    const sso_user_pw = process.env.SSO_USER_PW
Varac's avatar
Varac committed
    // https://docs.taiko.dev/api/setconfig/
Varac's avatar
Varac committed
    // setConfig( { observeTime: 1000});
    setConfig( {
      observeTime: 0,
      // Navigation timeout value in milliseconds for navigation after performing openTab, goto, reload, goBack, goForward, click, write, clear, press and evaluate.
      navigationTimeout: globalTimeout,
      highlightOnAction: 'true'
Varac's avatar
Varac committed

Varac's avatar
Varac committed
    console.log('Executing these tests: ' + taikoTests)
    await openBrowser({
      // Optimize chrome instances for docker an parallel runs, see:
      // https://docs.taiko.dev/taiko_in_docker/
      // https://docs.taiko.dev/frequently_asked_questions/#how-can-i-optimize-chrome-instances-for-parallel-runs%3F
      args: [
        "--disable-gpu",
        "--disable-dev-shm-usage",
        "--disable-setuid-sandbox",
        "--no-first-run",
        "--no-sandbox",
        "--no-zygote",
        "--start-maximized"
      ]
    });
Varac's avatar
Varac committed

Varac's avatar
Varac committed
    // Nextcloud and Onlyoffice
Varac's avatar
Varac committed
    if (taikoTests.includes('nextcloud') || taikoTests === 'all') {
      const nextcloudUrl = 'https://files.' + domain
Varac's avatar
Varac committed
      const onlyofficeUrl = 'https://office.' + domain
      console.log('• Onlyoffice')
Varac's avatar
Varac committed
      await goto(onlyofficeUrl + '/welcome')
      await waitFor(async () => (await text("Thank you for choosing ONLYOFFICE!").exists()))
      await waitFor(async () => (await text("Document Server is running").exists()))
Varac's avatar
Varac committed

      await goto(onlyofficeUrl + '/healthcheck')
      await waitFor(async () => (await text("true").exists()))

      console.log('• Nextcloud')
      await goto(nextcloudUrl)
Varac's avatar
Varac committed
      await sso_login_if_needed('Log in with Stackspin')
      await waitFor(async () => (await text("Set location for weather").exists()), globalTimeout)
      // Close potential nextcloud first run wizard modal
      // https://github.com/nextcloud/firstrunwizard/issues/488
      // Unfortunately, we need to sleep a while since I haven't found a
      // good way that closes the modal *if* it pops up, since these
      // tests should also work on subsequent logins.
      await waitFor(5000)
      await press('Escape')

Varac's avatar
Varac committed
      // Test password app
      await click('Passwords')
      await waitFor(async () => (await text("Handbook").exists()), globalTimeout)
Varac's avatar
Varac committed
      // Test if calendar app is enabled
      await click('Calendar')
      await waitFor(async () => (await text("Settings & Import").exists()), globalTimeout)
      console.log('• Nextcloud Onlyoffice integration')
Varac's avatar
Varac committed
      // Open document and type some text
Varac's avatar
Varac committed
      await click('Files')
      // Force page reload because of random empty pages for files app
      // https://open.greenhost.net/stackspin/nextcloud/-/issues/973
      await waitFor(async () => (await link({class:'new'}).isVisible()), globalTimeout)
Varac's avatar
Varac committed
      await click(link({class:'new'}))

      // Create random file name because NC20 will complain if file already
      // exists
      const file_rand = 'test-' + Math.random().toString(16).substr(2, 12)
      await press([...file_rand, 'Enter'])
Varac's avatar
Varac committed
      let italicButtonId = '#id-toolbar-btn-italic'
      await waitFor(async () => (await $(italicButtonId).isVisible()), globalTimeout)
Varac's avatar
Varac committed

      // Activate italic button
      let buttonStateBefore = await evaluate($(italicButtonId), (elem) => {return elem.getAttribute('class')})
      await assert.ok(!buttonStateBefore.includes('active'))
Varac's avatar
Varac committed

      await waitFor(async () => (await $('#id_target_cursor').isVisible()), globalTimeout)
Varac's avatar
Varac committed
      await click($(italicButtonId))
Varac's avatar
Varac committed
      let buttonStateAfter = await evaluate($(italicButtonId), (elem) => {return elem.getAttribute('class')})
      await assert.ok(buttonStateAfter.includes('active'))

      await press([...'Hi from taiko!', 'Enter'])
Varac's avatar
Varac committed

      // Deactivate italic finially
      await click($(italicButtonId))
      await closeTab()
Varac's avatar
Varac committed
    if (taikoTests.includes('wordpress') || taikoTests === 'all') {
      const wordpressUrl = 'https://www.' + domain

Varac's avatar
Varac committed
      console.log('• Wordpress')
      await goto(wordpressUrl)
      await waitFor('Hello world!')
      await goto(wordpressUrl + '/wp-admin/')
Varac's avatar
Varac committed
      await sso_login_if_needed('Login with OpenID Connect')
Varac's avatar
Varac committed
      await assert.ok(await link('Dashboard').exists())
Varac's avatar
Varac committed
    // Grafana
    if (taikoTests.includes('grafana') || taikoTests === 'all') {
      const grafanaUrl = 'https://grafana.' + domain

      console.log('• Grafana')
      await goto(grafanaUrl)
Varac's avatar
Varac committed
      await sso_login_if_needed('Sign in with Stackspin')

      // Node exporter dashboard
      // Couldn't select "Manage dashboards" from the sidebar menu easily,
      // so we just go there
Varac's avatar
Varac committed
      await goto(grafanaUrl + '/dashboards')
Varac's avatar
Varac committed
      await click(link('Nodes'))
      await('CPU Usage')

      // Explore Loki log messages
Varac's avatar
Varac committed
      // Currently disabled until admin user gets proper admin privileges
Varac's avatar
Varac committed
      // See https://open.greenhost.net/stackspin/single-sign-on/-/issues/122
Varac's avatar
Varac committed
      // await goto(grafanaUrl + '/explore')
      // await click(image(toRightOf('Explore')))
      // await click('Loki')
      // await click('Log browser')
      // await click('app')
      // await click('cert-manager')
      // await click('grafana')
      // await click('Show logs')
Varac's avatar
Varac committed
    // Wekan
    if (taikoTests.includes('wekan') || taikoTests === 'all') {
      const wekanUrl = 'https://wekan.' + domain

      console.log('• Wekan')
      await goto(wekanUrl)
Varac's avatar
Varac committed
      await sso_login_if_needed('sign in with Oidc')
      console.log(`\nPlease note that above error message is acceptable since wei
did not find a way with taiko to handle OIDC login popup windows well.
Wekan still doesnt support OIDC redirects (https://github.com/wekan/wekan/issues/3845).\n`)
Varac's avatar
Varac committed
      await goto(wekanUrl)
      await assert.ok(await text('All boards').exists())
Varac's avatar
Varac committed
    }

Varac's avatar
Varac committed
    // Dashboard
    if (taikoTests.includes('dashboard') || taikoTests === 'all') {
Varac's avatar
Varac committed
      const dashboardUrl = 'https://dashboard.' + domain
      console.log('• Dashboard at ' + dashboardUrl)
Varac's avatar
Varac committed
      await goto(dashboardUrl)
      await sso_login_if_needed('Sign in')
      await assert.ok(await text('Dashboard').exists())
      await assert.ok(await text('Utilities').exists())
Maarten de Waard's avatar
Maarten de Waard committed
    // Zulip
    if (taikoTests.includes('zulip') || taikoTests === 'all') {
Maarten de Waard's avatar
Maarten de Waard committed
      const zulipUrl = 'https://zulip.' + domain
Maarten de Waard's avatar
Maarten de Waard committed

      console.log('• Zulip')
      await goto(zulipUrl)
Varac's avatar
Varac committed
      await sso_login_if_needed("Log in with Stackspin")
      await assert.ok(await text('Private messages').exists())
Maarten de Waard's avatar
Maarten de Waard committed
    }

Varac's avatar
Varac committed
  } catch (error) {
Varac's avatar
Varac committed
    await screenshot()
Varac's avatar
Varac committed
    console.error(error)
Varac's avatar
Varac committed
    process.exitCode = 1
Varac's avatar
Varac committed
  } finally {
    await closeBrowser()
  }
})()