// Jenkins declarative pipeline. The agent needs Java 21, Maven and Google Chrome installed.
pipeline {
  agent any

  tools {
    // Names as configured in Manage Jenkins → Tools
    jdk 'JDK 21'
    maven 'Maven 3'
  }

  parameters {
    choice(name: 'GROUPS', choices: ['smoke', 'regression'], description: 'TestNG groups to run')
    string(name: 'BASE_URL', defaultValue: 'https://www.practiceqaautomation.com', description: 'Site under test')
  }

  environment {
    HEADLESS = 'true'
  }

  options {
    timeout(time: 30, unit: 'MINUTES')
    buildDiscarder(logRotator(numToKeepStr: '20'))
  }

  stages {
    stage('Test') {
      steps {
        sh "mvn -B test -Dgroups=${params.GROUPS} -DbaseUrl=${params.BASE_URL}"
      }
    }
  }

  post {
    always {
      junit 'target/surefire-reports/*.xml'                                  // test trend and failures in Jenkins
      archiveArtifacts artifacts: 'target/screenshots/*.png', allowEmptyArchive: true
    }
  }
}
