Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
import static com.microsoft.playwright.impl.Utils.*;

class BrowserImpl extends ChannelOwner implements Browser {
final Set<BrowserContextImpl> contexts = new HashSet<>();
// Insertion order, so that browser.contexts() lists the contexts in creation order like the other clients.
final Set<BrowserContextImpl> contexts = new LinkedHashSet<>();
private final ListenerCollection<EventType> listeners = new ListenerCollection<>();
boolean isConnectedOverWebSocket;
private boolean isConnected = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.microsoft.playwright.fixtures.PlaywrightTest;
import org.junit.jupiter.api.Tag;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern;

Expand All @@ -46,6 +48,21 @@ void shouldCreateNewPage(Browser browser) {
assertEquals(0, browser.contexts().size());
}

@PlaywrightTest
void shouldListContextsInCreationOrder(Browser browser) {
List<BrowserContext> contexts = new ArrayList<>();
for (int i = 0; i < 5; i++) {
contexts.add(browser.newContext());
}
assertEquals(contexts, browser.contexts());
contexts.remove(2).close();
assertEquals(contexts, browser.contexts());
for (BrowserContext context : contexts) {
context.close();
}
assertEquals(0, browser.contexts().size());
}

@PlaywrightTest
void shouldThrowUponSecondCreateNewPage(Browser browser) {
Page page = browser.newPage();
Expand Down
Loading