Running Tests In Cypress With GitHub Actions [Complete Guide]
Tags: webdev, cypress, automation, testing
Published: 2023-06-23 07:42:15

In today’s tech world, where speed is the key to modern software development, we should aim to get quick feedback on the impact of any change, and that is where CI/CD comes in place.

Setting up CI/CD is crucial for automated test cases because it gives more consistent results, agility, and efficient assessment of minor changes. With the shorter release and fast development cycles, we need to check that automated tests are passing on every code change, which can be easily done by configuring the CI/CD pipeline.

Let’s try to understand the impact of CI/CD with an example here:

You want to execute the automation suite whenever anyone pushes the code in the Git repository. So, how will you do that?

* **With no CI/CD set up for your project**

To run the automation suite, you have to pull the latest code and then run it locally on your machine, which is a tedious and lengthy process.

* **With CI/CD implemented**

You will set up your project’s CI/CD pipeline. So, your automation [test suite](https://www.lambdatest.com/learning-hub/test-suite?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=learning_hub) would run whenever anyone pushes a code or creates a pull request automatically. It will take the latest code from the Git repository and run the test.

Setting up CI/CD helps to save time. Over the past few years, [DevOps](https://www.lambdatest.com/blog/getting-started-with-devops/?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=blog) has become an important part of the software life cycle, leading to the growth of various DevOps tools and practices.

There are many [CI/CD tools](https://www.lambdatest.com/blog/best-ci-cd-tools/?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=blog) available in the market used by automation testers, but these days most people are using GitHub for version control and collaboration. So, GitHub Actions is becoming the favorite choice for automation testers/developers for CI/CD.

GitHub Actions is offered by GitHub as a SaaS offering. With GitHub Actions, you can achieve scheduling, parallelization, [run your tests on Docker](https://www.lambdatest.com/blog/run-selenium-tests-in-docker/?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=blog) Containers, and can do many more.

In this blog on Cypress with GitHub Actions, we will learn how to set up CI/CD pipeline for Cypress test cases using GitHub Actions.

## What is Cypress?

[Cypress](https://www.lambdatest.com/learning-hub/cypress-tutorial?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=learning_hub) is an open-source framework, which is built on Node.js and comes packaged as an npm module. It uses JavaScript for [writing the test cases](https://www.lambdatest.com/blog/17-lessons-i-learned-for-writing-effective-test-cases/?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=blog). As it runs tests directly inside the browser, it is fast compared to the other [automation testing tools](https://www.lambdatest.com/blog/automation-testing-tools/?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=blog) (or frameworks).

[Cypress automation tool](https://www.lambdatest.com/cypress-automation-tool?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=webpage) has received huge acceptance from QA and Developers and is constantly gaining popularity due to its features like easy installation, easy debugging, real-time reloads, and ease of use.

Below are some of the features, which make it unique from other [web automation](https://www.lambdatest.com/learning-hub/web-automation?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=learning_hub) tools in the market:

* Easy Installation.

* Easy Debugging.

* In-built support for Retries, Screenshots, and Videos (No Extra code needs to be written).

* Automatic Reload (Cypress reloads your test case whenever you make any changes to your script).

* Can easily run your tests on different viewports ( iPad, iPhone, Samsung).

* Flake Resistant (Cypress waits for commands and assertions before moving on to the next step which avoids flakiness in a test).

{% youtube jX3v3N6oN5M %}

***Learn why Python is the top choice for automation testing. This comprehensive tutorial provides a step-by-step guide to [Python automation testing](https://www.lambdatest.com/blog/python-automation-testing/?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=blog) to help you streamline your testing process.***

## What is GitHub Actions?

GitHub Actions is a [Continuous Integration](https://www.lambdatest.com/blog/what-is-continuous-integration-and-continuous-delivery/?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=blog) (build, test, merge) and Continuous Delivery (automatically released to the repository) **(CI/CD)** platform. It automates and executes the software development workflows right from GitHub.

With GitHub Actions, you can build, test, and publish across multiple platforms, operating systems, and languages all within the same workflow and then see the status checks displayed within the pull request.

![](https://cdn-images-1.medium.com/max/2312/0*w-0pS3msqGSiCpvD.png)

All GitHub Actions are handled via workflows, which are .yml files placed under the .github/workflows directory in a repository that defines automated processes. It brings automation directly into the software development lifecycle via event-driven triggers such as creating a pull request or pushing a code into a remote branch.

With GitHub Action, the pain of keeping your plugins updated is gone (which is the issue for other CI/CD tools like Jenkins), You don’t have to go to a separate tab for running CI/CD and pushing your code. It is all done in GitHub.

Some of the features of GitHub Actions are:

* Ease of setup. There is no installation required as it is on the cloud.

* Support of multiple languages and frameworks.

* Provides actions to every GitHub event.

* It can be shared via GitHub Marketplace.

* No explicit plugin is required for caching. You can write your own caching mechanism if you require caching.

* Asynchronous CI/CD is achieved using GitHub Actions.

*At present, GitHub Actions is free to use for public repositories, and for private, it has a pay-as-you-go mechanism.*

***We can speed up the software validation process and boost testing coverage by adopting automated testing. However, there are a lot of [challenges in test automation](https://www.lambdatest.com/blog/python-automation-testing/?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=blog).***

## How to setup GitHub Actions in your Git repository?

GitHub Actions lets you run workflows when a certain triggering event occurs such as a code push, or pull request. A GitHub repository can have multiple workflows. For example, we can create 1 workflow to run our test case whenever there is a code push and one workflow to test the pull requests.

As part of this Cypress with GitHub Actions tutorial, we will learn how to set up the GitHub Action pipeline whenever there is a code push to the remote branch.
Reference code can be found here:

![](https://cdn-images-1.medium.com/max/2000/0*KCJ6weuMl5D-OV_X.png)

Below are the steps to set up GitHub Actions in the Git repository:

 1. Login to your GitHub account.

 2. Create a workflow: Click on **Add file > Create new file**.

 3. Enter .github/workflows/main.yml ( It has to be in the same sequence). main.yml is the file name, you can name it as per your choice.

 4. Create a workflow file.

Follow the below sample code to create a GitHub Actions workflow (.yml file)

  

```
  name: Add Action
    on:
     push:
       branches:
         - main
    jobs:
     Cypress-Test:
       runs-on: ubuntu-latest
       steps:
         - name: Checkout GitCode
           uses: actions/checkout@v2
```

* **name** => It is the name of the workflow file. It appears in the “Actions” tab of the GitHub Repository with the same name.

* **on**=> On is the trigger condition, it specifies the trigger for the workflow. We have to add the events (**push, pull_request**, etc.) as subsections. In the above example, the workflow would be triggered whenever anyone pushes a change to the repository.

* **jobs**=> Groups all the jobs/tasks that are defined inside the job section in the yml file. We can define the name of jobs just in the next line.

* **runs-on**: ubuntu-latest => It configures the job to run on the latest version of Ubuntu. The job will execute on a fresh virtual machine hosted by GitHub. You can configure any value of the OS where you would like to execute the GitHub Actions workflow on.

* **Steps**=> It groups together all the steps that are defined in the yml file. There can be multiple steps in a .yml file. It is placed at the same level as the on section.

* **Uses**=>Syntax to use the GitHub Actions in the .yml file. You can pass the GitHub Actions to run the test case/ to checkout the code.

Now if you add this simple workflow to your repo, and push your code on the **main** branch, you can check that a workflow has been added under the Actions tab.

![](https://cdn-images-1.medium.com/max/3200/0*1Idcm2gf7Nc5GJcp.png)

If you click on the workflow run, you’ll see some details such as the commit, the status, the time duration, as well as the jobs that have run.

![](https://cdn-images-1.medium.com/max/3200/0*ddM9fi2U3IBCFUSQ.png)

As per the above screenshot, we have only 1 job, i.e., Cypress-Test. We can also view the logs about setting up the job and completing it just by clicking Cypress-Test.

![](https://cdn-images-1.medium.com/max/3200/0*2qIjY3SUUlMlvJo6.png)

If you want to explore more on the workflow syntax. You can check [here](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions).

***Learn why Python is the top choice for automation testing. This comprehensive tutorial provides a step-by-step guide to [Python automation testing](https://www.lambdatest.com/blog/python-automation-testing/?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=blog) to help you streamline your testing process.***

## How to run Cypress tests using GitHub Actions?

Cypress is a [test automation](https://www.lambdatest.com/automation-testing?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=webpage) tool for web applications, and GitHub Actions is a service that allows developers to automate various tasks, such as building, testing, and deploying code. Using Cypress with GitHub Actions allows us to automate the testing of a web application as part of the continuous integration and continuous deployment process. This can help ensure that the application is working properly and save time and effort for the development team.

To use Cypress with GitHub Actions, you would need to create a workflow file that defines the steps for running your Cypress tests. This file would be stored in your GitHub repository and would be executed by GitHub Actions whenever a specified event, such as pushing code to the repository, occurs.

We will see step by step, how to run the tests using Cypress with GitHub Actions.

**Pre-Requisites:**

* GitHub Repository with working Cypress code

* Knowledge of Cypress

**Test Scenario:**

 1. Open URL. [https://ecommerce-playground.lambdatest.io/index.php?route=account/login%22](https://ecommerce-playground.lambdatest.io/index.php?route=account/login%22)

 2. Log in to the application.

 3. Search the product.

 4. Verify the searched product.

Below is the [Cypress end-to-end test](https://www.lambdatest.com/cypress-e2e-testing?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=webpage) code where the user opens the browser, searches for a product, and verifies it in the end.

    

```
describe("Automation using Cypress", () => {
     it("Open website and enter username, password", () => {
       cy.visit(
         "https://ecommerce-playground.lambdatest.io/index.php?route=account/login"
       );
     });
     it("Login into the application using credentials", () => {
       cy.get('[id="input-email"]').type("lambdatest.Cypress@disposable.com");
       cy.get('[id="input-password"]').type("Cypress123!!");
       cy.get('[type="submit"]').eq(0).click();
     });
     it("Search the Product", () => {
       cy.get('[name="search"]').eq(0).type("Macbook");
       cy.get('[type="submit"]').eq(0).click();
     });
     it("Verify Product after search ", () => {
       cy.contains("Macbook");
     });
    });
```

In order to run the above code locally through the terminal, we would run the command **“npx cypress run”**.

It will run the [Cypress test automation](https://www.lambdatest.com/blog/cypress-test-automation-framework/?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=blog) and show you the test result in the terminal just like shown below:

![](https://cdn-images-1.medium.com/max/3068/0*RRinKuUulGSZyjyr.png)

Let’s learn how to run the above tests using Cypress with GitHub Actions. If you have followed setting up GitHub Actions in the above section of this blog on Cypress with GitHub Actions, by now you would know how to create a workflow .yml file.

Follow the below code to run the tests using Cypress with Github Actions:

    

```
name: Cypress Tests
    on: [push]
    jobs:
     Cypress-Test:
       runs-on: ubuntu-latest
       steps:
         - name: Checkout GitCode
           uses: actions/checkout@v2
     
         - name: Run Cypress Test
           uses: cypress-io/github-action@v4
           with:
             command: npx cypress run
             browser: chrome
```

In order to run it using Cypress with GitHub Actions workflow, we will use the Cypress official GitHub Actions (**cypress-io/github-action@v4**) (ref : Line11)

 1. We have provided the name of the workflow as **“Cypress Test”**.

 2. We provided the trigger condition, In the above case, it would be pushed. So, whenever there would be code push to the remote branch, this workflow would be executed.

 3. Jobs’ name is passed as **“Cypress Test”** under which we are providing the OS info to run it on the latest ubuntu OS.

 4. There are 2 steps added as part of the shared workflow .yml file.

* The first step, would checkout the code from the GitHub repository using GitHub Actions **“actions/checkout@v2”**.

* The second step would run the Cypress tests. Cypress has official GitHub Actions for running the Cypress tests, which is **“cypress-io/github-action@v4”**. This action provides npm installation, custom caching, and additional configuration options and simplifies the setup of advanced workflows using Cypress with GitHub Actions platform.

![](https://cdn-images-1.medium.com/max/2000/0*BI_0t0ftE-LJ0Qv_.png)

The above workflow would be called whenever there will be code push in your remote GitHub repository.

Once, the workflow is run. You can view the workflow run status from the Actions tab in your GitHub Project just as shown in the below screenshot.

![](https://cdn-images-1.medium.com/max/3200/0*m_DmHkmw4HeiW9Mg.png)

You can also check the step-by-step summary of each GitHub Actions just by clicking the file name and it will take you to the summary screen.

![](https://cdn-images-1.medium.com/max/3200/0*MdhJ-vvckcHUW6UE.png)

*cypress-io/github-action@v4.x.x . . is the Cypress official GitHub Action. By default, it:*

* *Install npm dependencies.*

* *Build the project (npm run build)*.

* *Start the project web server (npm start)*.

* *Run the Cypress tests within our GitHub repository within Electron*.

***In this Selenium with Java tutorial, you will learn everything you need to know to kick start your journey in Selenium [automation testing with Java](https://www.lambdatest.com/blog/selenium-with-java/?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=blog).***

## How to run the Cypress Test Case on a cloud platform using GitHub Actions?

There are multiple approaches to perform [Cypress testing](https://www.lambdatest.com/cypress-testing?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=webpage) on a cloud testing platform like LambdaTest using GitHub Actions.

Continuous quality cloud testing platforms such as LambdaTest lets you perform manual and automation testing of your websites and mobile applications on an [online device farm](https://www.lambdatest.com/online-device-farm?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=webpage) of 3000+ real browsers, devices, and platform combinations. It provides developers with the ability to run their automated tests using different [automation testing frameworks](https://www.lambdatest.com/blog/best-test-automation-frameworks-2021/?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=blog) including [Selenium](https://www.lambdatest.com/selenium?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=webpage), Cypress, Playwright and more.

{% youtube jrgx_3gfWVA %}

***Jenkins is an open-source automation server that is written entirely in Java. Learn how to do continuous integration with Jenkins with this comprehensive guide to [Jenkins Tutorial](https://www.lambdatest.com/learning-hub/jenkins?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=learning_hub).***

One of the ways is using the ***command*** as part of Cypress with GitHub Actions.

Below is the [Cypress end-to-end testing](https://www.lambdatest.com/cypress-e2e-testing?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=webpage) code, which I would run in the LambdaTest cloud platform.

   

```
 describe("Automation using Cypress", () => {
     it("Open website and enter username, password", () => {
       cy.visit(
         "https://ecommerce-playground.lambdatest.io/index.php?route=account/login"
       );
     });
     it("Login into the application using credentials", () => {
       cy.get('[id="input-email"]').type("lambdatest.Cypress@disposable.com");
       cy.get('[id="input-password"]').type("Cypress123!!");
       cy.get('[type="submit"]').eq(0).click();
     });
     it("Search the Product", () => {
       cy.get('[name="search"]').eq(0).type("Macbook");
       cy.get('[type="submit"]').eq(0).click();
     });
     it("Verify Product after search ", () => {
       cy.contains("Macbook");
     });
    });
```

To run the [Cypress UI tests ](https://www.lambdatest.com/cypress-ui-testing?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=webpage)on the LambdaTest Platform, we need to do the configuration using 3 steps.

**Step 1: Install LambdaTest CLI.**

Install LambdaTest CLI using npm, use the below command:

npm install lambdatest-cypress-cli

![](https://cdn-images-1.medium.com/max/3048/0*LwXtZmH9b-5UyifQ.png)

**Step 2: Set up the config.**

Once the LambdaTest CLI is installed, now we need to set up the configuration using the below command:

lambdatest-cypress init

![](https://cdn-images-1.medium.com/max/3074/0*Zo9tBWfssSAyxjpX.png)

After running the command, there will be a file created in your project named *“lambdatest-config.json”*. We need to set up the configuration in order to run our test case on different browsers on LambdaTest.

* **auth:** We need to set up the LambdaTest credentials, which will be used in lambdatest-config.json to run my test case on the cloud platform.

* **browsers:** Need to specify the browser and OS version on which we want our test case to run.

* **run_setting:** Need to set up the config in run_settings.
Set up the config name, which would differ based on different Cypress Versions, and set up the spec file.

  

```
  {
      "lambdatest_auth": {
         "username": "user.name",
         "access_key": "access.key"
      },
      "browsers": [
         {
            "browser": "Chrome",
            "platform": "Windows 10",
            "versions": [
               "latest-1"
            ]
         },
         {
            "browser": "Firefox",
            "platform": "Windows 10",
            "versions": [
               "latest-1"
            ]
         }
      ],
      "run_settings": {
         "config_file": "cypress.config.js",
         "reporter_config_file": "base_reporter_config.json",
         "build_name": "Cypress-Test",
         "parallels": 1,
         "specs": "./cypress/e2e/*/*.cy.js",
         "ignore_files": "",
         "network": false,
         "headless": false,
         "npm_dependencies": {
            "cypress": "11.2.0"
         }
      },
      "tunnel_settings": {
         "tunnel": false}}
```

**Step 3: Execute Test Case**

Once the config is done, now you can execute the Cypress test case on the LambdaTest cloud Platform. You just need to run the below command to run it on LambdaTest.

lambdatest-cypress run

![](https://cdn-images-1.medium.com/max/2674/0*_jpXq7SIhFkjcfST.png)

After the command is run and test cases are executed successfully, you can view the Cypress test run on LambdaTest cloud platform (Just like shown in the screenshot below):

![](https://cdn-images-1.medium.com/max/3200/0*N2SHhmR0nQD9xUbw.png)

You can also view the logs by navigating to the logs section.

![](https://cdn-images-1.medium.com/max/3200/0*jn6PSzIVxmzxYqMT.png)

Until now, we learnt how to run [Cypress automation tests](https://www.lambdatest.com/cypress-ui-automation?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=webpage) on the LambdaTest cloud platform using the IDE terminal. Let’s see how to run the above flow using Cypress with GitHub Actions.

In order to run it using Cypress with GitHub Actions workflow, we will use the Cypress official GitHub Actions (**cypress-io/github-action@v4**), which either works on the script passed in the package.json or directly picks the cypress commands passed in the .yml file.

So, we will create a script in package.json. In order to run the Cypress test on the LambdaTest cloud platform, we need to run the command “***lambdatest-cypress run***”.

The same command, we will create as a script in package.json just as shown below:

  

```
  {
     "name": "cypress_github-actions-example",
     "version": "1.0.0",
     "description": "test automation using cypress",
     "main": "index.js",
     "scripts": {
       "test": "lambdatest-cypress run"
     },
     "repository": {
       "type": "git",
       "url": "https://github.com/Anshita-Bhasin/Cypress_Github-Actions.git"
     },
     "author": "Anshita Bhasin",
     "license": "ISC",
     "devDependencies": {
       "cypress": "^11.2.0"
     },
     "dependencies": {
       "lambdatest-cypress-cli": "^3.0.7"
     }}
```

To test if the above script is working fine, Go to the terminal and execute the command “*< npm run scriptname >*”

For the above code, the command would be ***npm run test***. If you see the tests result just as shown below, that means your script is absolutely working fine.

![](https://cdn-images-1.medium.com/max/2768/0*weeCvc4yJNeDIAi_.png)

To run the same using GitHub Actions.

 1. Go to the workflow .yml file. (We covered above, how to create a .yml workflow file)

 2. Pass the script name as a command :

   

```
 name: Cypress Cloud Tests
    on: [push]
    jobs:
     Cypress-Test:
       runs-on: ubuntu-latest
       steps:
         - name: Checkout GitCode
           uses: actions/checkout@v2
     
         - name: Run Cypress Test
           uses: cypress-io/github-action@v4
           with:
             command: npm run test
```

Command basically runs the Cypress command to execute the Cypress tests. It will check in package.json if there is a command with the name “test” and then it will run, else it will throw an error.

After creating the workflow, you can check the Actions tab in your GitHub Repository. It will show the summary of the workflow run.

![](https://cdn-images-1.medium.com/max/3200/0*3TuyTtCu9ersNwXe.png)

Now, navigate to the LambdaTest cloud platform to ensure whether tests are executed or not. You should be able to see the latest build on LambdaTest.

![](https://cdn-images-1.medium.com/max/3200/0*uuMb7-XsZHkDsHgH.png)

***Here’s a guide on how to [automate Android app testing using Appium](https://www.lambdatest.com/blog/how-to-automate-android-apps-using-appium/?utm_source=devto&utm_medium=organic&utm_campaign=jun23_kj&utm_term=kj&utm_content=blog), a powerful framework that can help you streamline your testing process. Learn more now.***

## How to run Cypress tests for the specific browser using GitHub Actions?

You can also run tests on different browsers using Cypress with GitHub Actions. Just provide the Cypress-supported browser name on which you want to run your test case. As part of the code below, I have passed Firefox. So, the test case would run on the Firefox browser but you can pass Chrome, Electron, or any other browser which Cypress supports.

   

```
 name: Cypress Test on Firefox
    on: [push]
    jobs:
     cypress-run:
       runs-on: ubuntu-20.04
      
       name: E2E Test on Firefox
       steps:
         - uses: actions/checkout@v2
         - uses: cypress-io/github-action@v4
           with:
             browser: firefox
```

Once the above workflow is executed, you can go to the Actions tab and view the logs where you should be able to see the browser name. It should be the same as passed in the workflow file. Below is the sample screenshot of the workflow logs:

![](https://cdn-images-1.medium.com/max/2440/0*EQ-aK0LdP3po6scN.png)

## How to run Cypress tests in Docker Container GitHub Actions?

You can also run the Cypress tests in your Docker Container using GitHub Actions. There is already a docker image available online with chrome version 78 and Firefox version 70 pre-installed. You can pass the container image using an argument container. After executing the test cases, it also stops the container.

Below is the sample code to run the Cypress test in the docker container using GitHub Actions:

    

```
name: Cypress Test in custom container
    on: [push]
    jobs:
     cypress-test:
       runs-on: ubuntu-20.04
       name: Cypress Tests on docker container
       # Cypress Docker image with Chrome v78
       # and Firefox v70 pre-installed
       container: cypress/browsers:node12.13.0-chrome78-ff70
       steps:
         - uses: actions/checkout@v2
         - uses: cypress-io/github-action@v4
           with:
             browser: chrome
```

## How to get the Cypress test run results using GitHub Actions Artifacts?

You can get the Cypress test result as an artifact after your workflow is executed. You can store the generated videos or screenshots as CI artifacts. Let’s take an example — you want videos of your test run after every run but you want screenshots only when your test fails. So, this can be done by passing conditions in the workflow. We will use GitHub Actions actions/upload-artifact@v2 for storing the artifacts and then will pass the condition to show the artifacts.

Below is the sample code.

   

```
 name: Cypress Artifacts
    on: [push]
    jobs:
     cypress-run:
       runs-on: ubuntu-latest
       name: Test Artifacts
       steps:
         - uses: actions/checkout@v2
         - uses: cypress-io/github-action@v4
         - uses: actions/upload-artifact@v2
           if: failure()
           with:
             name: cypress-screenshots
             path: ./cypress/screenshots
         - uses: actions/upload-artifact@v2
           if: always()
           with:
             name: cypress-videos
             path: ./cypress/videos
```

After your workflow is executed, you can check the artifacts from the summary of the workflow.

Click on the Actions tab. Select the action for the desired workflow run. Click the workflow and it will navigate to the summary page.

![](https://cdn-images-1.medium.com/max/3200/0*VdlxVU4gYDLtkpZA.png)

## Conclusion

Cypress is compatible with different CI tools available in the market but one of the leading ones is GitHub Actions. Cypress even has its official GitHub Action(cypress-io/github-action@v4.x.x) which installs the npm dependency and runs the Cypress test. Running your Cypress test case on CI/CD platform gives you leverage to schedule it and run it on different trigger events which save a lot of time.

As part of this blog on Cypress with GitHub Actions, we covered the scenarios where we executed the Cypress test cases using GitHub Actions and also covered running it on a cloud platform.

Stay tuned for the next topics on the Cypress with GitHub Actions Series. Where the topics like test case scheduling, slack notification, and uploading results on AWS S3 Bucket using GitHub Actions would be covered.