├── .github ├── FUNDING.yml ├── dependabot.yml └── workflows │ ├── auto-merge.yml │ └── build.yml ├── .gitignore ├── README.md ├── pom.xml └── src ├── main ├── java │ └── io │ │ └── github │ │ └── bonigarcia │ │ └── wdm │ │ └── SpringBootDemoApp.java └── resources │ ├── logback.xml │ └── static │ ├── index.html │ └── other.html └── test ├── java └── io │ └── github │ └── bonigarcia │ └── wdm │ └── test │ └── SpringChromeTest.java └── resources └── logback-test.xml /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: webdrivermanager 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | custom: # Replace with a single custom sponsorship URL 10 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: maven 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: '06:00' 8 | open-pull-requests-limit: 99 9 | -------------------------------------------------------------------------------- /.github/workflows/auto-merge.yml: -------------------------------------------------------------------------------- 1 | name: Dependabot auto-merge 2 | on: pull_request 3 | 4 | permissions: 5 | contents: write 6 | pull-requests: write 7 | 8 | jobs: 9 | dependabot: 10 | runs-on: ubuntu-latest 11 | if: ${{ github.actor == 'dependabot[bot]' }} 12 | steps: 13 | - name: Dependabot metadata 14 | id: metadata 15 | uses: dependabot/fetch-metadata@v1.1.1 16 | with: 17 | github-token: "${{ secrets.GITHUB_TOKEN }}" 18 | - name: Enable auto-merge for Dependabot PRs 19 | run: | 20 | gh pr merge "$PR_URL" --auto --squash --body="Co-authored-by: Boni Garcia " 21 | env: 22 | PR_URL: ${{github.event.pull_request.html_url}} 23 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 24 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Checkout GitHub repo 14 | uses: actions/checkout@v2 15 | - name: Setup Java 16 | uses: actions/setup-java@v1 17 | with: 18 | java-version: 17 19 | - name: Start Xvfb 20 | run: Xvfb :99 & 21 | - name: Run tests 22 | run: mvn -B test 23 | env: 24 | DISPLAY: :99 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | target 3 | .classpath 4 | .project 5 | .settings 6 | /.idea 7 | *.iml 8 | phantomjsdriver.log 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Maven Central](https://img.shields.io/maven-central/v/io.github.bonigarcia/webdrivermanager.svg)](https://search.maven.org/#search%7Cga%7C1%7Cg%3Aio.github.bonigarcia%20a%3Awebdrivermanager) 2 | [![Build Status](https://github.com/bonigarcia/webdrivermanager-spring-boot/workflows/build/badge.svg)](https://github.com/bonigarcia/webdrivermanager-spring-boot/actions) 3 | [![badge-jdk](https://img.shields.io/badge/jdk-17-green.svg)](https://www.oracle.com/java/technologies/downloads/) 4 | [![License badge](https://img.shields.io/badge/license-Apache2-green.svg)](https://www.apache.org/licenses/LICENSE-2.0) 5 | [![Backers on Open Collective](https://opencollective.com/webdrivermanager/backers/badge.svg)](#backers) 6 | [![Sponsors on Open Collective](https://opencollective.com/webdrivermanager/sponsors/badge.svg)](#sponsors) 7 | [![Support badge](https://img.shields.io/badge/stackoverflow-webdrivermanager_java-green.svg?logo=stackoverflow)](https://stackoverflow.com/questions/tagged/webdrivermanager-java) 8 | [![Twitter Follow](https://img.shields.io/twitter/follow/boni_gg.svg?style=social)](https://twitter.com/boni_gg) 9 | 10 | # WebDriverManager Spring-Boot example [![][Logo]][GitHub Repository] 11 | 12 | This repository contains a basic project with JUnit tests using [Spring Boot], [Selenium WebDriver] and [WebDriverManager]. This code is open source, released under the terms of [Apache 2.0 License]. 13 | 14 | ## Usage 15 | 16 | In order to use WebDriverManager from tests in a Maven project, you need to add the following dependency in your `pom.xml` (Java 8 or upper required): 17 | 18 | ```xml 19 | 20 | io.github.bonigarcia 21 | webdrivermanager 22 | ${wdm.version} 23 | test 24 | 25 | ``` 26 | 27 | ... or in Gradle project: 28 | 29 | ``` 30 | dependencies { 31 | testImplementation("io.github.bonigarcia:webdrivermanager:${wdm.version}") 32 | } 33 | ``` 34 | 35 | Then you can let WebDriverManager to do manage WebDriver binaries for your application/test. For example, as a JUnit test using Chrome browser: 36 | 37 | ```java 38 | public class ChromeTest { 39 | 40 | private WebDriver driver; 41 | 42 | @BeforeClass 43 | public static void setupClass() { 44 | WebDriverManager.chromedriver().setup(); 45 | } 46 | 47 | @Before 48 | public void setupTest() { 49 | driver = new ChromeDriver(); 50 | } 51 | 52 | @After 53 | public void teardown() { 54 | if (driver != null) { 55 | driver.quit(); 56 | } 57 | } 58 | 59 | @Test 60 | public void test() { 61 | // Your test code here 62 | } 63 | 64 | } 65 | ``` 66 | 67 | ... and using Firefox: 68 | 69 | ```java 70 | public class FirefoxTest { 71 | 72 | private WebDriver driver; 73 | 74 | @BeforeClass 75 | public static void setupClass() { 76 | WebDriverManager.firefoxdriver().setup(); 77 | } 78 | 79 | @Before 80 | public void setupTest() { 81 | driver = new FirefoxDriver(); 82 | } 83 | 84 | @After 85 | public void teardown() { 86 | if (driver != null) { 87 | driver.quit(); 88 | } 89 | } 90 | 91 | @Test 92 | public void test() { 93 | // Your test code here 94 | } 95 | 96 | } 97 | ``` 98 | 99 | ## Help 100 | 101 | If you have questions on how to use WebDriverManager properly with a special configuration or suchlike, please consider asking a question on [Stack Overflow] and tag it with *webdrivermanager-java*. 102 | 103 | ## Support 104 | 105 | WebDriverManager is part of [OpenCollective], an online funding platform for open and transparent communities. You can support the project by contributing as a backer (i.e., a personal [donation] or [recurring contribution]) or as a [sponsor] (i.e., a recurring contribution by a company). 106 | 107 | ### Backers 108 | 109 | 110 | 111 | ### Sponsors 112 | 113 | 114 | 115 | 116 | 117 | ## About 118 | 119 | WebDriverManager (Copyright © 2015-2023) is a project created and maintained by [Boni Garcia] licensed under [Apache 2.0 License]. 120 | 121 | [Apache 2.0 License]: https://www.apache.org/licenses/LICENSE-2.0 122 | [Boni Garcia]: https://bonigarcia.github.io/ 123 | [Selenium WebDriver]: https://docs.seleniumhq.org/projects/webdriver/ 124 | [WebDriverManager]:https://github.com/bonigarcia/webdrivermanager/ 125 | [Logo]: https://bonigarcia.github.io/img/webdrivermanager.png 126 | [GitHub Repository]: https://github.com/bonigarcia/webdrivermanager-spring-boot 127 | [Spring Boot]: https://spring.io/projects/spring-boot 128 | [Stack Overflow]: https://stackoverflow.com/questions/tagged/webdrivermanager-java 129 | [OpenCollective]: https://opencollective.com/webdrivermanager 130 | [donation]: https://opencollective.com/webdrivermanager/donate 131 | [recurring contribution]: https://opencollective.com/webdrivermanager/contribute/backer-8132/checkout 132 | [sponsor]: https://opencollective.com/webdrivermanager/contribute/sponsor-8133/checkout 133 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | io.github.bonigarcia 7 | webdrivermanager-spring-boot 8 | 1.0.0 9 | 10 | 11 | org.springframework.boot 12 | spring-boot-starter-parent 13 | 3.5.0 14 | 15 | 16 | 17 | 18 | 6.1.0 19 | 5.5 20 | 21 | 17 22 | ${java.version} 23 | ${java.version} 24 | 25 | UTF-8 26 | ${project.encondig} 27 | ${project.encondig} 28 | 29 | 30 | 31 | 32 | org.slf4j 33 | slf4j-api 34 | 35 | 36 | ch.qos.logback 37 | logback-classic 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-starter 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-web 46 | 47 | 48 | 49 | org.springframework.boot 50 | spring-boot-starter-test 51 | test 52 | 53 | 54 | org.junit.jupiter 55 | junit-jupiter 56 | test 57 | 58 | 59 | org.seleniumhq.selenium 60 | selenium-java 61 | test 62 | 63 | 64 | io.github.bonigarcia 65 | webdrivermanager 66 | ${wdm.version} 67 | test 68 | 69 | 70 | org.apache.httpcomponents.client5 71 | httpclient5 72 | ${httpclient5.version} 73 | test 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /src/main/java/io/github/bonigarcia/wdm/SpringBootDemoApp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2021 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia.wdm; 18 | 19 | import org.springframework.boot.SpringApplication; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | 22 | /** 23 | * Basic spring-boot application. 24 | * 25 | * @author Boni Garcia (boni.gg@gmail.com) 26 | * @since 1.0.0 27 | */ 28 | @SpringBootApplication 29 | public class SpringBootDemoApp { 30 | 31 | public static void main(String[] args) { 32 | SpringApplication.run(SpringBootDemoApp.class, args); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Spring Boot Test - Page 1 5 | 6 | 7 | 8 |

Home page

9 | Go to another page. 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/main/resources/static/other.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Spring Boot Test - Page 2 5 | 6 | 7 | 8 |

Other page

9 | Hello! 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/test/java/io/github/bonigarcia/wdm/test/SpringChromeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * (C) Copyright 2021 Boni Garcia (https://bonigarcia.github.io/) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package io.github.bonigarcia.wdm.test; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | 21 | import org.junit.jupiter.api.AfterEach; 22 | import org.junit.jupiter.api.BeforeAll; 23 | import org.junit.jupiter.api.BeforeEach; 24 | import org.junit.jupiter.api.Test; 25 | import org.junit.jupiter.api.extension.ExtendWith; 26 | import org.openqa.selenium.By; 27 | import org.openqa.selenium.WebDriver; 28 | import org.openqa.selenium.chrome.ChromeDriver; 29 | import org.openqa.selenium.chrome.ChromeOptions; 30 | import org.springframework.boot.test.context.SpringBootTest; 31 | import org.springframework.boot.test.web.server.LocalServerPort; 32 | import org.springframework.test.context.junit.jupiter.SpringExtension; 33 | 34 | import io.github.bonigarcia.wdm.SpringBootDemoApp; 35 | import io.github.bonigarcia.wdm.WebDriverManager; 36 | 37 | /** 38 | * Test using a local web application based on spring-boot. 39 | * 40 | * @author Boni Garcia (boni.gg@gmail.com) 41 | * @since 1.0.0 42 | */ 43 | @ExtendWith(SpringExtension.class) 44 | @SpringBootTest(classes = SpringBootDemoApp.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 45 | class SpringChromeTest { 46 | 47 | WebDriver driver; 48 | 49 | @LocalServerPort 50 | int serverPort; 51 | 52 | @BeforeAll 53 | static void setupClass() { 54 | WebDriverManager.chromedriver().setup(); 55 | } 56 | 57 | @BeforeEach 58 | void setupTest() { 59 | ChromeOptions options = new ChromeOptions(); 60 | options.addArguments("--remote-allow-origins=*"); 61 | driver = new ChromeDriver(options); 62 | } 63 | 64 | @AfterEach 65 | void teardown() { 66 | if (driver != null) { 67 | driver.quit(); 68 | } 69 | } 70 | 71 | @Test 72 | void test() { 73 | // Open system under test 74 | driver.get("http://localhost:" + serverPort); 75 | 76 | // Verify first page title 77 | String firstPageTitle = driver.getTitle(); 78 | String expectedFirstPageTitle = "Spring Boot Test - Page 1"; 79 | assertEquals(expectedFirstPageTitle, firstPageTitle); 80 | 81 | // Click on link 82 | driver.findElement(By.linkText("another")).click(); 83 | 84 | // Verify second page caption 85 | String secondPageCaption = driver.findElement(By.id("caption")) 86 | .getText(); 87 | String expectedSecondPageTitle = "Other page"; 88 | assertEquals(expectedSecondPageTitle, secondPageCaption); 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36}.%M\(%line\) -- %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | --------------------------------------------------------------------------------