From ec4ae8b4e14cc077ae5e8c98569557560b46bb6e Mon Sep 17 00:00:00 2001 From: Alhussein Ibrahim Date: Wed, 26 Feb 2025 11:30:48 +0100 Subject: [PATCH 01/17] feat: replace SUT in java scripting intro --- ...seSimulation.java => EcommSimulation.java} | 17 ++-- .../code/ScriptingIntro1SampleJava.java | 4 +- .../code/ScriptingIntro2SampleJava.java | 7 +- .../code/ScriptingIntro3SampleJava.java | 11 ++- .../code/ScriptingIntro4SampleJava.java | 17 ++-- content/tutorials/scripting-intro/index.md | 80 +++++++++---------- 6 files changed, 64 insertions(+), 72 deletions(-) rename content/tutorials/scripting-intro/code/{ComputerDatabaseSimulation.java => EcommSimulation.java} (68%) diff --git a/content/tutorials/scripting-intro/code/ComputerDatabaseSimulation.java b/content/tutorials/scripting-intro/code/EcommSimulation.java similarity index 68% rename from content/tutorials/scripting-intro/code/ComputerDatabaseSimulation.java rename to content/tutorials/scripting-intro/code/EcommSimulation.java index e9848be0..08488f72 100644 --- a/content/tutorials/scripting-intro/code/ComputerDatabaseSimulation.java +++ b/content/tutorials/scripting-intro/code/EcommSimulation.java @@ -15,7 +15,7 @@ */ //#full-example -package computerdatabase; +package ecomm; import static io.gatling.javaapi.core.CoreDsl.*; import static io.gatling.javaapi.http.HttpDsl.*; @@ -23,21 +23,18 @@ import io.gatling.javaapi.core.*; import io.gatling.javaapi.http.*; -public class ComputerDatabaseSimulation extends Simulation { +public class EcommSimulation extends Simulation { - HttpProtocolBuilder httpProtocol = - http.baseUrl("https://computer-database.gatling.io") - .acceptHeader("application/json") - .contentTypeHeader("application/json"); + HttpProtocolBuilder httpProtocol = http.baseUrl("https://ecomm.gatling.io") + .acceptHeader("application/json"); ScenarioBuilder myFirstScenario = scenario("My First Scenario") - .exec(http("Request 1") - .get("/computers/")); + .exec(http("Request 1") + .get("/products/")); { setUp( - myFirstScenario.injectOpen(constantUsersPerSec(2).during(60)) - ).protocols(httpProtocol); + myFirstScenario.injectOpen(constantUsersPerSec(2).during(60))).protocols(httpProtocol); } } //#full-example diff --git a/content/tutorials/scripting-intro/code/ScriptingIntro1SampleJava.java b/content/tutorials/scripting-intro/code/ScriptingIntro1SampleJava.java index 4f46bd95..33999f66 100644 --- a/content/tutorials/scripting-intro/code/ScriptingIntro1SampleJava.java +++ b/content/tutorials/scripting-intro/code/ScriptingIntro1SampleJava.java @@ -15,7 +15,7 @@ */ //#setup-the-file -package computerdatabase; +package ecomm; import static io.gatling.javaapi.core.CoreDsl.*; import static io.gatling.javaapi.http.HttpDsl.*; @@ -26,7 +26,7 @@ class ScriptingIntro1SampleJava { //#extend-the-simulation-class - public class ComputerDatabaseSimulation extends Simulation { + public class EcommSimulation extends Simulation { } //#extend-the-simulation-class diff --git a/content/tutorials/scripting-intro/code/ScriptingIntro2SampleJava.java b/content/tutorials/scripting-intro/code/ScriptingIntro2SampleJava.java index 4d1b8c6f..73ec1a59 100644 --- a/content/tutorials/scripting-intro/code/ScriptingIntro2SampleJava.java +++ b/content/tutorials/scripting-intro/code/ScriptingIntro2SampleJava.java @@ -22,13 +22,12 @@ class ScriptingIntro2SampleJava { //#define-the-protocol-class - public class ComputerDatabaseSimulation extends Simulation { + public class EcommSimulation extends Simulation { // Add the HttpProtocolBuilder: - HttpProtocolBuilder httpProtocol = - http.baseUrl("https://computer-database.gatling.io") + HttpProtocolBuilder httpProtocol = http.baseUrl("https://ecomm.gatling.io") // set the "accept" header to a value suited for the expected response - .acceptHeader("text/html"); + .acceptHeader("application/json"); } //#define-the-protocol-class } diff --git a/content/tutorials/scripting-intro/code/ScriptingIntro3SampleJava.java b/content/tutorials/scripting-intro/code/ScriptingIntro3SampleJava.java index 05faa009..39f6bf82 100644 --- a/content/tutorials/scripting-intro/code/ScriptingIntro3SampleJava.java +++ b/content/tutorials/scripting-intro/code/ScriptingIntro3SampleJava.java @@ -22,16 +22,15 @@ class ScriptingIntro3SampleJava { //#write-the-scenario - public class ComputerDatabaseSimulation extends Simulation { + public class EcommSimulation extends Simulation { - HttpProtocolBuilder httpProtocol = - http.baseUrl("https://computer-database.gatling.io") - // set the "accept" header to a value suited for the expected response - .acceptHeader("text/html"); + HttpProtocolBuilder httpProtocol = http.baseUrl("https://ecomm.gatling.io") + // set the "accept" header to a value suited for the expected response + .acceptHeader("application/json"); // Add the ScenarioBuilder: ScenarioBuilder myScenario = scenario("My Scenario") - .exec(http("Request 1").get("/computers/")); + .exec(http("Request 1").get("/products/")); } //#write-the-scenario } diff --git a/content/tutorials/scripting-intro/code/ScriptingIntro4SampleJava.java b/content/tutorials/scripting-intro/code/ScriptingIntro4SampleJava.java index a523ae9d..e659adcd 100644 --- a/content/tutorials/scripting-intro/code/ScriptingIntro4SampleJava.java +++ b/content/tutorials/scripting-intro/code/ScriptingIntro4SampleJava.java @@ -22,23 +22,20 @@ class ScriptingIntro4SampleJava { //#define-the-injection-profile - public class ComputerDatabaseSimulation extends Simulation { + public class EcommSimulation extends Simulation { - HttpProtocolBuilder httpProtocol = - http.baseUrl("https://computer-database.gatling.io") - // set the "accept" header to a value suited for the expected response - .acceptHeader("text/html"); + HttpProtocolBuilder httpProtocol = http.baseUrl("https://ecomm.gatling.io") + // set the "accept" header to a value suited for the expected response + .acceptHeader("application/json"); ScenarioBuilder myScenario = scenario("My Scenario") - .exec( - http("Request 1").get("/computers/") - ); + .exec( + http("Request 1").get("/products/")); // Add the setUp block: { setUp( - myScenario.injectOpen(constantUsersPerSec(2).during(60)) - ).protocols(httpProtocol); + myScenario.injectOpen(constantUsersPerSec(2).during(60))).protocols(httpProtocol); } } //#define-the-injection-profile diff --git a/content/tutorials/scripting-intro/index.md b/content/tutorials/scripting-intro/index.md index d62e2e9e..a9cbfd42 100644 --- a/content/tutorials/scripting-intro/index.md +++ b/content/tutorials/scripting-intro/index.md @@ -12,10 +12,10 @@ This guide is intended for Gatling versions `{{< var gatlingVersion >}}` and lat Gatling is a highly flexible load-testing platform. You can write load tests in Java, Kotlin, and Scala or use our [no-code feature](https://gatling.io/features/no-code-generator/) with Gatling Enterprise. In this guide, we cover a "Hello world"-style example of how to: - - [install and setup your local dev environment]({{< ref "#install-gatling" >}}), - - [write your first simulation]({{< ref "#simulation-construction" >}}), - - [run a simulation on Gatling Enterprise Cloud]({{< ref "#run-the-simulation-on-gatling-enterprise-cloud" >}}), - - [run the simulation locally for debugging]({{< ref "#run-the-simulation-locally-for-debugging" >}}). +- [install and setup your local dev environment]({{< ref "#install-gatling" >}}), +- [write your first simulation]({{< ref "#simulation-construction" >}}), +- [run a simulation on Gatling Enterprise Cloud]({{< ref "#run-the-simulation-on-gatling-enterprise-cloud" >}}), +- [run the simulation locally for debugging]({{< ref "#run-the-simulation-locally-for-debugging" >}}). {{< alert tip >}} Join the [Gatling Community Forum](https://community.gatling.io) to discuss load testing with other users. Please try to find answers in the documentation before asking for help. @@ -33,13 +33,13 @@ This section guides you through installation and setting up your developer envir - CI/CD integrations, - Java, Kotlin, and Scala SDKs -This guide uses the Java SDK with the Maven wrapper. Gatling recommends that developers use the Java SDK unless they are already experienced with Scala or Kotlin. Java is widely taught in CS courses, requires less CPU for compiling, and is easier to configure in Maven and Gradle. You can adapt the steps to your development environment using reference documentation links provided throughout the guide. +This guide uses the Java SDK with the Maven wrapper. Gatling recommends that developers use the Java SDK unless they are already experienced with Scala or Kotlin. Java is widely taught in CS courses, requires less CPU for compiling, and is easier to configure in Maven and Gradle. You can adapt the steps to your development environment using reference documentation links provided throughout the guide. ### Sign up for Gatling Enterprise Cloud Gatling Enterprise Cloud is a fully managed SaaS solution for load testing. Sign up for a [trial account](https://auth.gatling.io/auth/realms/gatling/protocol/openid-connect/registrations?client_id=gatling-enterprise-cloud-public&response_type=code&scope=openid&redirect_uri=https%3A%2F%2Fcloud.gatling.io%2Fr%2Fgatling) to run your first test on Gatling Enterprise Cloud. The [Gatling website](https://gatling.io/features) has a full list of Enterprise features. -### Install Gatling +### Install Gatling {{< alert info >}} **Prerequisites** @@ -52,48 +52,48 @@ This guide uses the Gatling Java SDK with Maven, which is accessed by downloadin https://github.com/gatling/gatling-maven-plugin-demo-java/archive/refs/heads/main.zip {{< /button >}} -## Simulation construction +## Simulation construction This guide introduces the basic Gatling HTTP features. Gatling provides a cloud-hosted web application -[https://computer-database.gatling.io](https://computer-database.gatling.io) for running sample simulations. You'll learn how to construct simulations +[https://ecomm.gatling.io](https://ecomm.gatling.io) for running sample simulations. You'll learn how to construct simulations using the Java SDK. Code examples for the Kotlin and Scala SDKs are available throughout the Documentation. ### Learn the simulation components A Gatling simulation consists of the following: -- importing Gatling classes, +- importing Gatling classes, - configuring the protocol (commonly HTTP), -- describing a scenario, +- describing a scenario, - setting up the injection profile (virtual user profile). The following procedure teaches you to develop the simulation from each constituent component. If you want to skip ahead and copy the final simulation, jump to [Test execution]({{< ref "#test-execution" >}}). Learn more about simulations in the -[Documentation]({{< ref "/reference/script/core/simulation" >}}). +[Documentation]({{< ref "/reference/script/core/simulation" >}}). -#### Setup the file +#### Setup the file Once you have downloaded and extracted the Gatling `zip` file, open the project in your integrated development -environment (IDE). Gatling recommends the [IntelliJ community edition](https://www.jetbrains.com/idea/download/). +environment (IDE). Gatling recommends the [IntelliJ community edition](https://www.jetbrains.com/idea/download/). -1. Navigate to and open `src/test/java/computerdatabase/ComputerDatabaseSimulation.java`. +1. Navigate to and open `src/test/java/ecomm/EcommSimulation.java`. 2. Modify the simulation by deleting everything below line 7 `import io.gatling.javaapi.http.*;`. 3. The simulation should now look like the following: {{< include-code "ScriptingIntro1Sample#setup-the-file" java >}} -#### Extend the `Simulation` class +#### Extend the `Simulation` class -You must extend Gatling's `Simulation` class to write a script. To extend the `Simulation` class, after the import statements, add: +You must extend Gatling's `Simulation` class to write a script. To extend the `Simulation` class, after the import statements, add: {{< include-code "ScriptingIntro1Sample#extend-the-simulation-class" java >}} #### Define the protocol class -Inside the `ComputerDatabaseSimulation` class, add an `HTTP protocol` class. Learn about all of the +Inside the `EcommSimulation` class, add an `HTTP protocol` class. Learn about all of the `HttpProtocolBuilder` options in the [Documentation]({{< ref "/reference/script/protocols/http/protocol" >}}). For -this example, the `baseUrl` property is hardcoded as the Gatling computer database test site, and the `acceptHeader` and -contentTypeHeader` properties are set to `application/json`. +this example, the `baseUrl` property is hardcoded as the Gatling e-commerce test site, and the `acceptHeader` and +contentTypeHeader`properties are set to`application/json`. {{< include-code "ScriptingIntro2Sample#define-the-protocol-class" java >}} @@ -101,53 +101,53 @@ contentTypeHeader` properties are set to `application/json`. The next step is to describe the user journey. For a web application, this usually consists of a user arriving at the application and then a series of interactions with the application. The following scenario mocks a user arriving on the -home page of the [Gatling sample application](https://computer-database.gatling.io). +home page of the [Gatling sample application](https://ecomm.gatling.io). {{< include-code "ScriptingIntro3Sample#write-the-scenario" java >}} See the [Documentation]({{< ref "/reference/script/core/scenario" >}}) for the available scenario -components. +components. #### Define the injection profile The final component of a Gatling simulation is the injection profile. The injection profile is contained in the `setUp` block. The following example adds 2 users per second for 60 seconds. See the -[Documentation]({{< ref "/reference/script/core/injection" >}}) for all of the injection profile options. +[Documentation]({{< ref "/reference/script/core/injection" >}}) for all of the injection profile options. {{< include-code "ScriptingIntro4Sample#define-the-injection-profile" java >}} Congrats! You have written your first Gatling simulation. The next step is to learn how to run the simulation locally -and on Gatling Enterprise Cloud. +and on Gatling Enterprise Cloud. ## Test execution -Now, you should have a completed simulation that looks like the following: +Now, you should have a completed simulation that looks like the following: -{{< include-code "ComputerDatabaseSimulation#full-example" java >}} +{{< include-code "EcommSimulation#full-example" java >}} ### Run the Simulation on Gatling Enterprise Cloud Gatling Enterprise Cloud is a feature-rich SaaS platform that is designed for teams and organizations to get the most -out of load testing. With the trial account, you created in the [Prerequisites section]({{< ref "#install-gatling" >}}), you can upload and run your test with advanced configuration, reporting, and collaboration features. +out of load testing. With the trial account, you created in the [Prerequisites section]({{< ref "#install-gatling" >}}), you can upload and run your test with advanced configuration, reporting, and collaboration features. From Gatling 3.11 packaging and running simulations on Gatling Enterprise Cloud is simplified by using [configuration as code]({{< ref "reference/execute/cloud/user/configuration-as-code" >}}). In this tutorial, we only use the default configuration to demonstrate deploying your project. You can learn more about customizing your configuration with our [configuration-as-code guide]({{< ref "guides/config-as-code" >}}). -To deploy and run your simulation on Gatling Enterprise Cloud, use the following procedure: +To deploy and run your simulation on Gatling Enterprise Cloud, use the following procedure: -1. Generate an [API token]({{< ref "/reference/execute/cloud/admin/api-tokens" >}}) with the `Configure` permission in your Gatling Enterprise Cloud account. +1. Generate an [API token]({{< ref "/reference/execute/cloud/admin/api-tokens" >}}) with the `Configure` permission in your Gatling Enterprise Cloud account. 2. Add the API token to your current terminal session by replacing `` with the API token generated in step 1 and running the following command: - {{< platform-toggle >}} - Linux/MacOS: export GATLING_ENTERPRISE_API_TOKEN= - Windows: set GATLING_ENTERPRISE_API_TOKEN= - {{}} + {{< platform-toggle >}} + Linux/MacOS: export GATLING_ENTERPRISE_API_TOKEN= + Windows: set GATLING_ENTERPRISE_API_TOKEN= + {{}} 3. Run the following command in your terminal to deploy and start your simulation: - {{< platform-toggle >}} - Linux/MacOS: ./mvnw gatling:enterpriseStart - Windows: mvnw.cmd gatling:enterpriseStart - {{}} + {{< platform-toggle >}} + Linux/MacOS: ./mvnw gatling:enterpriseStart + Windows: mvnw.cmd gatling:enterpriseStart + {{}} Watch the Simulation deploy automatically and generate real-time reports. @@ -164,12 +164,12 @@ Windows: mvnw.cmd gatling:test Select `1 Run the Simulation locally` to start the test. -When the test has finished, there is an HTML link in the terminal that you can use to access the static report. +When the test has finished, there is an HTML link in the terminal that you can use to access the static report. ## Keep learning You have successfully run your first test! To keep learning, we recommend the following resources: - - [Gatling Academy](https://gatling.io/academy) - - [Introduction to the Recorder]({{< ref "recorder" >}}) - - [Writing realistic tests]({{< ref "advanced" >}}) +- [Gatling Academy](https://gatling.io/academy) +- [Introduction to the Recorder]({{< ref "recorder" >}}) +- [Writing realistic tests]({{< ref "advanced" >}}) From 32d192a1b3ffc80cff050f47e8fc50654302206e Mon Sep 17 00:00:00 2001 From: Alhussein Ibrahim Date: Wed, 26 Feb 2025 11:30:48 +0100 Subject: [PATCH 02/17] chore: remove gatling academy reference --- content/tutorials/scripting-intro/index.md | 1 - 1 file changed, 1 deletion(-) diff --git a/content/tutorials/scripting-intro/index.md b/content/tutorials/scripting-intro/index.md index a9cbfd42..7d5019d5 100644 --- a/content/tutorials/scripting-intro/index.md +++ b/content/tutorials/scripting-intro/index.md @@ -170,6 +170,5 @@ When the test has finished, there is an HTML link in the terminal that you can u You have successfully run your first test! To keep learning, we recommend the following resources: -- [Gatling Academy](https://gatling.io/academy) - [Introduction to the Recorder]({{< ref "recorder" >}}) - [Writing realistic tests]({{< ref "advanced" >}}) From 634d524773738dba6eea432f8d4de47d4c5307c5 Mon Sep 17 00:00:00 2001 From: Alhussein Ibrahim Date: Wed, 26 Feb 2025 11:30:48 +0100 Subject: [PATCH 03/17] feat: add simple manual use case option for simulation deployment --- content/tutorials/scripting-intro/index.md | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/content/tutorials/scripting-intro/index.md b/content/tutorials/scripting-intro/index.md index 7d5019d5..c9804309 100644 --- a/content/tutorials/scripting-intro/index.md +++ b/content/tutorials/scripting-intro/index.md @@ -127,6 +127,31 @@ Now, you should have a completed simulation that looks like the following: ### Run the Simulation on Gatling Enterprise Cloud +You can package, deploy, and run your simulation using one of two approaches, depending on whether you prefer a manual or automated process. + +#### Simple Manual Use Case + +1. Manually generate the package by executing the following command locally on your developer’s workstation: + + {{< platform-toggle >}} + Linux/MacOS: ./mvnw gatling:enterprisePackage + Windows: mvnw.cmd gatling:enterprisePackage + {{}} + +2. The above command will create a packaged **jar** file in your project's **target** directory. + +3. From your Gatling Enterprise console, go to **Packages**. Create a new package specifying its name, team that owns it, select your packaged jar file for upload then click **Save**. + +4. Go to **Simulations** > **Create a simulation** > **Test as code**. Under **Select a package**, choose the newly created package, then click **Create** + +5. Configure your simulation parameters: + - Simulation name + - Under **Select your package and simulation** > **Simulation**, select your simulation class. + - Under **Configure your locations**, choose the _Managed_ type and select a location based on your preference. + - Click **Save and launch** + +#### Advanced Use Case with Automated Deployments (Configuration-as-Code) + Gatling Enterprise Cloud is a feature-rich SaaS platform that is designed for teams and organizations to get the most out of load testing. With the trial account, you created in the [Prerequisites section]({{< ref "#install-gatling" >}}), you can upload and run your test with advanced configuration, reporting, and collaboration features. From 34e3460dfd6ec7b306297e8c0d947cd6219242d5 Mon Sep 17 00:00:00 2001 From: Alhussein Ibrahim Date: Wed, 5 Mar 2025 17:34:09 +0100 Subject: [PATCH 04/17] feat: add enterpriseDeploy option --- content/tutorials/scripting-intro/index.md | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/content/tutorials/scripting-intro/index.md b/content/tutorials/scripting-intro/index.md index c9804309..d4268b67 100644 --- a/content/tutorials/scripting-intro/index.md +++ b/content/tutorials/scripting-intro/index.md @@ -167,12 +167,21 @@ To deploy and run your simulation on Gatling Enterprise Cloud, use the following Windows: set GATLING_ENTERPRISE_API_TOKEN= {{}} -3. Run the following command in your terminal to deploy and start your simulation: +3. Run one of the following two commands according to your needs: - {{< platform-toggle >}} - Linux/MacOS: ./mvnw gatling:enterpriseStart - Windows: mvnw.cmd gatling:enterpriseStart - {{}} + - To deploy your package **and** start the simulation, run: + + {{< platform-toggle >}} + Linux/MacOS: ./mvnw gatling:enterpriseStart -Dgatling.enterprise.simulationName="" + Windows: mvnw.cmd gatling:enterpriseStart -Dgatling.enterprise.simulationName="" + {{}} + + - To deploy your package without starting a run: + + {{< platform-toggle >}} + Linux/MacOS: ./mvnw gatling:enterpriseDeploy + Windows: mvnw.cmd gatling:enterpriseDeploy + {{}} Watch the Simulation deploy automatically and generate real-time reports. From be9a8e034c97f00f730260b73cd22524f787f5f4 Mon Sep 17 00:00:00 2001 From: Alhussein Ibrahim Date: Fri, 7 Mar 2025 11:54:24 +0100 Subject: [PATCH 05/17] chore: add missing punctuation --- content/tutorials/scripting-intro/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/content/tutorials/scripting-intro/index.md b/content/tutorials/scripting-intro/index.md index d4268b67..dd61c8ce 100644 --- a/content/tutorials/scripting-intro/index.md +++ b/content/tutorials/scripting-intro/index.md @@ -142,13 +142,13 @@ You can package, deploy, and run your simulation using one of two approaches, de 3. From your Gatling Enterprise console, go to **Packages**. Create a new package specifying its name, team that owns it, select your packaged jar file for upload then click **Save**. -4. Go to **Simulations** > **Create a simulation** > **Test as code**. Under **Select a package**, choose the newly created package, then click **Create** +4. Go to **Simulations** > **Create a simulation** > **Test as code**. Under **Select a package**, choose the newly created package, then click **Create**. 5. Configure your simulation parameters: - - Simulation name + - Simulation name. - Under **Select your package and simulation** > **Simulation**, select your simulation class. - Under **Configure your locations**, choose the _Managed_ type and select a location based on your preference. - - Click **Save and launch** + - Click **Save and launch**. #### Advanced Use Case with Automated Deployments (Configuration-as-Code) From 68cb3affa1a1c7b41494f92a9b70460b2375c6b7 Mon Sep 17 00:00:00 2001 From: Alhussein Ibrahim Date: Fri, 7 Mar 2025 13:08:31 +0100 Subject: [PATCH 06/17] chore: rebase all code snippets on ecomm --- .../scripting-intro/code/BasicSimulation.java | 47 +++++++++++++++++++ .../scripting-intro/code/EcommSimulation.java | 40 ---------------- .../code/ScriptingIntro1SampleJava.java | 4 +- .../code/ScriptingIntro2SampleJava.java | 13 +++-- .../code/ScriptingIntro3SampleJava.java | 21 +++++---- .../code/ScriptingIntro4SampleJava.java | 25 ++++++---- content/tutorials/scripting-intro/index.md | 23 +++++---- 7 files changed, 96 insertions(+), 77 deletions(-) create mode 100644 content/tutorials/scripting-intro/code/BasicSimulation.java delete mode 100644 content/tutorials/scripting-intro/code/EcommSimulation.java diff --git a/content/tutorials/scripting-intro/code/BasicSimulation.java b/content/tutorials/scripting-intro/code/BasicSimulation.java new file mode 100644 index 00000000..d345c686 --- /dev/null +++ b/content/tutorials/scripting-intro/code/BasicSimulation.java @@ -0,0 +1,47 @@ +/* + * Copyright 2011-2025 GatlingCorp (https://gatling.io) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +//#full-example +package example; + +import static io.gatling.javaapi.core.CoreDsl.*; +import static io.gatling.javaapi.http.HttpDsl.*; + +import io.gatling.javaapi.core.*; +import io.gatling.javaapi.http.*; + +public class BasicSimulation extends Simulation { + + // Define HTTP configuration + // Reference: https://docs.gatling.io/reference/script/protocols/http/protocol/ + HttpProtocolBuilder httpProtocol = + http.baseUrl("https://api-ecomm.gatling.io") + .acceptHeader("application/json") + .userAgentHeader( + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/119.0"); + + // Define scenario + // Reference: https://docs.gatling.io/reference/script/core/scenario/ + ScenarioBuilder scenario = + scenario("Scenario").exec(http("Session").get("/session")); + + // Define injection profile and execute the test + // Reference: https://docs.gatling.io/reference/script/core/injection/ + { + setUp(scenario.injectOpen(constantUsersPerSec(2).during(60))).protocols(httpProtocol); + } +} +//#full-example diff --git a/content/tutorials/scripting-intro/code/EcommSimulation.java b/content/tutorials/scripting-intro/code/EcommSimulation.java deleted file mode 100644 index 08488f72..00000000 --- a/content/tutorials/scripting-intro/code/EcommSimulation.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2011-2025 GatlingCorp (https://gatling.io) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -//#full-example -package ecomm; - -import static io.gatling.javaapi.core.CoreDsl.*; -import static io.gatling.javaapi.http.HttpDsl.*; - -import io.gatling.javaapi.core.*; -import io.gatling.javaapi.http.*; - -public class EcommSimulation extends Simulation { - - HttpProtocolBuilder httpProtocol = http.baseUrl("https://ecomm.gatling.io") - .acceptHeader("application/json"); - - ScenarioBuilder myFirstScenario = scenario("My First Scenario") - .exec(http("Request 1") - .get("/products/")); - - { - setUp( - myFirstScenario.injectOpen(constantUsersPerSec(2).during(60))).protocols(httpProtocol); - } -} -//#full-example diff --git a/content/tutorials/scripting-intro/code/ScriptingIntro1SampleJava.java b/content/tutorials/scripting-intro/code/ScriptingIntro1SampleJava.java index 33999f66..0d14e4a9 100644 --- a/content/tutorials/scripting-intro/code/ScriptingIntro1SampleJava.java +++ b/content/tutorials/scripting-intro/code/ScriptingIntro1SampleJava.java @@ -15,7 +15,7 @@ */ //#setup-the-file -package ecomm; +package example; import static io.gatling.javaapi.core.CoreDsl.*; import static io.gatling.javaapi.http.HttpDsl.*; @@ -26,7 +26,7 @@ class ScriptingIntro1SampleJava { //#extend-the-simulation-class - public class EcommSimulation extends Simulation { + public class BasicSimulation extends Simulation { } //#extend-the-simulation-class diff --git a/content/tutorials/scripting-intro/code/ScriptingIntro2SampleJava.java b/content/tutorials/scripting-intro/code/ScriptingIntro2SampleJava.java index 73ec1a59..dad45d00 100644 --- a/content/tutorials/scripting-intro/code/ScriptingIntro2SampleJava.java +++ b/content/tutorials/scripting-intro/code/ScriptingIntro2SampleJava.java @@ -22,12 +22,15 @@ class ScriptingIntro2SampleJava { //#define-the-protocol-class - public class EcommSimulation extends Simulation { + public class BasicSimulation extends Simulation { - // Add the HttpProtocolBuilder: - HttpProtocolBuilder httpProtocol = http.baseUrl("https://ecomm.gatling.io") - // set the "accept" header to a value suited for the expected response - .acceptHeader("application/json"); + // Define HTTP configuration + // Reference: https://docs.gatling.io/reference/script/protocols/http/protocol/ + HttpProtocolBuilder httpProtocol = + http.baseUrl("https://api-ecomm.gatling.io") + .acceptHeader("application/json") + .userAgentHeader( + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/119.0"); } //#define-the-protocol-class } diff --git a/content/tutorials/scripting-intro/code/ScriptingIntro3SampleJava.java b/content/tutorials/scripting-intro/code/ScriptingIntro3SampleJava.java index 39f6bf82..7a76d352 100644 --- a/content/tutorials/scripting-intro/code/ScriptingIntro3SampleJava.java +++ b/content/tutorials/scripting-intro/code/ScriptingIntro3SampleJava.java @@ -22,15 +22,20 @@ class ScriptingIntro3SampleJava { //#write-the-scenario - public class EcommSimulation extends Simulation { + public class BasicSimulation extends Simulation { - HttpProtocolBuilder httpProtocol = http.baseUrl("https://ecomm.gatling.io") - // set the "accept" header to a value suited for the expected response - .acceptHeader("application/json"); + // Define HTTP configuration + // Reference: https://docs.gatling.io/reference/script/protocols/http/protocol/ + HttpProtocolBuilder httpProtocol = + http.baseUrl("https://api-ecomm.gatling.io") + .acceptHeader("application/json") + .userAgentHeader( + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/119.0"); - // Add the ScenarioBuilder: - ScenarioBuilder myScenario = scenario("My Scenario") - .exec(http("Request 1").get("/products/")); - } + // Define scenario + // Reference: https://docs.gatling.io/reference/script/core/scenario/ + ScenarioBuilder scenario = + scenario("Scenario").exec(http("Session").get("/session")); + } //#write-the-scenario } diff --git a/content/tutorials/scripting-intro/code/ScriptingIntro4SampleJava.java b/content/tutorials/scripting-intro/code/ScriptingIntro4SampleJava.java index e659adcd..dcdfb857 100644 --- a/content/tutorials/scripting-intro/code/ScriptingIntro4SampleJava.java +++ b/content/tutorials/scripting-intro/code/ScriptingIntro4SampleJava.java @@ -22,20 +22,25 @@ class ScriptingIntro4SampleJava { //#define-the-injection-profile - public class EcommSimulation extends Simulation { + public class BasicSimulation extends Simulation { - HttpProtocolBuilder httpProtocol = http.baseUrl("https://ecomm.gatling.io") - // set the "accept" header to a value suited for the expected response - .acceptHeader("application/json"); + // Define HTTP configuration + // Reference: https://docs.gatling.io/reference/script/protocols/http/protocol/ + HttpProtocolBuilder httpProtocol = + http.baseUrl("https://api-ecomm.gatling.io") + .acceptHeader("application/json") + .userAgentHeader( + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/119.0"); - ScenarioBuilder myScenario = scenario("My Scenario") - .exec( - http("Request 1").get("/products/")); + // Define scenario + // Reference: https://docs.gatling.io/reference/script/core/scenario/ + ScenarioBuilder scenario = + scenario("Scenario").exec(http("Session").get("/session")); - // Add the setUp block: + // Define injection profile and execute the test + // Reference: https://docs.gatling.io/reference/script/core/injection/ { - setUp( - myScenario.injectOpen(constantUsersPerSec(2).during(60))).protocols(httpProtocol); + setUp(scenario.injectOpen(constantUsersPerSec(2).during(60))).protocols(httpProtocol); } } //#define-the-injection-profile diff --git a/content/tutorials/scripting-intro/index.md b/content/tutorials/scripting-intro/index.md index dd61c8ce..44ab6f6b 100644 --- a/content/tutorials/scripting-intro/index.md +++ b/content/tutorials/scripting-intro/index.md @@ -46,11 +46,12 @@ Gatling Enterprise Cloud is a fully managed SaaS solution for load testing. Sign Java 11, 17, or 21 64-bit OpenJDK LTS (Long Term Support) version installed on your local machine. We recommend the [Azul JDK](https://www.azul.com/downloads/?package=jdk#zulu). {{< /alert >}} -This guide uses the Gatling Java SDK with Maven, which is accessed by downloading and extracting the following `zip`file: +This guide uses the Gatling Java SDK with Maven. Use the following procedure to install Gatling: -{{< button title="Download Gatling" >}} -https://github.com/gatling/gatling-maven-plugin-demo-java/archive/refs/heads/main.zip -{{< /button >}} +1. Clone the following [repo](https://github.com/gatling/se-ecommerce-demo-gatling-tests). + +2. Open the project in your IDE or terminal. +3. Navigate to the `/java` folder for JavaScript projects in your terminal. ## Simulation construction @@ -76,7 +77,7 @@ and copy the final simulation, jump to [Test execution]({{< ref "#test-execution Once you have downloaded and extracted the Gatling `zip` file, open the project in your integrated development environment (IDE). Gatling recommends the [IntelliJ community edition](https://www.jetbrains.com/idea/download/). -1. Navigate to and open `src/test/java/ecomm/EcommSimulation.java`. +1. Navigate to and open `src/test/java//example/BasicSimulation.java`. 2. Modify the simulation by deleting everything below line 7 `import io.gatling.javaapi.http.*;`. 3. The simulation should now look like the following: @@ -90,18 +91,16 @@ You must extend Gatling's `Simulation` class to write a script. To extend the `S #### Define the protocol class -Inside the `EcommSimulation` class, add an `HTTP protocol` class. Learn about all of the +Inside the `BasicSimulation` class, add an `HTTP protocol` class. Learn about all of the `HttpProtocolBuilder` options in the [Documentation]({{< ref "/reference/script/protocols/http/protocol" >}}). For -this example, the `baseUrl` property is hardcoded as the Gatling e-commerce test site, and the `acceptHeader` and -contentTypeHeader`properties are set to`application/json`. +this example, the `baseUrl` property is hardcoded as the Gatling e-commerce test site, and the `acceptHeader` is set to `application/json`. {{< include-code "ScriptingIntro2Sample#define-the-protocol-class" java >}} #### Write the scenario The next step is to describe the user journey. For a web application, this usually consists of a user arriving at the -application and then a series of interactions with the application. The following scenario mocks a user arriving on the -home page of the [Gatling sample application](https://ecomm.gatling.io). +application and then a series of interactions with the application. The following scenario performs a get request to `https://api-ecomm.gatling.io/session` to retrieve the current user session. {{< include-code "ScriptingIntro3Sample#write-the-scenario" java >}} @@ -123,7 +122,7 @@ and on Gatling Enterprise Cloud. Now, you should have a completed simulation that looks like the following: -{{< include-code "EcommSimulation#full-example" java >}} +{{< include-code "BasicSimulation#full-example" java >}} ### Run the Simulation on Gatling Enterprise Cloud @@ -196,7 +195,7 @@ Linux/MacOS: ./mvnw gatling:test Windows: mvnw.cmd gatling:test {{}} -Select `1 Run the Simulation locally` to start the test. +Select `[1] example.BasicSimulation` to start the test. When the test has finished, there is an HTML link in the terminal that you can use to access the static report. From 9d51dd6f52c90ae5a52ac180092c42c2e74229a4 Mon Sep 17 00:00:00 2001 From: Alhussein Ibrahim Date: Fri, 7 Mar 2025 13:15:53 +0100 Subject: [PATCH 07/17] fix: remove zip reference --- content/tutorials/scripting-intro/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/tutorials/scripting-intro/index.md b/content/tutorials/scripting-intro/index.md index 44ab6f6b..1c6d6fe6 100644 --- a/content/tutorials/scripting-intro/index.md +++ b/content/tutorials/scripting-intro/index.md @@ -74,7 +74,7 @@ and copy the final simulation, jump to [Test execution]({{< ref "#test-execution #### Setup the file -Once you have downloaded and extracted the Gatling `zip` file, open the project in your integrated development +Once you have cloned the demo e-commerce repo, open the project in your integrated development environment (IDE). Gatling recommends the [IntelliJ community edition](https://www.jetbrains.com/idea/download/). 1. Navigate to and open `src/test/java//example/BasicSimulation.java`. From 0e8eb0845bfd3103b86840961061d4d0b894a1b9 Mon Sep 17 00:00:00 2001 From: Alhussein Ibrahim Date: Fri, 7 Mar 2025 13:19:30 +0100 Subject: [PATCH 08/17] chore: adjust wording --- content/tutorials/scripting-intro/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/tutorials/scripting-intro/index.md b/content/tutorials/scripting-intro/index.md index 1c6d6fe6..1aa167e7 100644 --- a/content/tutorials/scripting-intro/index.md +++ b/content/tutorials/scripting-intro/index.md @@ -74,10 +74,10 @@ and copy the final simulation, jump to [Test execution]({{< ref "#test-execution #### Setup the file -Once you have cloned the demo e-commerce repo, open the project in your integrated development +Once you have cloned the Gatling repo, open the project in your integrated development environment (IDE). Gatling recommends the [IntelliJ community edition](https://www.jetbrains.com/idea/download/). -1. Navigate to and open `src/test/java//example/BasicSimulation.java`. +1. Navigate to and open `src/test/java/example/BasicSimulation.java`. 2. Modify the simulation by deleting everything below line 7 `import io.gatling.javaapi.http.*;`. 3. The simulation should now look like the following: From 621f5ab6fdbaff4a09a2c14cdd555ad87d9880e2 Mon Sep 17 00:00:00 2001 From: Alhussein Ibrahim Date: Fri, 7 Mar 2025 13:22:51 +0100 Subject: [PATCH 09/17] fix: fix simulation directory --- content/tutorials/scripting-intro/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/tutorials/scripting-intro/index.md b/content/tutorials/scripting-intro/index.md index 1aa167e7..ffeaccd1 100644 --- a/content/tutorials/scripting-intro/index.md +++ b/content/tutorials/scripting-intro/index.md @@ -77,7 +77,7 @@ and copy the final simulation, jump to [Test execution]({{< ref "#test-execution Once you have cloned the Gatling repo, open the project in your integrated development environment (IDE). Gatling recommends the [IntelliJ community edition](https://www.jetbrains.com/idea/download/). -1. Navigate to and open `src/test/java/example/BasicSimulation.java`. +1. Navigate to and open `java/src/test/java/example/BasicSimulation.java`. 2. Modify the simulation by deleting everything below line 7 `import io.gatling.javaapi.http.*;`. 3. The simulation should now look like the following: From 11be6c9c7b4b71e34f83ada2dba0f26ca3106759 Mon Sep 17 00:00:00 2001 From: Alhussein Ibrahim Date: Fri, 7 Mar 2025 13:47:35 +0100 Subject: [PATCH 10/17] chore: add simulation class to local run command --- content/tutorials/scripting-intro/index.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/content/tutorials/scripting-intro/index.md b/content/tutorials/scripting-intro/index.md index ffeaccd1..2ef4b920 100644 --- a/content/tutorials/scripting-intro/index.md +++ b/content/tutorials/scripting-intro/index.md @@ -191,12 +191,10 @@ new or modified simulation locally is often useful to ensure it works before lau Using the Java SDK, you can launch your test with the following command in the project root directory: {{< platform-toggle>}} -Linux/MacOS: ./mvnw gatling:test -Windows: mvnw.cmd gatling:test +Linux/MacOS: ./mvnw gatling:test -Dgatling.simulationClass=example.BasicSimulation +Windows: mvnw.cmd gatling:test -Dgatling.simulationClass=example.BasicSimulation {{}} -Select `[1] example.BasicSimulation` to start the test. - When the test has finished, there is an HTML link in the terminal that you can use to access the static report. ## Keep learning From f2708b933d37c2bfecf2cc60b1c5fb979360e80f Mon Sep 17 00:00:00 2001 From: Alhussein Ibrahim Date: Fri, 7 Mar 2025 15:32:56 +0100 Subject: [PATCH 11/17] chore: specify repository cloning instead of install --- content/tutorials/scripting-intro/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/tutorials/scripting-intro/index.md b/content/tutorials/scripting-intro/index.md index 2ef4b920..0c3e96fc 100644 --- a/content/tutorials/scripting-intro/index.md +++ b/content/tutorials/scripting-intro/index.md @@ -39,7 +39,7 @@ This guide uses the Java SDK with the Maven wrapper. Gatling recommends that dev Gatling Enterprise Cloud is a fully managed SaaS solution for load testing. Sign up for a [trial account](https://auth.gatling.io/auth/realms/gatling/protocol/openid-connect/registrations?client_id=gatling-enterprise-cloud-public&response_type=code&scope=openid&redirect_uri=https%3A%2F%2Fcloud.gatling.io%2Fr%2Fgatling) to run your first test on Gatling Enterprise Cloud. The [Gatling website](https://gatling.io/features) has a full list of Enterprise features. -### Install Gatling +### Clone Gatling demo repository { #install-gatling } {{< alert info >}} **Prerequisites** @@ -48,7 +48,7 @@ Java 11, 17, or 21 64-bit OpenJDK LTS (Long Term Support) version installed on y This guide uses the Gatling Java SDK with Maven. Use the following procedure to install Gatling: -1. Clone the following [repo](https://github.com/gatling/se-ecommerce-demo-gatling-tests). +1. Clone the following [repository](https://github.com/gatling/se-ecommerce-demo-gatling-tests). 2. Open the project in your IDE or terminal. 3. Navigate to the `/java` folder for JavaScript projects in your terminal. From b6fbb701f05919dbbf6835cd9ea27ea890776ed0 Mon Sep 17 00:00:00 2001 From: Alhussein Ibrahim Date: Fri, 7 Mar 2025 16:16:42 +0100 Subject: [PATCH 12/17] fix: fix javascript typo --- content/tutorials/scripting-intro/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/tutorials/scripting-intro/index.md b/content/tutorials/scripting-intro/index.md index 0c3e96fc..eaf193bc 100644 --- a/content/tutorials/scripting-intro/index.md +++ b/content/tutorials/scripting-intro/index.md @@ -51,7 +51,7 @@ This guide uses the Gatling Java SDK with Maven. Use the following procedure to 1. Clone the following [repository](https://github.com/gatling/se-ecommerce-demo-gatling-tests). 2. Open the project in your IDE or terminal. -3. Navigate to the `/java` folder for JavaScript projects in your terminal. +3. Navigate to the `/java` folder. ## Simulation construction From 1a881c5677c09097336262bdca01c9c90bb1e20c Mon Sep 17 00:00:00 2001 From: Alhussein Ibrahim Date: Mon, 10 Mar 2025 11:54:58 +0100 Subject: [PATCH 13/17] chore: adjust code samples indentation --- .../code/ScriptingIntro1SampleJava.java | 8 ++-- .../code/ScriptingIntro2SampleJava.java | 22 +++++------ .../code/ScriptingIntro3SampleJava.java | 30 +++++++-------- .../code/ScriptingIntro4SampleJava.java | 38 +++++++++---------- 4 files changed, 49 insertions(+), 49 deletions(-) diff --git a/content/tutorials/scripting-intro/code/ScriptingIntro1SampleJava.java b/content/tutorials/scripting-intro/code/ScriptingIntro1SampleJava.java index 0d14e4a9..68899554 100644 --- a/content/tutorials/scripting-intro/code/ScriptingIntro1SampleJava.java +++ b/content/tutorials/scripting-intro/code/ScriptingIntro1SampleJava.java @@ -25,9 +25,9 @@ //#setup-the-file class ScriptingIntro1SampleJava { - //#extend-the-simulation-class - public class BasicSimulation extends Simulation { +//#extend-the-simulation-class +public class BasicSimulation extends Simulation { - } - //#extend-the-simulation-class +} +//#extend-the-simulation-class } diff --git a/content/tutorials/scripting-intro/code/ScriptingIntro2SampleJava.java b/content/tutorials/scripting-intro/code/ScriptingIntro2SampleJava.java index dad45d00..780980ef 100644 --- a/content/tutorials/scripting-intro/code/ScriptingIntro2SampleJava.java +++ b/content/tutorials/scripting-intro/code/ScriptingIntro2SampleJava.java @@ -21,16 +21,16 @@ import io.gatling.javaapi.http.*; class ScriptingIntro2SampleJava { - //#define-the-protocol-class - public class BasicSimulation extends Simulation { +//#define-the-protocol-class +public class BasicSimulation extends Simulation { - // Define HTTP configuration - // Reference: https://docs.gatling.io/reference/script/protocols/http/protocol/ - HttpProtocolBuilder httpProtocol = - http.baseUrl("https://api-ecomm.gatling.io") - .acceptHeader("application/json") - .userAgentHeader( - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/119.0"); - } - //#define-the-protocol-class + // Define HTTP configuration + // Reference: https://docs.gatling.io/reference/script/protocols/http/protocol/ + HttpProtocolBuilder httpProtocol = + http.baseUrl("https://api-ecomm.gatling.io") + .acceptHeader("application/json") + .userAgentHeader( + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/119.0"); +} +//#define-the-protocol-class } diff --git a/content/tutorials/scripting-intro/code/ScriptingIntro3SampleJava.java b/content/tutorials/scripting-intro/code/ScriptingIntro3SampleJava.java index 7a76d352..4ca50e32 100644 --- a/content/tutorials/scripting-intro/code/ScriptingIntro3SampleJava.java +++ b/content/tutorials/scripting-intro/code/ScriptingIntro3SampleJava.java @@ -21,21 +21,21 @@ import io.gatling.javaapi.http.*; class ScriptingIntro3SampleJava { - //#write-the-scenario - public class BasicSimulation extends Simulation { +//#write-the-scenario +public class BasicSimulation extends Simulation { - // Define HTTP configuration - // Reference: https://docs.gatling.io/reference/script/protocols/http/protocol/ - HttpProtocolBuilder httpProtocol = - http.baseUrl("https://api-ecomm.gatling.io") - .acceptHeader("application/json") - .userAgentHeader( - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/119.0"); + // Define HTTP configuration + // Reference: https://docs.gatling.io/reference/script/protocols/http/protocol/ + HttpProtocolBuilder httpProtocol = + http.baseUrl("https://api-ecomm.gatling.io") + .acceptHeader("application/json") + .userAgentHeader( + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/119.0"); - // Define scenario - // Reference: https://docs.gatling.io/reference/script/core/scenario/ - ScenarioBuilder scenario = - scenario("Scenario").exec(http("Session").get("/session")); - } - //#write-the-scenario + // Define scenario + // Reference: https://docs.gatling.io/reference/script/core/scenario/ + ScenarioBuilder scenario = + scenario("Scenario").exec(http("Session").get("/session")); + } +//#write-the-scenario } diff --git a/content/tutorials/scripting-intro/code/ScriptingIntro4SampleJava.java b/content/tutorials/scripting-intro/code/ScriptingIntro4SampleJava.java index dcdfb857..5bb341e7 100644 --- a/content/tutorials/scripting-intro/code/ScriptingIntro4SampleJava.java +++ b/content/tutorials/scripting-intro/code/ScriptingIntro4SampleJava.java @@ -21,27 +21,27 @@ import io.gatling.javaapi.http.*; class ScriptingIntro4SampleJava { - //#define-the-injection-profile - public class BasicSimulation extends Simulation { +//#define-the-injection-profile +public class BasicSimulation extends Simulation { - // Define HTTP configuration - // Reference: https://docs.gatling.io/reference/script/protocols/http/protocol/ - HttpProtocolBuilder httpProtocol = - http.baseUrl("https://api-ecomm.gatling.io") - .acceptHeader("application/json") - .userAgentHeader( - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/119.0"); + // Define HTTP configuration + // Reference: https://docs.gatling.io/reference/script/protocols/http/protocol/ + HttpProtocolBuilder httpProtocol = + http.baseUrl("https://api-ecomm.gatling.io") + .acceptHeader("application/json") + .userAgentHeader( + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/119.0"); - // Define scenario - // Reference: https://docs.gatling.io/reference/script/core/scenario/ - ScenarioBuilder scenario = - scenario("Scenario").exec(http("Session").get("/session")); + // Define scenario + // Reference: https://docs.gatling.io/reference/script/core/scenario/ + ScenarioBuilder scenario = + scenario("Scenario").exec(http("Session").get("/session")); - // Define injection profile and execute the test - // Reference: https://docs.gatling.io/reference/script/core/injection/ - { - setUp(scenario.injectOpen(constantUsersPerSec(2).during(60))).protocols(httpProtocol); - } + // Define injection profile and execute the test + // Reference: https://docs.gatling.io/reference/script/core/injection/ + { + setUp(scenario.injectOpen(constantUsersPerSec(2).during(60))).protocols(httpProtocol); } - //#define-the-injection-profile +} +//#define-the-injection-profile } From a27b1de0ff7746cff529fa9dec2cc91fa195d780 Mon Sep 17 00:00:00 2001 From: Alhussein Ibrahim Date: Tue, 18 Mar 2025 10:43:33 +0100 Subject: [PATCH 14/17] chore: show local run in interactive mode --- content/tutorials/scripting-intro/index.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/content/tutorials/scripting-intro/index.md b/content/tutorials/scripting-intro/index.md index eaf193bc..499a2ac8 100644 --- a/content/tutorials/scripting-intro/index.md +++ b/content/tutorials/scripting-intro/index.md @@ -188,12 +188,16 @@ Watch the Simulation deploy automatically and generate real-time reports. The open-source version of Gatling allows you to run simulations locally, generating load from your computer. Running a new or modified simulation locally is often useful to ensure it works before launching it on Gatling Enterprise Cloud. -Using the Java SDK, you can launch your test with the following command in the project root directory: +Using the Java SDK, you can launch your test in interactive mode using the following approach: -{{< platform-toggle>}} -Linux/MacOS: ./mvnw gatling:test -Dgatling.simulationClass=example.BasicSimulation -Windows: mvnw.cmd gatling:test -Dgatling.simulationClass=example.BasicSimulation -{{}} +1. Run the following command in the Java project root directory: + + {{< platform-toggle>}} + Linux/MacOS: ./mvnw gatling:test + Windows: mvnw.cmd gatling:test + {{}} + +2. Choose `[1] example.BasicSimulation`. When the test has finished, there is an HTML link in the terminal that you can use to access the static report. From acdc567910d801729864c2ba1de76ee2fae37118 Mon Sep 17 00:00:00 2001 From: Alhussein Ibrahim Date: Fri, 21 Mar 2025 10:14:24 +0100 Subject: [PATCH 15/17] chore: adjust maven project directory --- content/tutorials/scripting-intro/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/content/tutorials/scripting-intro/index.md b/content/tutorials/scripting-intro/index.md index 499a2ac8..2e92ac98 100644 --- a/content/tutorials/scripting-intro/index.md +++ b/content/tutorials/scripting-intro/index.md @@ -51,7 +51,7 @@ This guide uses the Gatling Java SDK with Maven. Use the following procedure to 1. Clone the following [repository](https://github.com/gatling/se-ecommerce-demo-gatling-tests). 2. Open the project in your IDE or terminal. -3. Navigate to the `/java` folder. +3. Navigate to the `/java/maven` folder. ## Simulation construction @@ -77,7 +77,7 @@ and copy the final simulation, jump to [Test execution]({{< ref "#test-execution Once you have cloned the Gatling repo, open the project in your integrated development environment (IDE). Gatling recommends the [IntelliJ community edition](https://www.jetbrains.com/idea/download/). -1. Navigate to and open `java/src/test/java/example/BasicSimulation.java`. +1. Navigate to and open `java/maven/src/test/java/example/BasicSimulation.java`. 2. Modify the simulation by deleting everything below line 7 `import io.gatling.javaapi.http.*;`. 3. The simulation should now look like the following: @@ -190,7 +190,7 @@ The open-source version of Gatling allows you to run simulations locally, genera new or modified simulation locally is often useful to ensure it works before launching it on Gatling Enterprise Cloud. Using the Java SDK, you can launch your test in interactive mode using the following approach: -1. Run the following command in the Java project root directory: +1. In the `java/maven` directory, run the following command: {{< platform-toggle>}} Linux/MacOS: ./mvnw gatling:test From 4bf30ee485bbee5beff5bbcf65ba5c4074203f69 Mon Sep 17 00:00:00 2001 From: Alhussein Ibrahim Date: Fri, 21 Mar 2025 10:18:04 +0100 Subject: [PATCH 16/17] chore: change user-agent header --- content/tutorials/scripting-intro/code/BasicSimulation.java | 2 +- .../scripting-intro/code/ScriptingIntro2SampleJava.java | 2 +- .../scripting-intro/code/ScriptingIntro3SampleJava.java | 2 +- .../scripting-intro/code/ScriptingIntro4SampleJava.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/content/tutorials/scripting-intro/code/BasicSimulation.java b/content/tutorials/scripting-intro/code/BasicSimulation.java index d345c686..9a840ec0 100644 --- a/content/tutorials/scripting-intro/code/BasicSimulation.java +++ b/content/tutorials/scripting-intro/code/BasicSimulation.java @@ -31,7 +31,7 @@ public class BasicSimulation extends Simulation { http.baseUrl("https://api-ecomm.gatling.io") .acceptHeader("application/json") .userAgentHeader( - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/119.0"); + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36"); // Define scenario // Reference: https://docs.gatling.io/reference/script/core/scenario/ diff --git a/content/tutorials/scripting-intro/code/ScriptingIntro2SampleJava.java b/content/tutorials/scripting-intro/code/ScriptingIntro2SampleJava.java index 780980ef..55aa2473 100644 --- a/content/tutorials/scripting-intro/code/ScriptingIntro2SampleJava.java +++ b/content/tutorials/scripting-intro/code/ScriptingIntro2SampleJava.java @@ -30,7 +30,7 @@ public class BasicSimulation extends Simulation { http.baseUrl("https://api-ecomm.gatling.io") .acceptHeader("application/json") .userAgentHeader( - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/119.0"); + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36"); } //#define-the-protocol-class } diff --git a/content/tutorials/scripting-intro/code/ScriptingIntro3SampleJava.java b/content/tutorials/scripting-intro/code/ScriptingIntro3SampleJava.java index 4ca50e32..23bb54de 100644 --- a/content/tutorials/scripting-intro/code/ScriptingIntro3SampleJava.java +++ b/content/tutorials/scripting-intro/code/ScriptingIntro3SampleJava.java @@ -30,7 +30,7 @@ public class BasicSimulation extends Simulation { http.baseUrl("https://api-ecomm.gatling.io") .acceptHeader("application/json") .userAgentHeader( - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/119.0"); + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36"); // Define scenario // Reference: https://docs.gatling.io/reference/script/core/scenario/ diff --git a/content/tutorials/scripting-intro/code/ScriptingIntro4SampleJava.java b/content/tutorials/scripting-intro/code/ScriptingIntro4SampleJava.java index 5bb341e7..7356b48f 100644 --- a/content/tutorials/scripting-intro/code/ScriptingIntro4SampleJava.java +++ b/content/tutorials/scripting-intro/code/ScriptingIntro4SampleJava.java @@ -30,7 +30,7 @@ public class BasicSimulation extends Simulation { http.baseUrl("https://api-ecomm.gatling.io") .acceptHeader("application/json") .userAgentHeader( - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/119.0"); + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36"); // Define scenario // Reference: https://docs.gatling.io/reference/script/core/scenario/ From 2fde4ec7b20dbf31fecbf911289e1de191012212 Mon Sep 17 00:00:00 2001 From: Al Hussein Ahmed Date: Fri, 21 Mar 2025 14:16:05 +0100 Subject: [PATCH 17/17] Update content/tutorials/scripting-intro/code/BasicSimulation.java Co-authored-by: Karim Atwa --- .../tutorials/scripting-intro/code/BasicSimulation.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/content/tutorials/scripting-intro/code/BasicSimulation.java b/content/tutorials/scripting-intro/code/BasicSimulation.java index 9a840ec0..499dca37 100644 --- a/content/tutorials/scripting-intro/code/BasicSimulation.java +++ b/content/tutorials/scripting-intro/code/BasicSimulation.java @@ -28,10 +28,9 @@ public class BasicSimulation extends Simulation { // Define HTTP configuration // Reference: https://docs.gatling.io/reference/script/protocols/http/protocol/ HttpProtocolBuilder httpProtocol = - http.baseUrl("https://api-ecomm.gatling.io") - .acceptHeader("application/json") - .userAgentHeader( - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36"); +http.baseUrl("https://api-ecomm.gatling.io") + .acceptHeader("application/json") + .userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36"); // Define scenario // Reference: https://docs.gatling.io/reference/script/core/scenario/