import master from '../wdio.conf.js'
import EuiReporter from '../core/reporter/eui-reporter.js'
import ZephyrPublisher from '../core/reporter/publishers/zephyr-publisher.js'
import tools from '@eui/tools/scripts/utils/tools.js'
const { vaultUser, vaultPassword  } = tools.getArgs()
import {join} from 'path'
import testSuites from './suites.json' assert { type: "json" }
const IMAGE_FOLDER_PREFIX = './packages/eui-automation/tests/wdioImages/'

export const config = Object.assign(master.config, {
  vaultConfig: {
    endpoint: 'https://vault.compasscorporate.eu/v1',
    user: vaultUser,
    password: vaultPassword
  },
  screenshot: 'fail',  // never, fail or always
  browserlog: 'always',  // never, fail or always
  baseUrl: 'https://eui.ecdevops.eu/',
  specs: ['./packages/eui-automation/tests/**/*.spec.js'],
  logLevel: 'error',
  suites: testSuites,
  maxInstances: 5,
  capabilities: [
    {
      browserName: 'chrome',
      'goog:chromeOptions': {
        args: ['disable-infobars', 'window-size=1920,1080', 'incognito', 'headless'],
        // args: ['disable-infobars', '--window-size=1920,1080', '--incognito'],
      },
      "goog:loggingPrefs": { browser: "ALL", driver: "ALL", performance: "ALL" },
    },
  ],
  env: 'PROD',
  window_width: 1920,
  window_height: 1080,
  // set below flag to true to enable wdioImageComparison code in eUI tests
  useWdioImageComparison: true,
  automationProtocol:'webdriver',
  services: [
  ['image-comparison', {
      // Some options, see the docs for more
      baselineFolder: join(process.cwd(), IMAGE_FOLDER_PREFIX),
      formatImageName: '{tag}-{logName}-{width}x{height}',
      screenshotPath: join(process.cwd(), '.tmp/'),
      savePerInstance: true,
      autoSaveBaseline: true,
      blockOutStatusBar: true,
      blockOutToolBar: true,
      // NOTE: When you are testing a hybrid app please use this setting
      isHybridApp: true,
  }]],
  reporters: ['spec',
  ['allure', {
    outputDir: 'allure-results',
    cleanBefore: true,
    disableWebdriverStepsReporting: true,
    disableWebdriverScreenshotsReporting: false,
    openReport: true // CAREFULL, should be false when run on CI execution or other execution agent
  }],
  [EuiReporter, {
    loggerOptions: {
      reportDir: 'jsonReport'
    },
    publishers: [
      {
        type:ZephyrPublisher,
        config:{
          publish: 'never',  // never, fail or always
          baseUrl: 'https://webgate.ec.europa.eu/CITnet/jira',
          zapiUrl: '/rest/zapi/latest',
          projectKey: 'CCQA',
          boardId: '4414',
          onlyPublishFailures: true,
          deleteOldReports: true,
          keepMonthsHistoryNbr:3,
          // vaultConfig can be added as an alternative to passing username and password in the config
          // username and password can still be used however
          // the vaultConfig entry will be removed in the beforeSession hook and
          // replaced with all entries of the given vault secret unless the entry already exists
          vaultConfig: {
            path: "/secret/functional/citnet",
            key: "default",
          }
        }
      }
    ]
  }]]
});


