Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion java/src/dev/selenium/tools/javadoc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ java_binary(
],
deps = [
"//java/src/org/openqa/selenium:core",
"//java/src/org/openqa/selenium/os",
"//java/src/org/openqa/selenium/io",
"@rules_jvm_external//private/tools/java/com/github/bazelbuild/rules_jvm_external/zip",
],
)
1 change: 1 addition & 0 deletions java/src/org/openqa/selenium/io/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ java_library(
name = "io",
srcs = glob(["*.java"]),
visibility = [
"//java/src/dev/selenium/tools/javadoc:__pkg__",
"//java/src/dev/selenium/tools/modules:__pkg__",
"//java/src/org/openqa/selenium:__pkg__",
"//java/src/org/openqa/selenium/os:__pkg__",
Expand Down
1 change: 1 addition & 0 deletions java/test/org/openqa/selenium/testing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ java_library(
artifact("org.junit.platform:junit-platform-commons"),
artifact("org.eclipse.mylyn.github:org.eclipse.egit.github.core"),
artifact("org.assertj:assertj-core"),
artifact("org.jspecify:jspecify"),
] + JUNIT5_DEPS,
)

Expand Down
3 changes: 2 additions & 1 deletion java/test/org/openqa/selenium/testing/JupiterTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.net.URL;
import java.time.Duration;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -73,7 +74,7 @@ public void prepareEnvironment() {
} catch (IllegalStateException ex) {
// this should not happen with bazel, a new JVM is used for each class
// the annotation is on class level, so we should never see this
LOG.info("appServer is restarted with secureServer=true");
LOG.log(Level.WARNING, "appServer is restarted with secureServer=true", ex);
environment.stop();
environment = new InProcessTestEnvironment(true);
}
Expand Down
25 changes: 18 additions & 7 deletions java/test/org/openqa/selenium/testing/SeleniumExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;
import org.jspecify.annotations.NonNull;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
Expand Down Expand Up @@ -95,7 +97,7 @@ public void beforeEach(ExtensionContext context) throws Exception {
if (noDriverBeforeTest.isPresent()) {
NoDriverBeforeTest annotation = noDriverBeforeTest.get();
if (current.matches(annotation.value())) {
LOG.info("Destroying driver before test " + context.getDisplayName());
LOG.info(() -> "Destroying driver before test " + displayName(context));
removeDriver();
nullDriver = true;
return;
Expand All @@ -106,13 +108,13 @@ public void beforeEach(ExtensionContext context) throws Exception {
if (needsFreshDriver.isPresent()) {
NeedsFreshDriver annotation = needsFreshDriver.get();
if (current.matches(annotation.value())) {
LOG.info("Restarting driver before test " + context.getDisplayName());
LOG.info(() -> "Restarting driver before test " + displayName(context));
removeDriver();
}
}

// TraceMethodNameRule.starting
LOG.info(">>> Starting " + context.getDisplayName());
LOG.info(() -> ">>> Starting " + displayName(context));

// NotYetImplementedRule
failedWithNotYetImplemented = false;
Expand All @@ -121,14 +123,22 @@ public void beforeEach(ExtensionContext context) throws Exception {
failedWithRemoteBuild = false;
}

@NonNull
private static String displayName(ExtensionContext context) {
return context
.getTestClass()
.map(testClass -> testClass.getSimpleName() + '.' + context.getDisplayName())
.orElse(context.getDisplayName());
}

@Override
public void afterEach(ExtensionContext context) throws Exception {
// SwitchToTopRule
SwitchToTopRule switchToTopRule = new SwitchToTopRule(context);
switchToTopRule.apply();

// TraceMethodNameRule.finished
LOG.info("<<< Finished " + context.getDisplayName());
LOG.info(() -> "<<< Finished " + displayName(context));

// CaptureLoggingRule
captureLoggingRule.endLogCapture();
Expand Down Expand Up @@ -250,9 +260,9 @@ public WebDriver getDriver() {
return null;
}

LOG.info("CREATING DRIVER");
LOG.info(() -> "CREATING DRIVER");
WebDriver driver = actuallyCreateDriver();
LOG.info("CREATED " + driver);
LOG.info(() -> "CREATED " + driver);
return driver;
}

Expand Down Expand Up @@ -293,7 +303,8 @@ public void removeDriver() {

try {
current.driver.quit();
} catch (RuntimeException ignored) {
} catch (RuntimeException e) {
LOG.log(Level.SEVERE, "Failed to quit browser: ", e);
// fall through
}

Expand Down
29 changes: 18 additions & 11 deletions java/test/org/openqa/selenium/testing/StaticResources.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,37 +49,44 @@ static void ensureAvailable() {
BazelBuild bazel = new BazelBuild();

// W3C emulation
bazel.build("//javascript/atoms/fragments:is-displayed");
copy("javascript/atoms/fragments/is-displayed.js", "org/openqa/selenium/remote/isDisplayed.js");
bazel.build("//javascript/webdriver/atoms:get-attribute");
copy(
"javascript/atoms/fragments/is-displayed.js",
"org/openqa/selenium/remote/isDisplayed.js",
() -> bazel.build("//javascript/atoms/fragments:is-displayed"));

copy(
"javascript/webdriver/atoms/get-attribute.js",
"org/openqa/selenium/remote/getAttribute.js");
"org/openqa/selenium/remote/getAttribute.js",
() -> bazel.build("//javascript/webdriver/atoms:get-attribute"));

// Relative locators
bazel.build("//javascript/atoms/fragments:find-elements");
copy(
"javascript/atoms/fragments/find-elements.js",
"org/openqa/selenium/support/locators/findElements.js");
"org/openqa/selenium/support/locators/findElements.js",
() -> bazel.build("//javascript/atoms/fragments:find-elements"));

// Firefox XPI
copy(
"third_party/js/selenium/webdriver_prefs.json",
"org/openqa/selenium/firefox/webdriver_prefs.json");
bazel.build("third_party/js/selenium:webdriver_xpi");
copy("third_party/js/selenium/webdriver.xpi", "org/openqa/selenium/firefox/xpi/webdriver.xpi");
"org/openqa/selenium/firefox/webdriver_prefs.json",
() -> bazel.build("third_party/js/selenium:webdriver_json"));
copy(
"third_party/js/selenium/webdriver.xpi",
"org/openqa/selenium/firefox/xpi/webdriver.xpi",
() -> bazel.build("third_party/js/selenium:webdriver_xpi"));
}

private static void copy(String copyFrom, String copyTo) {
private static void copy(String copyFrom, String copyTo, Runnable build) {
try {
Path source = InProject.locate("bazel-bin").resolve(copyFrom);
Path dest = InProject.locate("java/build/test").resolve(copyTo);

if (Files.exists(dest)) {
// Assume we're good.
// Target file already exists, no need to copy.
return;
}

build.run();
Files.createDirectories(dest.getParent());
Files.copy(source, dest);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ private static Optional<Supplier<WebDriver>> createDelegate(Capabilities desired
return Optional.of(ctor.newInstance(desiredCapabilities));
} catch (InvocationTargetException e) {
throw new RuntimeException(e.getTargetException());
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand All @@ -120,6 +122,8 @@ private static Optional<Class<? extends Supplier<WebDriver>>> getDelegateClass()
Class<? extends Supplier<WebDriver>> clazz =
(Class<? extends Supplier<WebDriver>>) Class.forName(delegateClassName);
return Optional.of(clazz);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand All @@ -144,11 +148,12 @@ private ExternalServerDriverSupplier(URL serverUrl, Supplier<WebDriver> delegate
@Override
public WebDriver get() {
try {
LOG.info("Waiting for server to be ready at " + serverUrl);
LOG.info(() -> "Waiting for server to be ready at " + serverUrl);
new UrlChecker().waitUntilAvailable(60, SECONDS, new URL(serverUrl + "/status"));
LOG.info("Server is ready");
LOG.info(() -> "Server is ready at " + serverUrl);
} catch (UrlChecker.TimeoutException e) {
throw new RuntimeException("The external server is not accepting commands", e);
throw new RuntimeException(
"The external server is not accepting commands at " + serverUrl, e);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -133,7 +134,7 @@ public OutOfProcessSeleniumServer start(String mode, String... extraFlags) {
new UrlChecker().waitUntilAvailable(10, SECONDS, url);
LOG.info("Server is ready");
} catch (UrlChecker.TimeoutException e) {
LOG.severe("Server failed to start: " + e.getMessage());
LOG.log(Level.SEVERE, "Server failed to start: " + e.getMessage(), e);
process.shutdown();
LOG.severe(process.getOutput());
process = null;
Expand Down Expand Up @@ -176,6 +177,7 @@ private String buildServerAndClasspath() {
return location;
}
} catch (IOException e) {
LOG.log(Level.SEVERE, "Failed to build server", e);
// Fall through
}

Expand Down
Loading