Skip to content

Commit

Permalink
[java] Adding ability to clear listeners in DevTools and breaking dep…
Browse files Browse the repository at this point in the history
…endency between DevTools tests
  • Loading branch information
barancev committed Oct 19, 2019
1 parent 2d5cde1 commit 36ff0bf
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions java/client/src/org/openqa/selenium/devtools/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public <X> void addListener(Event<X> event, Consumer<X> handler) {
eventCallbacks.put(event, handler);
}

public void clearListeners() {
eventCallbacks.clear();
}

@Override
public void close() {
socket.close();
Expand Down
4 changes: 4 additions & 0 deletions java/client/src/org/openqa/selenium/devtools/DevTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public <X> void addListener(Event<X> event, Consumer<X> handler) {
connection.addListener(event, handler);
}

public void clearListeners() {
connection.clearListeners();
}

public void createSessionIfThereIsNotOne() {
if (cdpSession == null) {
createSession();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ public void verifyCacheDisabledAndClearCache() {

devTools.send(enable(Optional.empty(), Optional.empty(), Optional.of(100000000)));

devTools.addListener(responseReceived(), responseReceived -> assertEquals(false, responseReceived.getResponse().getFromDiskCache()));

driver.get(appServer.whereIs("simpleTest.html"));

devTools.send(setCacheDisabled(true));

devTools.addListener(responseReceived(), responseReceived -> assertEquals(false, responseReceived.getResponse().getFromDiskCache()));

driver.get(appServer.whereIs("simpleTest.html"));

devTools.send(clearBrowserCache());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ public void setUp() {

devTools = ((HasDevTools) driver).getDevTools();
devTools.createSessionIfThereIsNotOne();
devTools.clearListeners();
}
}

0 comments on commit 36ff0bf

Please sign in to comment.