├── .gitignore ├── .gitpod.Dockerfile ├── .gitpod.yml ├── README.md ├── capabilities ├── pom.xml ├── run.sh └── src └── test └── groovy ├── GebConfig.groovy ├── Pages ├── DuckDuckGoQueryPage.groovy └── DuckDuckGoResultPage.groovy └── Spec ├── BasePageGebSpec.groovy └── BingSpecPageGebSpec.groovy /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | *.log 3 | output/ 4 | build/ 5 | target/ 6 | .idea 7 | *.iml 8 | -------------------------------------------------------------------------------- /.gitpod.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM gitpod/workspace-full 2 | 3 | USER gitpod 4 | 5 | # Install custom tools, runtime, etc. using apt-get 6 | # For example, the command below would install "bastet" - a command line tetris clone: 7 | # 8 | # RUN sudo apt-get -q update && \ 9 | # sudo apt-get install -yq bastet && \ 10 | # sudo rm -rf /var/lib/apt/lists/* 11 | # 12 | # More information: https://www.gitpod.io/docs/config-docker/ 13 | -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | #image: 2 | # file: .gitpod.Dockerfile 3 | 4 | 5 | # List the start up tasks. You can start them in parallel in multiple terminals. See https://www.gitpod.io/docs/config-start-tasks/ 6 | tasks: 7 | - init: mvn compile 8 | command: ./run.sh 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Run Selenium Tests With Geb On LambdaTest 2 | 3 | ![image](https://user-images.githubusercontent.com/70570645/171909605-8dae46ca-d189-49b1-815d-2b9476f905e8.png) 4 | 5 |

6 | Blog 7 |   ⋅   8 | Docs 9 |   ⋅   10 | Learning Hub 11 |   ⋅   12 | Newsletter 13 |   ⋅   14 | Certifications 15 |   ⋅   16 | YouTube 17 |

18 |   19 |   20 |   21 | 22 | *Learn how to use Geb framework to configure and run your Java automation testing scripts on the LambdaTest platform.* 23 | 24 | [](https://accounts.lambdatest.com/register?utm_source=github&utm_medium=repo&utm_campaign=geb-parallel-sample-code) 25 | 26 | ## Table Of Contents 27 | 28 | * [Pre-requisites](#pre-requisites) 29 | * [Run Your First Test](#run-your-first-test) 30 | * [Local Testing With Geb](#testing-locally-hosted-or-privately-hosted-projects) 31 | 32 | 33 | ## Pre-requisites 34 | 35 | Before you can start performing Geb automation testing with Selenium, you would need to: 36 | 37 | - Install the latest **Java development environment** i.e. **JDK 1.8**. 38 | 39 | - Download the latest **Selenium Client** and its **WebDriver bindings** from the [official website](https://www.selenium.dev/downloads/). Latest versions of Selenium Client and WebDriver are ideal for running your automation script on LambdaTest Selenium cloud grid. 40 | 41 | - Install **Maven**. It can be downloaded and installed following the steps from [the official website](https://maven.apache.org/). Maven can also be installed easily on **Linux/MacOS** using [Homebrew](https://brew.sh/) package manager. 42 | 43 | ### Cloning Repo And Installing Dependencies 44 | 45 | **Step 1:** Clone the LambdaTest’s Geb GitHub Repository and navigate to the code directory as shown below: 46 | 47 | ```bash 48 | git clone https://github.com/LambdaTest/geb-parallel-sample-code 49 | cd geb-parallel-sample-code 50 | ``` 51 | 52 | **Step 2:** Compile Maven dependencies using the below command: 53 | 54 | ```bash 55 | mvn compile 56 | ``` 57 | 58 | You may also want to run the command below to check for outdated dependencies. 59 | 60 | ```bash 61 | mvn versions:display-dependency-updates 62 | ``` 63 | 64 | ### Setting Up Your Authentication 65 | 66 | Make sure you have your LambdaTest credentials with you to run test automation scripts. You can get these credentials from the [LambdaTest Automation Dashboard](https://automation.lambdatest.com/build?utm_source=github&utm_medium=repo&utm_campaign=geb-parallel-sample-code) or by your [LambdaTest Profile](https://accounts.lambdatest.com/login?utm_source=github&utm_medium=repo&utm_campaign=geb-parallel-sample-code). 67 | 68 | **Step 3:** Set LambdaTest **Username** and **Access Key** in environment variables. 69 | 70 | * For **Linux/macOS**: 71 | 72 | ```bash 73 | export LT_USERNAME="YOUR_USERNAME" 74 | export LT_ACCESS_KEY="YOUR ACCESS KEY" 75 | ``` 76 | * For **Windows**: 77 | ```bash 78 | set LT_USERNAME="YOUR_USERNAME" 79 | set LT_ACCESS_KEY="YOUR ACCESS KEY" 80 | ``` 81 | 82 | ## Run Your First Test 83 | 84 | ### Configuring Your Test Capabilities 85 | 86 | **Step 4:** In `capabilities.json` file, you need to update your test capabilities. Here, we are passing browser, browser version, and operating system information, along with LambdaTest Selenium grid capabilities via capabilities object. The capabilities object in the above code are defined as: 87 | 88 | ```json title="capabilities.json" 89 | { 90 | "build": "GebParallelTest", 91 | "platform": "Windows 10", 92 | "browserName": "Microsoft Edge", 93 | "version":"latest" 94 | } 95 | 96 | { 97 | "build": "GebParallelTest", 98 | "platform": "Windows 10", 99 | "browserName": "Chrome", 100 | "version":"latest" 101 | } 102 | ``` 103 | 104 | You can generate capabilities for your test requirements with the help of [Desired Capability Generator](https://www.lambdatest.com/capabilities-generator/?utm_source=github&utm_medium=repo&utm_campaign=geb-parallel-sample-code). 105 | 106 | ### Executing The Test 107 | 108 | **Step 5:** The tests can be executed in the terminal from the root of the project using the following commands: 109 | 110 | ```bash 111 | ./run.sh 112 | ``` 113 | 114 | ```bash 115 | mvn -Dlambdageb.capabilities=capabilities clean test 116 | ``` 117 | 118 | Your test results would be displayed on the test console (or command-line interface if you are using terminal/cmd) and on LambdaTest Automation Dashboard. 119 | 120 | ## Testing Locally Hosted Or Privately Hosted Projects 121 | 122 | You can test your locally hosted or privately hosted projects with LambdaTest Selenium grid using LambdaTest Tunnel. All you would have to do is set up an SSH tunnel using tunnel and pass toggle `tunnel = True` via desired capabilities. LambdaTest Tunnel establishes a secure SSH protocol based tunnel that allows you in testing your locally hosted or privately hosted pages, even before they are live. 123 | 124 | Refer our [LambdaTest Tunnel documentation](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/?utm_source=github&utm_medium=repo&utm_campaign=geb-parallel-sample-code) for more information. 125 | 126 | Here’s how you can establish LambdaTest Tunnel. 127 | 128 | Download the binary file of: 129 | * [LambdaTest Tunnel for Windows](https://downloads.lambdatest.com/tunnel/v3/windows/64bit/LT_Windows.zip) 130 | * [LambdaTest Tunnel for macOS](https://downloads.lambdatest.com/tunnel/v3/mac/64bit/LT_Mac.zip) 131 | * [LambdaTest Tunnel for Linux](https://downloads.lambdatest.com/tunnel/v3/linux/64bit/LT_Linux.zip) 132 | 133 | Open command prompt and navigate to the binary folder. 134 | 135 | Run the following command: 136 | 137 | ```bash 138 | LT -user {user’s login email} -key {user’s access key} 139 | ``` 140 | So if your user name is lambdatest@example.com and key is 123456, the command would be: 141 | 142 | ```bash 143 | LT -user lambdatest@example.com -key 123456 144 | ``` 145 | Once you are able to connect **LambdaTest Tunnel** successfully, you would just have to pass on tunnel capabilities in the code shown below : 146 | 147 | **Tunnel Capability** 148 | 149 | ```java 150 | DesiredCapabilities capabilities = new DesiredCapabilities(); 151 | capabilities.setCapability("tunnel", true); 152 | ``` 153 | 154 | ## Additional Links 155 | 156 | - [Advanced Configuration For Capabilities](https://www.lambdatest.com/support/docs/selenium-automation-capabilities/?utm_source=github&utm_medium=repo&utm_campaign=geb-parallel-sample-code) 157 | - [How To Test Locally Hosted Apps](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/?utm_source=github&utm_medium=repo&utm_campaign=geb-parallel-sample-code) 158 | - [How To Integrate LambdaTest With CI/CD](https://www.lambdatest.com/support/docs/integrations-with-ci-cd-tools/?utm_source=github&utm_medium=repo&utm_campaign=geb-parallel-sample-code) 159 | 160 | ## Documentation & Resources :books: 161 | 162 | 163 | Visit the following links to learn more about LambdaTest's features, setup and tutorials around test automation, mobile app testing, responsive testing, and manual testing. 164 | 165 | * [LambdaTest Documentation](https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=geb-parallel-sample-code) 166 | * [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=geb-parallel-sample-code) 167 | * [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=geb-parallel-sample-code) 168 | 169 | ## LambdaTest Community :busts_in_silhouette: 170 | 171 | The [LambdaTest Community](https://community.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=geb-parallel-sample-code) allows people to interact with tech enthusiasts. Connect, ask questions, and learn from tech-savvy people. Discuss best practises in web development, testing, and DevOps with professionals from across the globe 🌎 172 | 173 | ## What's New At LambdaTest ❓ 174 | 175 | To stay updated with the latest features and product add-ons, visit [Changelog](https://changelog.lambdatest.com/) 176 | 177 | ## About LambdaTest 178 | 179 | [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=geb-parallel-sample-code) is a leading test execution and orchestration platform that is fast, reliable, scalable, and secure. It allows users to run both manual and automated testing of web and mobile apps across 3000+ different browsers, operating systems, and real device combinations. Using LambdaTest, businesses can ensure quicker developer feedback and hence achieve faster go to market. Over 500 enterprises and 1 Million + users across 130+ countries rely on LambdaTest for their testing needs. 180 | 181 | ### Features 182 | 183 | * Run Selenium, Cypress, Puppeteer, Playwright, and Appium automation tests across 3000+ real desktop and mobile environments. 184 | * Real-time cross browser testing on 3000+ environments. 185 | * Test on Real device cloud 186 | * Blazing fast test automation with HyperExecute 187 | * Accelerate testing, shorten job times and get faster feedback on code changes with Test At Scale. 188 | * Smart Visual Regression Testing on cloud 189 | * 120+ third-party integrations with your favorite tool for CI/CD, Project Management, Codeless Automation, and more. 190 | * Automated Screenshot testing across multiple browsers in a single click. 191 | * Local testing of web and mobile apps. 192 | * Online Accessibility Testing across 3000+ desktop and mobile browsers, browser versions, and operating systems. 193 | * Geolocation testing of web and mobile apps across 53+ countries. 194 | * LT Browser - for responsive testing across 50+ pre-installed mobile, tablets, desktop, and laptop viewports 195 | 196 | 197 | [](https://accounts.lambdatest.com/register?utm_source=github&utm_medium=repo&utm_campaign=geb-parallel-sample-code) 198 | 199 | 200 | ## We are here to help you :headphones: 201 | 202 | * Got a query? we are available 24x7 to help. [Contact Us](mailto:support@lambdatest.com) 203 | * For more info, visit - [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=geb-parallel-sample-code) 204 | -------------------------------------------------------------------------------- /capabilities: -------------------------------------------------------------------------------- 1 | {"build": "GebParallelTest", "platform": "Windows 10", "browserName": "Microsoft Edge", "version":"latest"} 2 | {"build": "GebParallelTest", "platform": "Windows 10", "browserName": "Chrome", "version":"latest"} 3 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.lambdatest 8 | geb-groovy-spock-lambda 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | org.apache.maven.plugins 14 | maven-surefire-plugin 15 | 2.19 16 | 17 | 6 18 | false 19 | -Duser.language=en 20 | -Xmx1024m 21 | -Xms256m 22 | -XX:MaxPermSize=256m 23 | -Dfile.encoding=UTF-8 24 | false 25 | 26 | *Spec.* 27 | 28 | 29 | target/test-reports/geb 30 | 31 | 32 | 33 | 34 | 35 | org.codehaus.gmaven 36 | gmaven-plugin 37 | 1.4 38 | 39 | 40 | 1.8 41 | 42 | 43 | 44 | 45 | testCompile 46 | 47 | 48 | 49 | 50 | ${pom.basedir}/src/test/groovy 51 | 52 | **/*.groovy 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | org.codehaus.gmaven.runtime 62 | gmaven-runtime-1.8 63 | 1.4 64 | 65 | 66 | org.codehaus.groovy 67 | groovy-all 68 | 69 | 70 | 71 | 72 | org.codehaus.groovy 73 | groovy-all 74 | 2.4.7 75 | 76 | 77 | org.spockframework 78 | spock-core 79 | 1.0-groovy-2.4 80 | 81 | 82 | org.codehaus.groovy 83 | groovy-all 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | org.codehaus.groovy 95 | groovy-all 96 | 2.4.7 97 | 98 | 99 | junit 100 | junit 101 | 4.12 102 | test 103 | 104 | 105 | 106 | org.spockframework 107 | spock-core 108 | 1.0-groovy-2.4 109 | test 110 | 111 | 112 | org.codehaus.groovy 113 | groovy-all 114 | 115 | 116 | 117 | 118 | org.gebish 119 | geb-spock 120 | 0.13.1 121 | test 122 | 123 | 124 | org.seleniumhq.selenium 125 | selenium-firefox-driver 126 | 2.53.1 127 | test 128 | 129 | 130 | 131 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | while read config 3 | do 4 | echo "Running config $config" 5 | mvn -Dlambdageb.capabilities="$config" clean test & 6 | done < capabilities -------------------------------------------------------------------------------- /src/test/groovy/GebConfig.groovy: -------------------------------------------------------------------------------- 1 | atCheckWaiting = true 2 | cacheDriver = false 3 | autoClearCookies = false 4 | driver = {} 5 | -------------------------------------------------------------------------------- /src/test/groovy/Pages/DuckDuckGoQueryPage.groovy: -------------------------------------------------------------------------------- 1 | package Pages 2 | 3 | import geb.Page 4 | 5 | class DuckDuckGoQueryPage extends Page { 6 | 7 | static url = "https://www.duckduckgo.com/" 8 | 9 | static at = { title.contentEquals("DuckDuckGo — Privacy, simplified.") } 10 | 11 | static content = { 12 | searchField { $("input", id: "search_form_input_homepage")} 13 | searchButton { $("input", id:"search_button_homepage") } 14 | displayCheck { $("input", id:"search_button_homepage") } 15 | } 16 | 17 | void search(String word) { 18 | 19 | searchField.value(word) 20 | println(displayCheck.displayed) 21 | println(displayCheck.isDisplayed()) 22 | searchButton.click() 23 | 24 | } 25 | } -------------------------------------------------------------------------------- /src/test/groovy/Pages/DuckDuckGoResultPage.groovy: -------------------------------------------------------------------------------- 1 | package Pages 2 | 3 | class DuckDuckGoResultPage extends DuckDuckGoQueryPage { 4 | 5 | public static String searchWord; 6 | 7 | static at = { title.startsWith(searchWord) } 8 | } -------------------------------------------------------------------------------- /src/test/groovy/Spec/BasePageGebSpec.groovy: -------------------------------------------------------------------------------- 1 | package Spec 2 | 3 | import geb.spock.GebSpec 4 | import groovy.json.JsonSlurper 5 | import org.junit.Rule 6 | import org.junit.rules.TestName 7 | import org.openqa.selenium.remote.DesiredCapabilities 8 | import org.openqa.selenium.remote.RemoteWebDriver 9 | import org.openqa.selenium.JavascriptExecutor; 10 | import spock.lang.Stepwise 11 | 12 | class BasePageGebSpec extends GebSpec { 13 | public String username = System.getenv("LT_USERNAME") 14 | public String accessKey = System.getenv("LT_ACCESS_KEY") 15 | private String status="passed" 16 | 17 | /** 18 | * Represents the browser to be used as part of the test run. 19 | */ 20 | private String browser 21 | /** 22 | * Represents the operating system to be used as part of the test run. 23 | */ 24 | private String os 25 | /** 26 | * Represents the version of the browser to be used as part of the test run. 27 | */ 28 | private String version 29 | /** 30 | * Represents the deviceName of mobile device 31 | */ 32 | private String deviceName 33 | /** 34 | * Represents the device-orientation of mobile device 35 | */ 36 | private String deviceOrientation 37 | /** 38 | * Instance variable which contains the Sauce Job Id. 39 | */ 40 | private String sessionId 41 | 42 | private static boolean driverCreated 43 | 44 | @Rule 45 | public TestName name = new TestName() { 46 | public String getMethodName() { 47 | return super.getMethodName() 48 | } 49 | } 50 | 51 | private isSpecStepwise() { 52 | this.class.getAnnotation(Stepwise) != null 53 | } 54 | 55 | /** 56 | * 57 | * @return the value of the Sauce Job id. 58 | */ 59 | public String getSessionId() { 60 | return sessionId 61 | } 62 | 63 | public void setupSpec() throws Exception { 64 | driverCreated = false 65 | } 66 | 67 | public void setup() throws Exception { 68 | Map capMap 69 | String capabilityString = System.getProperty("lambdageb.capabilities") 70 | 71 | 72 | if (capabilityString) { 73 | capMap = new JsonSlurper().parseText(capabilityString) 74 | DesiredCapabilities capabilities = new DesiredCapabilities(capMap) 75 | String methodName = name.getMethodName() 76 | String specName = this.class.getSimpleName() 77 | if(isSpecStepwise()){ 78 | methodName = "All tests in " + specName 79 | } 80 | capabilities.setCapability("name", String.format("%s.%s", specName, methodName)) 81 | capabilities.setCapability("newCommandTimeout", 180) 82 | driver = new RemoteWebDriver( 83 | new URL("https://" + username + ":" + accessKey + 84 | "@hub.lambdatest.com/wd/hub"), capabilities) 85 | 86 | this.sessionId = (((RemoteWebDriver) driver).getSessionId()).toString() 87 | } 88 | driverCreated = true 89 | } 90 | 91 | @Override 92 | public void cleanup() throws Exception { 93 | if(!isSpecStepwise()){ 94 | ((JavascriptExecutor) driver).executeScript("lambda-status=" + status); 95 | driver.quit() 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/test/groovy/Spec/BingSpecPageGebSpec.groovy: -------------------------------------------------------------------------------- 1 | package Spec 2 | /** 3 | * Created by Arpit Gupta on 12-12-2019. 4 | */ 5 | 6 | import Pages.DuckDuckGoQueryPage 7 | import Pages.DuckDuckGoResultPage 8 | import geb.driver.CachingDriverFactory 9 | 10 | class BingSpecPageGebSpec extends BasePageGebSpec { 11 | 12 | def cleanup() { 13 | CachingDriverFactory.clearCache() 14 | } 15 | 16 | def "Geb Code: LambdaTest Grid"() { 17 | String q = "FactWish facts" 18 | DuckDuckGoResultPage.searchWord = q 19 | 20 | when: 21 | to DuckDuckGoQueryPage 22 | 23 | and: 24 | search(q) 25 | 26 | then: 27 | waitFor {at DuckDuckGoResultPage} 28 | 29 | 30 | } 31 | } 32 | --------------------------------------------------------------------------------