Skip to content

Instantly share code, notes, and snippets.

@shirish87
Last active September 8, 2024 18:39
Show Gist options
  • Save shirish87/0211d05dc43d5b8a52567cf4add87984 to your computer and use it in GitHub Desktop.
Save shirish87/0211d05dc43d5b8a52567cf4add87984 to your computer and use it in GitHub Desktop.
pipeline {
agent {
label "windows"
}
environment {
PYTHON_VERSION = "3.7.0"
BROWSERSTACK = credentials("browserstack")
BROWSERSTACK_USERNAME = "${env.BROWSERSTACK_USR}"
BROWSERSTACK_ACCESS_KEY = "${env.BROWSERSTACK_PSW}"
CHROME_DRIVER_PATH = "C:\\jenkins\\chromedriver"
}
stages {
// stage('Download ChromeDriver') {
// when {
// expression {
// def fileExists = powershell(returnStdout: true, script: 'Test-Path "${env.CHROME_DRIVER_PATH}\\chromedriver.exe"') == "True"
// println "chromedriver exists: $fileExists"
// return !fileExists
// }
// }
// steps {
// powershell '''
// $latestVersion = (Invoke-WebRequest -Uri 'https://chromedriver.storage.googleapis.com/LATEST_RELEASE' -UseBasicParsing).Content
// $downloadUrl = "https://chromedriver.storage.googleapis.com/$latestVersion/chromedriver_win32.zip"
// Invoke-WebRequest -Uri $downloadUrl -OutFile 'chromedriver.zip'
// Expand-Archive -Path 'chromedriver.zip' -DestinationPath '${env.CHROME_DRIVER_PATH}'
// $env:Path += ";${env.CHROME_DRIVER_PATH}"
// Remove-Item -Path 'chromedriver.zip' -Force
// '''
// }
// }
stage('Setup Python') {
steps {
bat "pyenv install -q ${env.PYTHON_VERSION}"
}
}
stage('Setup Repository') {
steps {
checkout([
$class: 'GitSCM',
branches: [[name: 'main']],
userRemoteConfigs: [[url: 'https://github.com/shirish87/samples.git']]
])
dir('python/pip') {
script {
def yaml = """
userName: BROWSERSTACK_USERNAME
accessKey: BROWSERSTACK_ACCESS_KEY
projectName: sdk-samples-ci
buildName: sdk-samples-ci-python
framework: pytest
platforms:
- os: OS X
osVersion: Big Sur
browserName: Chrome
browserVersion: latest
- os: Windows
osVersion: 10
browserName: Chrome
browserVersion: latest
- deviceName: Samsung Galaxy S22 Ultra
browserName: chrome # Try 'samsung' for Samsung browser
osVersion: 12.0
parallelsPerPlatform: 5
browserstackLocal: false
testObservability: true
accessibility: true
"""
writeFile(file: ".\\browserstack.yml", text: yaml)
}
powershell '''
pyenv local ${env.PYTHON_VERSION}
python -m venv env
.\\env\\Scripts\\Activate.ps1
python -m pip install --upgrade pip
'''
}
}
}
stage('Install dependencies') {
steps {
dir('python/pip') {
powershell '''
.\\env\\Scripts\\Activate.ps1
python -m pip install -r .\\selenium_pytest\\requirements.txt
python -m pip install browserstack-sdk
'''
}
}
}
stage('Test') {
steps {
dir('python/pip') {
powershell '''
.\\env\\Scripts\\Activate.ps1
browserstack-sdk pytest .\\selenium_pytest\\ --junit-xml=.\\reports\\junit-report.xml
deactivate
'''
}
}
post {
success {
junit '**/reports/junit-report.xml'
}
cleanup {
cleanWs()
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment