Skip to content

Commit edbebe0

Browse files
committed
[bidi][java] Add traverse history command
1 parent bd5cbe5 commit edbebe0

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

java/src/org/openqa/selenium/bidi/browsingcontext/BrowsingContext.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,19 @@ public String print(PrintOptions printOptions) {
325325
}));
326326
}
327327

328+
public void traverseHistory(long delta) {
329+
this.bidi.send(
330+
new Command<>("browsingContext.traverseHistory", Map.of(CONTEXT, id, "delta", delta)));
331+
}
332+
333+
public void back() {
334+
this.traverseHistory(-1);
335+
}
336+
337+
public void forward() {
338+
this.traverseHistory(1);
339+
}
340+
328341
public void close() {
329342
// This might need more clean up actions once the behavior is defined.
330343
// Specially when last tab or window is closed.

java/test/org/openqa/selenium/bidi/browsingcontext/BrowsingContextTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
2121
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
2222
import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;
23+
import static org.openqa.selenium.support.ui.ExpectedConditions.titleIs;
24+
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;
2325
import static org.openqa.selenium.testing.Safely.safelyCall;
2426
import static org.openqa.selenium.testing.drivers.Browser.CHROME;
2527
import static org.openqa.selenium.testing.drivers.Browser.EDGE;
@@ -43,6 +45,7 @@
4345
import org.openqa.selenium.environment.webserver.Page;
4446
import org.openqa.selenium.print.PrintOptions;
4547
import org.openqa.selenium.remote.RemoteWebElement;
48+
import org.openqa.selenium.testing.Ignore;
4649
import org.openqa.selenium.testing.JupiterTestBase;
4750
import org.openqa.selenium.testing.NotYetImplemented;
4851

@@ -498,6 +501,41 @@ void canPrintPage() {
498501
assertThat(printPage).contains("JVBER");
499502
}
500503

504+
@Test
505+
@NotYetImplemented(SAFARI)
506+
@NotYetImplemented(IE)
507+
@NotYetImplemented(CHROME)
508+
@NotYetImplemented(FIREFOX)
509+
public void canNavigateBackInTheBrowserHistory() {
510+
BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle());
511+
browsingContext.navigate(pages.formPage, ReadinessState.COMPLETE);
512+
513+
wait.until(visibilityOfElementLocated(By.id("imageButton"))).submit();
514+
wait.until(titleIs("We Arrive Here"));
515+
516+
browsingContext.back();
517+
wait.until(titleIs("We Leave From Here"));
518+
}
519+
520+
@Test
521+
@NotYetImplemented(SAFARI)
522+
@NotYetImplemented(IE)
523+
@NotYetImplemented(CHROME)
524+
@NotYetImplemented(FIREFOX)
525+
void canNavigateForwardInTheBrowserHistory() {
526+
BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle());
527+
browsingContext.navigate(pages.formPage, ReadinessState.COMPLETE);
528+
529+
wait.until(visibilityOfElementLocated(By.id("imageButton"))).submit();
530+
wait.until(titleIs("We Arrive Here"));
531+
532+
browsingContext.back();
533+
wait.until(titleIs("We Leave From Here"));
534+
535+
browsingContext.forward();
536+
wait.until(titleIs("We Arrive Here"));
537+
}
538+
501539
private String alertPage() {
502540
return appServer.create(
503541
new Page()

0 commit comments

Comments
 (0)