seleniumbase / SeleniumBase

📊 Python's all-in-one framework for web crawling, scraping, testing, and reporting. Supports pytest. UC Mode provides stealth. Includes many tools.
https://seleniumbase.io
MIT License
5.03k stars 945 forks source link

Jenkins pipeline script required #1993

Closed mastafadhil closed 1 year ago

mastafadhil commented 1 year ago

Hi,

I have been trying for days to try and get my jenkins pipeline to work, I was already able to execute tests via docker on my local using cmd lines, however when trying to do the same steps on jenkins it keeps on failing. Is there any way you could possibly provide an example of working jenkins pipeline script (regardless of using dockerfile to build the image or by using the docker image on dockerhub) that is able to generate reports within the docker container.

Here is what i have been working with :

node { git 'https://gitlab.com/username/repo.git'

def myEnv = docker.build 'seleniumbase:1'

// Run tests inside the Docker container
def containerName = 'sbase-container'
def testCommand = 'pytest'  // Replace with your actual test command
def testCommand2 = "--var1=username' --var2='password' --dashboard --html=/SeleniumBase/examples/reports-generated/report.html  --browser=chrome --headless"

try {
    def container = myEnv.run("-i -t --name ${containerName}")
    container.inside {
        bat './run_script.sh'
    }
} finally {
    // Clean up the Docker container
    bat "docker stop ${containerName}"  // Use 'bat' step for Windows
    bat "docker rm ${containerName}"  // Use 'bat' step for Windows
}

}

thank you so much in advance.

mdmintz commented 1 year ago

There's a Dockerfile here: https://github.com/seleniumbase/SeleniumBase/blob/master/Dockerfile

There are a few SeleniumBase Jenkins tutorials here:

Here's a video on the SeleniumBase Jenkins integration (it's from 2016, but the main details still hold True): https://www.youtube.com/watch?v=n-sno20R9P0

mastafadhil commented 1 year ago

Hi mdmintz, i've already looked into the links provided above and i am also already usingthe same Dockerfile to build my own image (with minor adjustments, i was able to attach my test scripts into the image), however none of the links above provides any sort of Jenkinsfile pipeline sample/example that can be used to build a pipeline in Jenkins. Is it possible that the Jenkinsfile script that I have attached above is not working, because the Dockerfile is meant to be used with Linux env (i am testing on Windows env for now)?

Thank you so much in advance and sorry for the inconvenience caused. Truly love your framework and been using it for months now.

mdmintz commented 1 year ago

The Dockerfile that SeleniumBase provides is for a Linux env. That shouldn't be used with a Windows env. You can simplify things by just focusing on running pytest from a Jenkinsfile.

Based on https://www.jenkins.io/doc/book/pipeline/jenkinsfile/ examples, here's a possible Jenkinsfile script that assumes Python and pip are already installed:

pipeline {
    agent any

    stages {
        stage('Build') {
            steps {
                pip install -U seleniumbase
            }
        }
        stage('Test') {
            steps {
                pytest --dashboard --html=report.html -s --headless
            }
        }
    }
}

Here are some outside resources I found regarding pytest and Jenkinsfile:

Since you're using seleniumbase as a pytest plugin, the real focus should be on running pytest from your Jenkins environments.