-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove dependency upon internet URLs for selenium tests #3271
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no real sense in having two ways to test that Selenium is working, so just removed this altogether.