DEV Community

keploy
keploy

Posted on • Originally published at keploy.io

Continuous UI Testing Pipeline: BrowserStack with GitHub Actions

Image description
Did you know 88% of users don’t return to sites with poor experiences, even if they offer excellent services and content? It’s time to recognize that a seamless user interface (UI) and user experience (UX) are essential to a product or company’s success, not mere luxuries.

This is where Continuous UI Testing steps in. Ditching the conventional testing approaches, continuous UI testing integrates itself into almost every step of development & deployment. This not only ensures perfection for all browsers and devices but also achieves precision without slowing down your development pipeline.

In this blog, we’ll explore the role BrowserStack and GitHub Actions. The former (BrowserStack) allows you to run automated tests on real browsers & devices and ensures unparalleled accuracy. Whereas, GitHub Actions, on the other hand, automates this process, by triggering your testing workflows seamlessly whenever you push code. Let’s explore how.

Why is Continuous UI Testing so Essential?

In today’s dynamic environments, neglecting periodic UI testing leads to issues like:

  • Broken Layouts: Small changes in the code can inadvertently disrupt the design, misplace elements, or cause unresponsive interfaces.

  • Faulty cross-browser compatibility: Your application might seamlessly work in one browser, and end up breaking in another. This can be particularly frustrating for users.

  • Poor user experience: It takes seconds to drive users away with a glitchy interface. This directly impacts your brand reputation and revenue.

In any given CI/CD workflow, the risk multiplies with every continuous change in the code. A regular UI Consistency check can highlight such issues & risks before time. It’s practically feasible to invest in these tests and checks at a building stage, without carrying the headache of expensive fixes, last-minute changes, customer churn, and delayed releases.

Some high-scale Benefits of Consistent UI Checks are:

  • Enhanced development speed: If focusing on the long-run path, you do not debug randomly, but solve breakage in your code at the very stage of building. Automated testing enhances speed and innovation.

  • Higher reliability: Continuous testing certainly shrinks the UI bugs that might’ve slipped into production. So, you finally have a consistent performance across all environments!

Manual Testing vs. Continuous UI Testing:

Aspect Continuous UI Testing Manual Test Techniques
Execution Time Automated & faster Slow & resource-intensive
Coverage Comprehensive across browsers and devices Limited to selected devices
Scalability Scalable with CI/CD workflows. Difficult to scale with frequent changes
Error Detection Consistent & accurate error detection Prone to human & other errors
Cost Efficiency Lower with automation. Expensive over time due to manual effort

What is BrowserStack ?

BrowserStack is known to be a leading cloud-based testing platform, which essentially lets developers test their applications across a vast range of browsers, operating systems, and devices. It’s a perfect replacement for any in-house device lab. BrowserStack’s additional benefits include:

  • Visual Tests for your platform: Helps you with a consistent user experience without bothering about platform fragmentation. Seamless detection of visual regressions and enables pixel-perfect designs.

  • Supports Automated Testing: You can easily run Cypress, Selenium, or any other test framework on BrowserStack for clean and robust UI validation.

  • Cross-Browser & Device Testing: Validates a seamless run across different browsers and versions across different devices.

What is GitHub Actions?

It’s an automation tool that seamlessly integrates with GitHub. ‘Actions’ helps developers to initiate, manage, and trigger the workflows, specifically based on code pushes, PRs (pull requests), or scheduled triggers. Some key features of GitHub Actions are:

  • Parallel Execution: It essentially helps in running jobs concurrently for saving time and accelerate delivery.

  • Customizable Pipelines: Actions can be so efficient in defining your project workflows by using YAML files tailored to any specific CI/CD needs.

  • Wide Integration: You can seamlessly combine with third-party tools like BrowserStack, or AWS , etc. for any kind of comprehensive automation.

  • Event-Driven Workflows: Probably the best part, it allows task automation, based on repository events, like running tests or deploying your repository code.

Prerequisites :

Following is a list of tools that you will require in order to perform the set-up of interface testing with BrowserStack and GitHub Actions:

  • A GitHub repository.

  • Access to BrowserStack (Automate).

  • Selenium/Cypress test scripts (or an example script provided in the blog).

How BrowserStack Integrates with GitHub Actions?

After finally understanding the key deliverables of choosing BrowserStack and GitHub Actions, we can conclude that together they can prove to be effectively robust & automated. Read further to learn how clean it could make your UI testing run on different devices and browsers. Welcome to the Step-by-Step Technical walkthrough for the integration process:

Step-1 : Event Triggering: Activating Your Workflow
Step-2 : Code Checkout: Preparing the Test Environment
Step-3 : Test Execution on BrowserStack: Running UI Tests
Step-4 : Results Collection and Reporting

Let’s see detailed approach for each of the four steps given above:

Step-1: Event Trigger: Activating Your Workflow

By stating “event-driven”, we essentially mean that the workflows in GitHub Actions are triggered by the repository event. It works like a doorbell—nothing happens until it is activated, triggering a predefined response.

Similar to that, GitHub Actions has a couple of events by which it could trigger the workflow in a certain way (depending on the event). Some examples are:

    • Push: Code is pushed to specific branches (e.g., main, develop,etc.)

      * Pull Request (PR): Initiating, syncing, or merging the pull requests.

      * Delete: When a branch or tag is deleted.

You can understand these example events with the help of a configuration in any given .yml file:

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main
  delete:  # Trigger workflow when a branch or tag is deleted
Enter fullscreen mode Exit fullscreen mode

Step-2: Code Checkout: Preparing the Test Environment

Now, the upcoming step in this process is using the workflow in GitHub Actions to fetch your repository codebase. We can fo it with actions/checkout action, which will further ensure that all test scripts and configuration files of your repository are succesfully available for execution.

An example of YAML snippet for this could be:

steps:
  - name: Checkout Repository
    uses: actions/checkout@v3
Enter fullscreen mode Exit fullscreen mode

💡
By default, the checkout action fetches only the latest commit to speed up workflows. Use fetch-depth: 0 for full repository history if required.

Step-3: Test Execution on BrowserStack: Running UI Tests

The key essence of integrating BrowserStack with GitHub Actions lies within executing UI tests seamlessly on BrowserStack’s powerful infrastructure. This crucial set-up allows the developers to automate any type of cross-browser testing, pretty efficiently. As a result, you get a consistent performance of your application across any varying environment. Here's in detail how test execution is configured in BrowserStack:

  1. Set-Up BrowserStack Credentials:
* Authenticating test execution will require Access Keys.

* We store these Access Keys securely as ‘GitHub Secrets’ (`BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY`):
Enter fullscreen mode Exit fullscreen mode
    ```yaml
    steps:
      - name: Set BrowserStack Credentials
        env:
          BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
          BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
    ```
Enter fullscreen mode Exit fullscreen mode
  1. Installing Dependencies:
* You must then install the project dependencies based on your project (e.g., Selenium, Cypress). This `.yml` file could be an example:
Enter fullscreen mode Exit fullscreen mode
    ```yaml
    steps:
      - name: Install Dependencies
        run: |
          npm install
          npm run build
    ```
Enter fullscreen mode Exit fullscreen mode
  1. Executing Tests via BrowserStack CLI or API:
* Configure the test runner to execute on BrowserStack Automate:  
    Example for Selenium:
Enter fullscreen mode Exit fullscreen mode
    ```yaml
    steps:
      - name: Run Selenium Tests on BrowserStack
        run: |
          npx selenium-standalone start &
          npm test
    ```
Enter fullscreen mode Exit fullscreen mode
* Example for Cypress (via BrowserStack Cypress CLI):
Enter fullscreen mode Exit fullscreen mode
    ```yaml
    steps:
      - name: Run Cypress Tests on BrowserStack
        run: |
          browserstack-cypress run --sync
    ```
Enter fullscreen mode Exit fullscreen mode

Step-4: Results Collection and Reporting

BrowserStack, as mentioned above, serves with the perfect report and analytics, by generating it comprehensively for you. These significantly include:

  • Execution Logs: a set of step-by-step logs for debugging.

  • Screenshots: Captures critical test steps and submits it to you.

  • Videos: Full recordings of test executions that were done in real-time.

  • Test Status: Highlights of the passed, failed, and skipped tests of your application.

The mentioned artifacts could easily be linked to the GitHub Actions workflow for easy accessibility. Here’s how we do it for instance of a .yml file.

steps:
  - name: Upload Artifacts
    uses: actions/upload-artifact@v3
    with:
      name: test-results
      path: ./path-to-results
Enter fullscreen mode Exit fullscreen mode

Advanced Features of Integration

  1. Parallel Test Execution:

    Run multiple test cases concurrently on different browsers and devices using BrowserStack Automate’s parallel testing capabilities. This can be configured via the test framework’s settings (e.g., maxInstances in Selenium).

  2. Dynamic Browser and Device Matrix:

    Define the testing matrix dynamically using JSON configurations, enabling easy updates to browsers and devices under test:

    {
      "browsers": [
        { "browser": "Chrome", "os": "Windows", "os_version": "10" },
        { "browser": "Safari", "os": "OS X", "os_version": "Monterey" }
      ]
    }
    
  3. Error Notifications:

    Set up notifications for workflow failures using integrations like Slack or email:

    steps:
      - name: Notify Slack
        uses: slackapi/slack-github-action@v1.23.0
        with:
          payload: '{"text":"UI Tests failed on GitHub Actions!"}'
    

Technical Diagram

Below is a diagram illustrating an integrated workflow

  1. GitHub Event: Code push or pull request triggers the workflow.

  2. CI Pipeline: GitHub Actions fetches the code and dependencies.

  3. BrowserStack Execution: Tests run on BrowserStack Automate.

  4. Test Results: Logs, screenshots, and reports are generated and linked back to the workflow.

By leveraging the seamless integration of BrowserStack and GitHub Actions, teams can automate their UI testing, ensuring comprehensive coverage across devices and browsers while accelerating their CI/CD pipelines.

This integration streamlines UI testing, enabling teams to identify issues early and deliver high-quality applications faster.

Pro Tips to Enhance Your UI Testing Efficiency

  1. Leverage Parallel Testing: Speed up your test cycles by running tests across multiple browsers and devices simultaneously, reducing runtime and improving coverage.

  2. Implement Retry Mechanisms: Implement retries to reduce flaky test impact, ensuring consistent results.

  3. Adopt Visual Regression Testing: Use tools like Percy to catch unintended UI changes by comparing visual snapshots, ensuring a seamless user interface.

Common Issues and How to Resolve Them

When implementing continuous UI testing, you might encounter several common challenges. Here are a few along with troubleshooting tips to resolve them:

  1. Flaky Tests:
* **Issue**: Flaky tests often result from network latency or timing issues.

* **Resolution**:

    * Implement **retry mechanisms** to handle intermittent failures.

    * Use **explicit waits** in your test scripts to ensure elements are loaded before interacting with them.

    * Regularly clean up test environments to avoid side effects from previous tests.
Enter fullscreen mode Exit fullscreen mode
  1. Configuration Errors:
* **Issue**: Misconfigured GitHub Actions workflows, such as incorrect paths or wrong credentials, can cause your tests to fail.

* **Resolution**:

    * Double-check your YAML file for syntax errors and verify that all paths to your scripts or dependencies are correct.

    * Ensure that **BrowserStack credentials** are properly stored as **GitHub Secrets**.

    * Review logs for clear error messages and verify dependencies are correctly installed during the workflow setup.
Enter fullscreen mode Exit fullscreen mode
  1. Browser Compatibility Issues
* Issue: UI tests might pass in one browser but fail in others due to differences in rendering engines or CSS support.

  • Resolution:

    • Use cross-browser testing tools like BrowserStack to test across multiple browsers and versions simultaneously.
    • Implement browser-specific test cases to account for differences in layout, behavior, and JavaScript support.
    • Regularly update your browser configurations to include the latest versions.
Enter fullscreen mode Exit fullscreen mode

Best Practices that you can adopt in this case:

  • Maintain a Stable Test Environment: Set up dedicated testing environments to ensure consistent results.

  • Monitor Test Performance: Keep an eye on test execution time and avoid running unnecessary tests.

  • Review Logs: Always inspect logs when tests fail to get clear insights into what went wrong.

  • Test in Parallel: To improve efficiency and coverage, test across multiple browsers and devices at once.

By addressing these common issues and following best practices, you can improve the reliability of your UI tests and ensure a smoother testing experience.

Keploy: Simplifying Test Automation with a Focus on Speed and Accuracy

Keploy is an open-source, no-code testing platform designed to streamline test generation and execution for modern applications. By automatically capturing API interactions, it helps generate reliable and comprehensive test cases without manual intervention.

Why Use Keploy in Continuous UI Testing?

  1. Automated Test Creation: Keploy automatically generates test cases by recording API calls during runtime, reducing the need for manual scripting.

  2. Regression Testing: It ensures your application maintains consistent performance by detecting and flagging deviations.

  3. Seamless CI/CD Integration: Keploy works alongside tools like GitHub Actions and BrowserStack, enhancing the efficiency of your CI/CD pipelines.

  4. Faster Iterations: Its ability to reduce time spent on test scripting allows teams to focus on development and innovation.

Use Case:

Pairing Keploy with BrowserStack offers a comprehensive testing solution, covering both APIs and UI elements for consistent cross-platform performance. By incorporating Keploy into your workflow, you can further enhance testing efficiency and accelerate delivery while maintaining top-notch application quality.

Conclusion

Continuous UI testing is no longer a luxury but a necessity in today’s fast-paced development environment. Tools like BrowserStack and GitHub Actions empower teams to deliver seamless, cross-platform user experiences by automating complex testing processes. These integrations enable faster development cycles, higher reliability, and reduced costs, ensuring your application meets the highest quality standards.

By pairing these tools with innovative platforms like Keploy, you can take your testing strategy to the next level catching both UI and API-level issues early in the development cycle. This not only accelerates your CI/CD pipeline but also strengthens your application’s overall resilience and user satisfaction.

Resources -

  • BrowserStack Documentation

  • GitHub Actions Documentation

  • Cross-Browser Testing with BrowserStack

Top comments (0)