-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove dependency upon internet URLs for selenium tests (#3271)
- Loading branch information
Showing
9 changed files
with
50 additions
and
156 deletions.
There are no files selected for viewing
50 changes: 25 additions & 25 deletions
50
modules/selenium/src/test/java/org/testcontainers/junit/BaseWebDriverContainerTest.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,62 +1,62 @@ | ||
package org.testcontainers.junit; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.junit.ClassRule; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.remote.RemoteWebDriver; | ||
import org.openqa.selenium.support.ui.ExpectedConditions; | ||
import org.openqa.selenium.support.ui.WebDriverWait; | ||
import org.testcontainers.containers.BrowserWebDriverContainer; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.Network; | ||
import org.testcontainers.containers.wait.strategy.HttpWaitStrategy; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static java.lang.String.format; | ||
import static org.rnorth.visibleassertions.VisibleAssertions.assertEquals; | ||
import static org.rnorth.visibleassertions.VisibleAssertions.assertTrue; | ||
|
||
/** | ||
* | ||
*/ | ||
public class BaseWebDriverContainerTest { | ||
|
||
protected void doSimpleWebdriverTest(BrowserWebDriverContainer rule) { | ||
@ClassRule | ||
public static Network NETWORK = Network.newNetwork(); | ||
|
||
@ClassRule | ||
public static GenericContainer<?> HELLO_WORLD = new GenericContainer<>(DockerImageName.parse("testcontainers/helloworld:1.0.0")) | ||
.withNetwork(NETWORK) | ||
.withNetworkAliases("helloworld") | ||
.withExposedPorts(8080, 8081) | ||
.waitingFor(new HttpWaitStrategy()); | ||
|
||
protected static void doSimpleExplore(BrowserWebDriverContainer<?> rule) { | ||
RemoteWebDriver driver = setupDriverFromRule(rule); | ||
System.out.println("Selenium remote URL is: " + rule.getSeleniumAddress()); | ||
System.out.println("VNC URL is: " + rule.getVncAddress()); | ||
|
||
driver.get("http://www.google.com"); | ||
WebElement search = driver.findElement(By.name("q")); | ||
search.sendKeys("testcontainers"); | ||
search.submit(); | ||
driver.get("http://helloworld:8080"); | ||
WebElement title = driver.findElement(By.tagName("h1")); | ||
|
||
List<WebElement> results = new WebDriverWait(driver, 15) | ||
.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("#search h3"))); | ||
|
||
assertTrue("the word 'testcontainers' appears in search results", | ||
results.stream() | ||
.anyMatch(el -> el.getText().contains("testcontainers"))); | ||
assertEquals("the index page contains the title 'Hello world'", | ||
"Hello world", | ||
title.getText().trim() | ||
); | ||
} | ||
|
||
protected void assertBrowserNameIs(BrowserWebDriverContainer rule, String expectedName) { | ||
protected void assertBrowserNameIs(BrowserWebDriverContainer<?> rule, String expectedName) { | ||
RemoteWebDriver driver = setupDriverFromRule(rule); | ||
String actual = driver.getCapabilities().getBrowserName(); | ||
assertTrue(format("actual browser name is %s", actual), | ||
actual.equals(expectedName)); | ||
} | ||
|
||
@NotNull | ||
private static RemoteWebDriver setupDriverFromRule(BrowserWebDriverContainer rule) { | ||
private static RemoteWebDriver setupDriverFromRule(BrowserWebDriverContainer<?> rule) { | ||
RemoteWebDriver driver = rule.getWebDriver(); | ||
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); | ||
return driver; | ||
} | ||
|
||
protected static void doSimpleExplore(BrowserWebDriverContainer rule) { | ||
RemoteWebDriver driver = setupDriverFromRule(rule); | ||
driver.get("http://en.wikipedia.org/wiki/Randomness"); | ||
|
||
// Oh! The irony! | ||
assertTrue("Randomness' description has the word 'pattern'", driver.findElementByPartialLinkText("pattern").isDisplayed()); | ||
} | ||
|
||
} |
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
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
31 changes: 0 additions & 31 deletions
31
modules/selenium/src/test/java/org/testcontainers/junit/FlakyContainerCreationTest.java
This file was deleted.
Oops, something went wrong.
69 changes: 0 additions & 69 deletions
69
modules/selenium/src/test/java/org/testcontainers/junit/LinkedContainerTest.java
This file was deleted.
Oops, something went wrong.
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