Skip to content

Commit

Permalink
[java] Fixing ChromeOptionsFunctionalTest and formatting files
Browse files Browse the repository at this point in the history
  • Loading branch information
diemol committed Jun 7, 2023
1 parent 0f0f706 commit 02744ac
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 30 deletions.
3 changes: 2 additions & 1 deletion java/src/org/openqa/selenium/WebDriverException.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public class WebDriverException extends RuntimeException {

public static final String SESSION_ID = "Session ID";
public static final String DRIVER_INFO = "Driver info";
protected static final String BASE_SUPPORT_URL = "https://www.selenium.dev/documentation/webdriver/troubleshooting/errors";
protected static final String BASE_SUPPORT_URL =
"https://www.selenium.dev/documentation/webdriver/troubleshooting/errors";

private final Map<String, String> extraInfo = new ConcurrentHashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import org.openqa.selenium.remote.service.DriverService;

/**
* Thrown by {@link org.openqa.selenium.remote.service.DriverFinder#getPath(DriverService, Capabilities)}.
* Thrown by {@link org.openqa.selenium.remote.service.DriverFinder#getPath(DriverService,
* Capabilities)}.
*/
public class NoSuchDriverException extends WebDriverException {

Expand Down
6 changes: 3 additions & 3 deletions java/src/org/openqa/selenium/remote/service/DriverFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public static String getPath(DriverService service, Capabilities options) {
try {
exePath = SeleniumManager.getInstance().getDriverPath(options);
} catch (Exception e) {
throw new NoSuchDriverException(String.format(
"Unable to obtain: %s", options), e);
throw new NoSuchDriverException(String.format("Unable to obtain: %s", options), e);
}
}

Expand All @@ -37,7 +36,8 @@ public static String getPath(DriverService service, Capabilities options) {
} else if (!new File(exePath).exists()) {
message = String.format("%s located at %s, but invalid", service.getDriverName(), exePath);
} else if (!new File(exePath).canExecute()) {
message = String.format("%s located at %s, cannot be executed", service.getDriverName(), exePath);
message =
String.format("%s located at %s, cannot be executed", service.getDriverName(), exePath);
} else {
return exePath;
}
Expand Down
19 changes: 9 additions & 10 deletions java/test/org/openqa/selenium/ClickTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@

package org.openqa.selenium;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.testing.Ignore;
import org.openqa.selenium.testing.JupiterTestBase;
import org.openqa.selenium.testing.NoDriverAfterTest;
import org.openqa.selenium.testing.NotYetImplemented;
import org.openqa.selenium.testing.SwitchToTopAfterTest;

import java.util.Set;

import static org.assertj.core.api.Assertions.assertThat;
import static org.openqa.selenium.WaitingConditions.newWindowIsOpened;
import static org.openqa.selenium.WaitingConditions.pageSourceToContain;
Expand All @@ -35,6 +25,15 @@
import static org.openqa.selenium.testing.drivers.Browser.IE;
import static org.openqa.selenium.testing.drivers.Browser.SAFARI;

import java.util.Set;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.testing.Ignore;
import org.openqa.selenium.testing.JupiterTestBase;
import org.openqa.selenium.testing.NoDriverAfterTest;
import org.openqa.selenium.testing.NotYetImplemented;
import org.openqa.selenium.testing.SwitchToTopAfterTest;

class ClickTest extends JupiterTestBase {

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.build.InProject;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.testing.JupiterTestBase;
import org.openqa.selenium.testing.NoDriverBeforeTest;
import org.openqa.selenium.testing.drivers.Browser;
Expand All @@ -49,8 +50,9 @@ public void canStartChromeWithCustomOptions() {
localDriver = seleniumExtension.createNewDriver(options);

localDriver.get(pages.clickJacker);

Object userAgent =
((ChromeDriver) localDriver).executeScript("return window.navigator.userAgent");
((RemoteWebDriver) localDriver).executeScript("return window.navigator.userAgent");
assertThat(userAgent).isEqualTo("foo;bar");
}

Expand All @@ -70,7 +72,8 @@ public void canSetAcceptInsecureCerts() {
options.setAcceptInsecureCerts(true);
localDriver = seleniumExtension.createNewDriver(options);

assertThat(((ChromeDriver) localDriver).getCapabilities().getCapability(ACCEPT_INSECURE_CERTS))
assertThat(
((RemoteWebDriver) localDriver).getCapabilities().getCapability(ACCEPT_INSECURE_CERTS))
.isEqualTo(true);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package org.openqa.selenium.testing;

import org.openqa.selenium.testing.drivers.Browser;

import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.openqa.selenium.testing.drivers.Browser;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Repeatable(NotWorkingInRemoteBazelBuildsList.class)
public @interface NotWorkingInRemoteBazelBuilds {

Browser value() default Browser.ALL;

}
21 changes: 11 additions & 10 deletions java/test/org/openqa/selenium/testing/SeleniumExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,19 @@ public void afterEach(ExtensionContext context) throws Exception {
current));
}

NotWorkingInRemoteBazelBuildsRule notWorkingInRemoteBuilds = new NotWorkingInRemoteBazelBuildsRule(context);
NotWorkingInRemoteBazelBuildsRule notWorkingInRemoteBuilds =
new NotWorkingInRemoteBazelBuildsRule(context);
boolean isNotExpectedToWork = notWorkingInRemoteBuilds.check();

if (isNotExpectedToWork && !failedWithRemoteBuild) {
Optional<Class<?>> testClass = context.getTestClass();
Optional<Method> testMethod = context.getTestMethod();
throw new Exception(
String.format(
"%s.%s is not yet expected to work on remote builds using %s, but it already works!",
testClass.map(Class::getName).orElse(""),
testMethod.map(Method::getName).orElse(""),
Browser.detect()));
String.format(
"%s.%s is not yet expected to work on remote builds using %s, but it already works!",
testClass.map(Class::getName).orElse(""),
testMethod.map(Method::getName).orElse(""),
Browser.detect()));
}
}

Expand Down Expand Up @@ -220,7 +221,8 @@ public void handleTestExecutionException(ExtensionContext context, Throwable thr
failedWithNotYetImplemented = true;
}

NotWorkingInRemoteBazelBuildsRule notWorkingInRemoteBuilds = new NotWorkingInRemoteBazelBuildsRule(context);
NotWorkingInRemoteBazelBuildsRule notWorkingInRemoteBuilds =
new NotWorkingInRemoteBazelBuildsRule(context);
if (notWorkingInRemoteBuilds.check()) {
failedWithRemoteBuild = true;
}
Expand Down Expand Up @@ -336,7 +338,6 @@ public boolean check() throws Exception {
findRepeatableAnnotations(element, NotYetImplemented.class);
return notImplemented(notYetImplementedList) || notImplemented(notYetImplemented.stream());
}

}

private static class NotWorkingInRemoteBazelBuildsRule {
Expand All @@ -362,9 +363,9 @@ public boolean check() {

Optional<AnnotatedElement> element = context.getElement();
Optional<NotWorkingInRemoteBazelBuilds> notWorkingList =
findAnnotation(element, NotWorkingInRemoteBazelBuilds.class);
findAnnotation(element, NotWorkingInRemoteBazelBuilds.class);
List<NotWorkingInRemoteBazelBuilds> notWorking =
findRepeatableAnnotations(element, NotWorkingInRemoteBazelBuilds.class);
findRepeatableAnnotations(element, NotWorkingInRemoteBazelBuilds.class);
return notWorkingYet(notWorkingList) || notWorkingYet(notWorking.stream());
}
}
Expand Down

0 comments on commit 02744ac

Please sign in to comment.