Skip to content

Commit

Permalink
[bidi][java] Add traverse history command
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani committed Nov 29, 2023
1 parent bd5cbe5 commit edbebe0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Expand Up @@ -325,6 +325,19 @@ public String print(PrintOptions printOptions) {
}));
}

public void traverseHistory(long delta) {
this.bidi.send(
new Command<>("browsingContext.traverseHistory", Map.of(CONTEXT, id, "delta", delta)));
}

public void back() {
this.traverseHistory(-1);
}

public void forward() {
this.traverseHistory(1);
}

public void close() {
// This might need more clean up actions once the behavior is defined.
// Specially when last tab or window is closed.
Expand Down
Expand Up @@ -20,6 +20,8 @@
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;
import static org.openqa.selenium.support.ui.ExpectedConditions.titleIs;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;
import static org.openqa.selenium.testing.Safely.safelyCall;
import static org.openqa.selenium.testing.drivers.Browser.CHROME;
import static org.openqa.selenium.testing.drivers.Browser.EDGE;
Expand All @@ -43,6 +45,7 @@
import org.openqa.selenium.environment.webserver.Page;
import org.openqa.selenium.print.PrintOptions;
import org.openqa.selenium.remote.RemoteWebElement;
import org.openqa.selenium.testing.Ignore;
import org.openqa.selenium.testing.JupiterTestBase;
import org.openqa.selenium.testing.NotYetImplemented;

Expand Down Expand Up @@ -498,6 +501,41 @@ void canPrintPage() {
assertThat(printPage).contains("JVBER");
}

@Test
@NotYetImplemented(SAFARI)
@NotYetImplemented(IE)
@NotYetImplemented(CHROME)
@NotYetImplemented(FIREFOX)
public void canNavigateBackInTheBrowserHistory() {
BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle());
browsingContext.navigate(pages.formPage, ReadinessState.COMPLETE);

wait.until(visibilityOfElementLocated(By.id("imageButton"))).submit();
wait.until(titleIs("We Arrive Here"));

browsingContext.back();
wait.until(titleIs("We Leave From Here"));
}

@Test
@NotYetImplemented(SAFARI)
@NotYetImplemented(IE)
@NotYetImplemented(CHROME)
@NotYetImplemented(FIREFOX)
void canNavigateForwardInTheBrowserHistory() {
BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle());
browsingContext.navigate(pages.formPage, ReadinessState.COMPLETE);

wait.until(visibilityOfElementLocated(By.id("imageButton"))).submit();
wait.until(titleIs("We Arrive Here"));

browsingContext.back();
wait.until(titleIs("We Leave From Here"));

browsingContext.forward();
wait.until(titleIs("We Arrive Here"));
}

private String alertPage() {
return appServer.create(
new Page()
Expand Down

0 comments on commit edbebe0

Please sign in to comment.