forked from soraiareis/demo-spring-selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6363eb1
commit 9e39e35
Showing
8 changed files
with
147 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
version: "3" | ||
services: | ||
selenium-hub: | ||
image: selenium/hub | ||
container_name: selenium-hub | ||
ports: | ||
- "4444:4444" | ||
chrome: | ||
image: selenium/node-chrome | ||
volumes: | ||
- /dev/shm:/dev/shm | ||
depends_on: | ||
- selenium-hub | ||
environment: | ||
- HUB_HOST=selenium-hub | ||
- HUB_PORT=4444 | ||
firefox: | ||
image: selenium/node-firefox | ||
volumes: | ||
- /dev/shm:/dev/shm | ||
depends_on: | ||
- selenium-hub | ||
environment: | ||
- HUB_HOST=selenium-hub | ||
- HUB_PORT=4444 |
This file contains 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
This file contains 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
27 changes: 25 additions & 2 deletions
27
src/test/java/demo/spring/selenium/config/WebDriverManager.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,41 @@ | ||
package demo.spring.selenium.config; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.chrome.ChromeOptions; | ||
import org.openqa.selenium.firefox.FirefoxDriver; | ||
import org.openqa.selenium.firefox.FirefoxOptions; | ||
import org.openqa.selenium.remote.RemoteWebDriver; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Scope; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class WebDriverManager { | ||
|
||
private static final String DOCKER_HOST = "http://127.0.0.1"; | ||
private static final String SELENIUM_PORT = "4444"; | ||
private static final String CHROME = "chrome"; | ||
private static final String CONTEXT = "local"; | ||
|
||
@Autowired | ||
private DemoSpringSeleniumProperties properties; | ||
|
||
@Bean | ||
@Scope("cucumber-glue") | ||
public WebDriver webDriverFactory() { | ||
return new FirefoxDriver(); | ||
public WebDriver webDriverFactory() throws IOException { | ||
return properties.getContext().equalsIgnoreCase(CONTEXT) ? new FirefoxDriver() | ||
: getRemoteWebDriver(properties.getBrowser()); | ||
} | ||
|
||
private WebDriver getRemoteWebDriver(String browser) throws IOException { | ||
String remote = String.format("%s:%s/wd/hub", DOCKER_HOST, SELENIUM_PORT); | ||
if (browser.equalsIgnoreCase(CHROME)) { | ||
return new RemoteWebDriver(new URL(remote), new ChromeOptions()); | ||
} | ||
return new RemoteWebDriver(new URL(remote), new FirefoxOptions()); | ||
} | ||
} | ||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
context: remote | ||
browser: firefox | ||
|
||
host: https://soraia.herokuapp.com | ||
|
||
logging: | ||
|