Created
October 4, 2018 13:05
-
-
Save dtelaroli/54895999944fb5a140c2cd62a93bef93 to your computer and use it in GitHub Desktop.
Spring Boot, Selenium and ChromeDriver Headless
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public class Beans { | |
@Bean @RequestScope(proxyMode = ScopedProxyMode.TARGET_CLASS) | |
public WebDriver webDriver() { | |
ChromeOptions options = new ChromeOptions() | |
.addArguments("--no-sandbox") | |
.setHeadless(true); | |
ChromeDriver driver = new ChromeDriver(options); | |
driver.setLogLevel(Level.WARNING); | |
return driver; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM openjdk:8-jdk | |
RUN apt install -y chromedriver | |
COPY target/app.jar app.jar | |
EXPOSE 8080 | |
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "./app.jar"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
@RequestMapping("/my") | |
public class MyController { | |
@Autowired | |
private WebDriver driver; | |
@GetMapping | |
public List<Log> index() { | |
driver.get("http://yourendpoint"); | |
//your asserts | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment