Skip to content

Commit

Permalink
Merge branch 'SeleniumHQ:trunk' into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
VietND96 authored Jan 8, 2024
2 parents e951af5 + 9bcccf2 commit f403139
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 27 deletions.
42 changes: 20 additions & 22 deletions java/src/org/openqa/selenium/remote/service/DriverFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.io.File;
import java.util.logging.Logger;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.manager.SeleniumManager;
import org.openqa.selenium.manager.SeleniumManagerOutput.Result;
Expand All @@ -36,41 +35,40 @@ public static Result getPath(DriverService service, Capabilities options) {

public static Result getPath(DriverService service, Capabilities options, boolean offline) {
Require.nonNull("Browser options", options);
Result result = new Result(service.getExecutable());
if (result.getDriverPath() != null) {
LOG.fine(
String.format(
"Skipping Selenium Manager, path to %s specified in Service class: %s",
service.getDriverName(), result.getDriverPath()));
}
String driverName = service.getDriverName();

result = new Result(System.getProperty(service.getDriverProperty()));
Result result = new Result(service.getExecutable());
if (result.getDriverPath() == null) {
try {
result = SeleniumManager.getInstance().getDriverPath(options, offline);
} catch (RuntimeException e) {
throw new WebDriverException(
String.format("Unable to obtain: %s, error %s", options, e.getMessage()), e);
result = new Result(System.getProperty(service.getDriverProperty()));
if (result.getDriverPath() == null) {
try {
result = SeleniumManager.getInstance().getDriverPath(options, offline);
} catch (RuntimeException e) {
throw new NoSuchDriverException(
String.format("Unable to obtain: %s, error %s", options, e.getMessage()), e);
}
} else {
LOG.fine(
String.format(
"Skipping Selenium Manager, path to %s found in system property: %s",
driverName, result.getDriverPath()));
}
} else {
LOG.fine(
String.format(
"Skipping Selenium Manager, path to %s found in system property: %s",
service.getDriverName(), result.getDriverPath()));
"Skipping Selenium Manager, path to %s specified in Service class: %s",
driverName, result.getDriverPath()));
}

String message;
if (result.getDriverPath() == null) {
message = String.format("Unable to locate or obtain %s", service.getDriverName());
message = String.format("Unable to locate or obtain %s", driverName);
} else if (!new File(result.getDriverPath()).exists()) {
message =
String.format(
"%s at location %s, does not exist", service.getDriverName(), result.getDriverPath());
String.format("%s at location %s, does not exist", driverName, result.getDriverPath());
} else if (!new File(result.getDriverPath()).canExecute()) {
message =
String.format(
"%s located at %s, cannot be executed",
service.getDriverName(), result.getDriverPath());
String.format("%s located at %s, cannot be executed", driverName, result.getDriverPath());
} else {
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
import com.google.common.collect.ImmutableSet;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.util.function.Predicate;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -61,14 +62,16 @@ class DriverServiceSessionFactoryTest {
private DriverService driverService;

@BeforeEach
public void setUp() throws MalformedURLException {
public void setUp() throws IOException {
tracer = DefaultTestTracer.createTracer();

clientFactory = mock(HttpClient.Factory.class);

driverService = mock(DriverService.class);
when(driverService.getUrl()).thenReturn(new URL("http://localhost:1234/"));
when(driverService.getExecutable()).thenReturn("/usr/bin/driver");
Path driverFile = Files.createTempFile("testDriver", ".tmp");
driverFile.toFile().setExecutable(true);
when(driverService.getExecutable()).thenReturn(driverFile.toString());

builder = mock(DriverService.Builder.class);
when(builder.build()).thenReturn(driverService);
Expand Down Expand Up @@ -147,10 +150,10 @@ void shouldNotInstantiateSessionIfRemoteEndReturnsInvalidResponse() throws IOExc
verify(builder, times(1)).build();
verifyNoMoreInteractions(builder);
verify(driverService, times(1)).getExecutable();
verify(driverService, times(1)).setExecutable(any(String.class));
verify(driverService, times(1)).start();
verify(driverService, atLeastOnce()).getUrl();
verify(driverService, times(1)).stop();
verifyNoMoreInteractions(driverService);
}

@Test
Expand Down Expand Up @@ -179,9 +182,9 @@ void shouldInstantiateSessionIfEverythingIsOK() throws IOException {
verify(builder, times(1)).build();
verifyNoMoreInteractions(builder);
verify(driverService, times(1)).getExecutable();
verify(driverService, times(1)).setExecutable(any(String.class));
verify(driverService, times(1)).start();
verify(driverService, atLeastOnce()).getUrl();
verifyNoMoreInteractions(driverService);
}

private DriverServiceSessionFactory factoryFor(String browser, DriverService.Builder builder) {
Expand Down
19 changes: 19 additions & 0 deletions javascript/node/selenium-webdriver/bidi/browsingContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,25 @@ class BrowsingContext {
throw Error(result['error'])
}
}

async traverseHistory(delta) {
const params = {
method: 'browsingContext.traverseHistory',
params: {
context: this._id,
delta: delta,
},
}
await this.bidi.send(params)
}

async forward() {
await this.traverseHistory(1)
}

async back() {
await this.traverseHistory(-1)
}
}

class NavigateResult {
Expand Down
33 changes: 33 additions & 0 deletions javascript/node/selenium-webdriver/test/bidi/bidi_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,39 @@ suite(
)
assert.equal(devicePixelRatio, 5)
})
xit('can navigate back in the browser history', async function () {
const id = await driver.getWindowHandle()
const browsingContext = await BrowsingContext(driver, {
browsingContextId: id,
})

await driver.get(Pages.formPage)

await driver.wait(until.elementLocated(By.id('imageButton')), 10000).submit()
await driver.wait(until.titleIs('We Arrive Here'), 5000)

await browsingContext.back()

await driver.wait(until.titleIs('We Leave From Here'), 5000)
})

xit('can navigate forward in the browser history', async function () {
const id = await driver.getWindowHandle()
const browsingContext = await BrowsingContext(driver, {
browsingContextId: id,
})

await driver.get(Pages.formPage)

await driver.wait(until.elementLocated(By.id('imageButton')), 10000).submit()
await driver.wait(until.titleIs('We Arrive Here'), 5000)

await browsingContext.back()
await driver.wait(until.titleIs('We Leave From Here'), 5000)

await browsingContext.forward()
await driver.wait(until.titleIs('We Arrive Here'), 5000)
})
})

describe('Browsing Context Inspector', function () {
Expand Down

0 comments on commit f403139

Please sign in to comment.