|
| 1 | +--- |
| 2 | +id: hyperexecute-karate-testing |
| 3 | +title: Karate Automation on HyperExecute |
| 4 | +hide_title: false |
| 5 | +sidebar_label: Karate |
| 6 | +description: Learn how to run Selenium automation tests on HyperExecute using the Karate framework |
| 7 | +keywords: |
| 8 | + - Karate |
| 9 | + - Karate selenium |
| 10 | + - Karate Java Selenium |
| 11 | + - Karate automation testing |
| 12 | + - selenium webdriver Karate |
| 13 | + - selenium Karate testing tutorial |
| 14 | + - Karate Java Selenium framework |
| 15 | + - lambdatest Karate |
| 16 | + - frameworks on lambdatest |
| 17 | + - hyperexecute |
| 18 | + - hyperexecute Karate testing |
| 19 | + - hyperexecute Karate testing |
| 20 | + - hyperexecute automation testing |
| 21 | + - HyperExecute Selenium automation |
| 22 | +url: https://www.lambdatest.com/support/docs/hyperexecute-karate-testing/ |
| 23 | +site_name: LambdaTest |
| 24 | +slug: hyperexecute-karate-testing/ |
| 25 | +--- |
| 26 | + |
| 27 | +import CodeBlock from '@theme/CodeBlock'; |
| 28 | +import {YOUR_LAMBDATEST_USERNAME, YOUR_LAMBDATEST_ACCESS_KEY} from "@site/src/component/keys"; |
| 29 | +import Tabs from '@theme/Tabs'; |
| 30 | +import TabItem from '@theme/TabItem'; |
| 31 | + |
| 32 | +<script type="application/ld+json" |
| 33 | + dangerouslySetInnerHTML={{ __html: JSON.stringify({ |
| 34 | + "@context": "https://schema.org", |
| 35 | + "@type": "BreadcrumbList", |
| 36 | + "itemListElement": [{ |
| 37 | + "@type": "ListItem", |
| 38 | + "position": 1, |
| 39 | + "name": "Home", |
| 40 | + "item": "https://www.lambdatest.com" |
| 41 | + },{ |
| 42 | + "@type": "ListItem", |
| 43 | + "position": 2, |
| 44 | + "name": "Support", |
| 45 | + "item": "https://www.lambdatest.com/support/docs/" |
| 46 | + },{ |
| 47 | + "@type": "ListItem", |
| 48 | + "position": 3, |
| 49 | + "name": "How to run automation tests on HyperExecute using Karate framework", |
| 50 | + "item": "https://www.lambdatest.com/support/docs/hyperexecute-karate-testing/" |
| 51 | + }] |
| 52 | + }) |
| 53 | + }} |
| 54 | +></script> |
| 55 | +Karate is a popular open-source test automation framework for API, performance, and UI testing. It combines API testing with BDD-style syntax and supports parallel execution. |
| 56 | + |
| 57 | +## 🚀 Why choose HyperExecute for Karate Testing? |
| 58 | +While Gatling is powerful on its own, running large-scale performance tests using traditional setups often introduces significant bottlenecks: |
| 59 | + |
| 60 | +### ⚠️ Challenges with Traditional Runners |
| 61 | +- **Limited Parallelism:** Local runners struggle to scale effectively across multiple CPU cores or nodes. |
| 62 | +- **Environment Inconsistencies:** Variations in environments lead to flaky tests and hard-to-reproduce bugs. |
| 63 | +- **Manual Test Orchestration:** Managing dependencies, execution order, and reporting manually is error-prone. |
| 64 | +- **Lack of Observability:** Debugging failures can be slow due to scattered logs and minimal visibility. |
| 65 | + |
| 66 | +### ✅ How HyperExecute Enhances Karate Testing |
| 67 | +LambdaTest’s HyperExecute platform eliminates these issues with a modern, cloud-native test runner that offers: |
| 68 | + |
| 69 | +- **⚡ Smart Test Distribution:** HyperExecute auto-splits Karate feature files across multiple nodes to optimize execution speed. |
| 70 | +- **🔒 Isolated Test Environments:** Each test job runs in a clean, sandboxed environment with controlled dependencies. |
| 71 | +- **📦 Seamless Artifact Upload:** Automatically captures and uploads Karate test reports for easier analysis. |
| 72 | +- **🔁 Built-in Retries & Stability Handling:** Reduce flakiness with automatic retries for failed test jobs. |
| 73 | +- **📈 Unified Dashboard & Logs:** Get centralized access to logs, artifacts, and test metadata for efficient debugging. |
| 74 | + |
| 75 | +## Prerequisites |
| 76 | +To run the Tests on HyperExecute from your Local System, you are required: |
| 77 | + |
| 78 | +- Your LambdaTest [Username and Access key](https://www.lambdatest.com/support/docs/hyperexecute-how-to-get-my-username-and-access-key/) |
| 79 | +- [HyperExecute YAML](https://www.lambdatest.com/support/docs/hyperexecute-yaml-version0.2/) file which contains all the necessary instructions. |
| 80 | +- [HyperExecute CLI](https://www.lambdatest.com/support/docs/hyperexecute-cli-run-tests-on-hyperexecute-grid/) in order to initiate a test execution Job . |
| 81 | +- Setup the [Environmental Variable](https://www.lambdatest.com/support/docs/hyperexecute-environment-variable-setup/) |
| 82 | + |
| 83 | +## Run a Sample Project |
| 84 | +### Step 1: Download Project |
| 85 | +You can use your own project to configure and test it. For demo purposes, we are using the sample repository. |
| 86 | + |
| 87 | +:::tip Sample repo |
| 88 | +Download or Clone the code sample for the Karate from the LambdaTest GitHub repository to run the tests on the HyperExecute. |
| 89 | + |
| 90 | +<a href="https://github.com/LambdaTest/hyperexecute-karate-sample/" className="github__anchor"><img loading="lazy" src={require('../assets/images/icons/github.png').default} alt="Image" className="doc_img"/> View on GitHub</a> |
| 91 | +::: |
| 92 | + |
| 93 | +### Step 2: Download the CLI in your Project |
| 94 | +Download the HyperExecute CLI and copy it into the root folder of the downloaded sample repository. |
| 95 | + |
| 96 | +| Platform | HyperExecute CLI | |
| 97 | +| ---------| ---------------- | |
| 98 | +| Linux | https://downloads.lambdatest.com/hyperexecute/linux/hyperexecute | |
| 99 | +| Windows | https://downloads.lambdatest.com/hyperexecute/windows/hyperexecute.exe | |
| 100 | +| macOS | https://downloads.lambdatest.com/hyperexecute/darwin/hyperexecute | |
| 101 | + |
| 102 | +### Step 3: Configyure `karate-config.js` file |
| 103 | +This file defines runtime behaviors and integrates Karate with LambdaTest status reporting. |
| 104 | + |
| 105 | +```javascript |
| 106 | +function fn() { |
| 107 | + var lambdaHooks = function() { |
| 108 | + if (karate.info.errorMessage) { |
| 109 | + script('lambda-status=failed'); |
| 110 | + } else { |
| 111 | + script('lambda-status=passed'); |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + var env = karate.env || 'dev'; |
| 116 | + karate.log('karate.env:', env); |
| 117 | + |
| 118 | + var config = { |
| 119 | + env: env, |
| 120 | + hub: karate.properties['hub'] |
| 121 | + }; |
| 122 | + |
| 123 | + karate.configure('afterScenario', lambdaHooks); |
| 124 | + |
| 125 | + return config; |
| 126 | +} |
| 127 | +``` |
| 128 | + |
| 129 | +:::note |
| 130 | +- `lambdaHooks` sets test status based on execution outcome. |
| 131 | +- `hub` is dynamically picked to support Selenium Grid for UI tests. |
| 132 | +- Supports environment-based configuration using `karate.env`. |
| 133 | +::: |
| 134 | + |
| 135 | + |
| 136 | +### Step 4: Create your hyperexecute.yml file |
| 137 | +The core of HyperExecute configuration lies in the `hyperexecute.yaml` file. Let’s break down the structure and understand each section: |
| 138 | + |
| 139 | +#### 1. Environment & Runtime Setup |
| 140 | +This section specifies the OS, runtime language, concurrency, and autosplit features: |
| 141 | + |
| 142 | +```yaml |
| 143 | +version: 0.1 |
| 144 | +runson: linux # OS to run the tests (e.g., linux, win) |
| 145 | +autosplit: true |
| 146 | +concurrency: 2 # Defines the number of test sessions to run concurrently |
| 147 | + |
| 148 | +runtime: |
| 149 | + language: java |
| 150 | + version: 11 |
| 151 | +``` |
| 152 | +
|
| 153 | +#### 2. Dependency Resolution with Maven |
| 154 | +Before running the actual performance test, ensure all project dependencies are resolved locally for a reproducible build. This step pulls all required Maven dependencies to a local directory (.m2), ensuring environment consistency. |
| 155 | +
|
| 156 | +```yaml |
| 157 | +pre: |
| 158 | + - mvn -Dmaven.repo.local=./.m2 dependency:resolve |
| 159 | +``` |
| 160 | +
|
| 161 | +#### 3. Configure Test Discovery |
| 162 | +Test discovery determines what files or test suites should be run. Use the [snooper](https://www.lambdatest.com/support/docs/hyperexecute-snooper/) utility to identify test files dynamically. |
| 163 | +
|
| 164 | +```yaml |
| 165 | +testDiscovery: |
| 166 | + type: raw |
| 167 | + mode: static |
| 168 | + command: snooper --targetOs=win --featureFilePaths=src/test/java/app --frameWork=java | sed 's/:.*//' | uniq |
| 169 | +``` |
| 170 | +
|
| 171 | +> You can change discovery logic to run at the scenario, tag, or step definition level based on your need. |
| 172 | +
|
| 173 | +#### 4. Configure the Test Execution Command |
| 174 | +The execution command uses Maven and passes feature file paths from discovery: |
| 175 | +
|
| 176 | +```yaml |
| 177 | +testRunnerCommand: mvn test -Dtest=MyApiRunner -DFeaturePath="$test" -Dhub=https://LT_USERNAME:LT_ACCESS_KEY@hub.lambdatest.com/wd/hub -Dmaven.repo.local=./.m2 |
| 178 | +``` |
| 179 | +
|
| 180 | +Here is a complete working YAML configuration that runs Gatling performance tests on linux runners via HyperExecute: |
| 181 | +
|
| 182 | +```yaml reference title="hyperexecute.yaml" |
| 183 | +https://github.com/LambdaTest/hyperexecute-karate-sample/blob/main/HyperExecute.yaml |
| 184 | +``` |
| 185 | + |
| 186 | +> 📘 For a deeper understanding and project-specific configurations, check out the [YAML documentation](https://www.lambdatest.com/support/docs/hyperexecute-yaml-parameters/). |
| 187 | +
|
| 188 | +### Step 5: Execute your Test Suite |
| 189 | +From the project root directory, execute the below CLI command in your terminal: |
| 190 | + |
| 191 | +<div className="lambdatest__codeblock"> |
| 192 | + <CodeBlock className="language-bash"> |
| 193 | + {`./hyperexecute --user ${ YOUR_LAMBDATEST_USERNAME()} --key ${ YOUR_LAMBDATEST_ACCESS_KEY()} --config hyperexecute.yaml`} |
| 194 | + </CodeBlock> |
| 195 | +</div> |
| 196 | + |
| 197 | +> **NOTE :** In case of macOS, if you get a permission denied warning while executing CLI, simply run **`chmod u+x ./hyperexecute`** to allow permission. In case you get a security popup, allow it from your **System Preferences** → **Security & Privacy** → **General tab**. |
| 198 | +
|
| 199 | +<img loading="lazy" src={require('../assets/images/hyperexecute/frameworks/karate/karate.png').default} alt="automation-dashboard" width="1920" height="868" className="doc_img"/> |
| 200 | + |
| 201 | +## Advanced Parameters |
| 202 | +Optimize your test pipeline using the following advanced features: |
| 203 | + |
| 204 | +- ✅ [Smart Test Splitting](/support/docs/hyperexecute-test-splitting-and-multiplexing/) – Automatically distribute tests across parallel runners |
| 205 | +- ⚡ [Fail Fast](/support/docs/hyperexecute-failfast/) – Stop test runs on the first failure |
| 206 | +- 📊 [Detailed Reports](/support/docs/hyperexecute-reports/) – Real-time terminal logs & rich test reports |
0 commit comments