How to run test on GitLab CI Locally

Related Product On This Page Pre-requisites to run test on GitLab topicallyMarch 07, 2026 · 6 min read · Testing Guide

Related Product

How to run examination on GitLab CI Locally

Running examination on GitLab CI typically involves pushing changes to the monument and waiting for grapevine executing, which can slow down and maturation. To streamline this process, GitLab Runner grant developers and QA teams to action CI jobs locally, making it easier to formalize .gitlab-ci.yml configurations, run tests, and catch errors before they reach the master pipeline.

This article cover how to run tests locally using GitLab CI, include prerequisites, setting up a project on GitLab, delimitate the CI pipeline, and executing test with GitLab Runner. It also walks through how to run Selenium tryout locally on GitLab CI using BrowserStack for cross-browser validation.

Pre-requisites to run test on GitLab locally

Before running trial locally on GitLab CI, insure the following prerequisites are in place to successfully set up and execute jobs.

  • Create GitLab Account and Log In to GitLab
  • Automation Project (Java-based automation task used in this article)
  • GitLab Runner
  • Understanding of maven lifecycle
  • GitLab CI pipeline file (gitlab-ci.yml)

Also Read:

Project Creation on GitLab to run Test Locally

Follow the below step to create a project in GitLab.

  • Log in to GitLabusing your certificate.

Click New Projecton the landing dashboard

  • Validate New labor screen gets displayed. SelectCreate a blank labor. You will be navigated to a new blind, which needs the pursual inputs
    • Project Name& # 8211; Add the projection gens (For examplemy_gitlab_ci_project)
    • Project Description (Optional)& # 8211; Add appropriate description for reference
    • Visibility Level– Select the Visibility Level for the project.
  • Opt the Initialize monument with a READMEpick, this creates a README file so that the Git depository is initialised and has a default branch that can be cloned.
  • Click Create project.
  • Now clone the project on local.
  • Add the automation files and advertise the changes.
# Clone the project git ringer & lt; project_clone_with_https_link & gt; # Navigate to the repository cd & lt; project_name & gt; # Add the automation labor files cp -R & lt; automation_local_project & gt; & lt; project_name & gt; # Push the changes to gitlab, ensure you are in git repo git add. # add all file git commit -m “ adding local automation project ” # commit to git local stage environs # Run this command post local prove git push origin master # push local level change to gitlab server
  • Check all the files are available in the GitLab repository.

How to execute Local Tests use GitLab Runner

To execute local exam using GitLab Runner, follow the steps sketch below:

For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.

  • Ensure a runner is usable in GitLab to run the jobs. If there is no runner,install GitLab Runner and register a contrabandistfor the project.
  • Follow the step below to install GitLab Runner locally and register the runner using the URL and token. The local testing and labor description will be displayed in the Settings & gt; CI / CD & gt; Runners tab.

Also Read:

# Download the binary for the system # macOS amd64 sudo curl -- yield /usr/local/bin/gitlab-runner ``https: //gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-amd64`` # macOS Apple Silicon/arm64 sudo whorl -- yield /usr/local/bin/gitlab-runner ``https: //gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-arm64`` # cater theme permission and execute sudo chmod +x /usr/local/bin/gitlab-runner # Register a gitlab runner gitlab-runner register
  • You must likewise select the executor character (GitLab supply a few executor types for runners. For example & # 8211; shell, docker)
  • To view the available runners go toSettings & gt; CI/CDand expandRunners. As long as you experience at least one smuggler that is active, with a green circle close to it, you have a contrabandist approachable to handle your jobs.
  • Define a .gitlab-ci.ymlfile at the root of the depository.gitlab-ci.ymlfile defines our CI/CD jobs.

Did you know:

Defining gitlab-ci.yml

You can outline the scripts that you require to execute in thisgitlab-ci.yml file.

  • Define the include and cache dependencies.
  • Reap commands that you need to fulfill in successiveness and the ones in parallel
  • Define the route where you want to deploy the application
  • Decide if you wish to execute the scripts automatically or actuate them manually.
  • The contents are gathered into jobs and run as a feature of a bigger pipeline. You can bunch numerous independent task into stages that action in a characterized order.

When your gitlab-ci.ymlconfiguration file is added to the repository, GitLab can ascertain it and execute your playscript with the GitLab Runner app. This app functions precisely like your terminal and predominantly helps you reproduce production-like scripts.

A sample gitlab-ci.yml expression like

# Adding variables to set maven local environmentvariables:



MAVEN_OPTS:-Dmaven.repo.local=.m2/repository # Docker persona to use latest whiz dispersionimage: maven: latest # setting up maven lifecycle degreestages:



 - build - test - package - deploy # setting up stash pathscache:



  paths:- .m2/repository - targetbuild_job:



  stage: build



  tags: 



    - docker



  script:- reverberation “ Maven compile started ” - “ mvn compile ”test_job:



  stage: test



  tags:



    - docker 



  script:



    - echo `` Maven examination started '' - “ mvn tryout ”package_job:



  stage: package



  tags: 



    - docker



  script: - echo “ Maven packaging started ” - “ mvn package ”deploy_job:



  stage: deploy



  tags: 



    - docker



  script: - echo “ Maven deploy started ”

In the above gitlab-ci.yml, the build job will run the playscript under build_job so test_job will action the exam scripts under test_job, and so on with the package and deploy stages.

Explore the shell executor.

gitlab-runner exec carapace test_job

Gitlab-runner exec is the command that helps quiz topically. The exec command should be execute directly from the source directory because .gitlab-ci.yml will be kept in the source directory. While executing this, you need to specify the executor type (shell in this case) and the gens of the job (test_job).

The above dictation will clone your project from GitLab, establish the dependencies, and action the tests.

Execute Selenium Tests in Gitlab CI topically habituate Browserstack

For the most late documentation, visit.

  1. Add BrowserStack Access Key as a variable in Variables underSettings - & gt; CI/CD
  2. Set the varying name asBROWSERSTACK_ACCESS_KEYas Key. Please note that the variable name set in Key is used in the test scripts that you need to integrate with BrowserStack.
  3. Enter the value, which is you Access Key. The Access Key is present in the splashboard.
  4. Repeat above step to addBROWSERSTACK_USERNAMEas a variable.

Now you want to update our examination scripts with the local environmentBROWSERSTACK_LOCALand environment identifierBROWSERSTACK_LOCAL_IDENTIFIER

String username= System.getenv (`` BROWSERSTACK_USERNAME ''); StringaccessKey= System.getenv (`` BROWSERSTACK_ACCESS_KEY ''); StringbrowserstackLocal= System.getenv (`` BROWSERSTACK_LOCAL ''); StringbrowserstackLocalIdentifier= System.getenv (`` BROWSERSTACK_LOCAL_IDENTIFIER ''); StringbuildName= System.getenv (`` BROWSERSTACK_BUILD_NAME ''); DesiredCapabilitiescapabilities= new DesiredCapabilities ();capabilities.setCapability (`` os '', `` Windows '');capability.setCapability (`` browser '', `` chrome '');capabilities.setCapability (`` build '',buildName);



capabilities.setCapability(`` browserstack.local '', browserstackLocal);



capabilities.setCapability (`` browserstack.localIdentifier '', browserstackLocalIdentifier);driver= new RemoteWebDriver (new URL (`` https: // '' +username + ":" + accessKey+ `` @ hub.browserstack.com/wd/hub ''),capability);

You also necessitate to configure thegitlab-ci.ymlfile to use the BrowserStack Local binary and route the tests through the local server

You can add pre-test steps to add the BrowserStack binary in yourgitlab-ci.ymlas demo below.

before_script:# Download the browserstack binary file - wget `` https: //www.browserstack.com/browserstack-local/BrowserStackLocal-linux-x64.zip '' # use the following dictation For OS X systems # - wget `` https: //www.browserstack.com/browserstack-local/BrowserStackLocal-darwin-x64.zip '' # Unzip the BrowserStack Local binary file # For Windows system use the following command # - wget `` https: //www.browserstack.com/browserstack-local/BrowserStackLocal-win32.zip '' # - powershell.exe D: \BrowserStackLocal.exe - unzip BrowserStackLocal-linux-x64.zip # Run the file with your admittance key - ./BrowserStackLocal -- key $ BROWSERSTACK_ACCESS_KEY -- daemon starttest:



     script:- & lt; our_test_command & gt; - ./BrowserStackLocal -- key $ BROWSERSTACK_ACCESS_KEY -- daemon stop

Talk to an Expert

Conclusion

Running tests locally with GitLab CI using GitLab Runner offers significant vantage in price of speed and efficiency during the development and debugging operation.

By setting up a moon-curser, take the appropriate executor, and defining a .gitlab-ci.yml file, developers can quickly formalize their CI configurations and test playscript without waiting for remote line execution.

Additionally, mix platforms like for Selenium try further enhances the testing process by enabling cross-browser validation topically. By adopting this testing approach, teams can streamline workflows, cut fault, and ensure more authentic deployments.

Tags
34,000+ Views

# Ask-and-Contributeabout this issue with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free