mirror of
https://github.com/microsoft/playwright-java.git
synced 2025-09-08 21:01:00 +00:00
fix: correctly initialize page.isClosed() (#163)
This commit is contained in:
parent
190bcbdd78
commit
077e8f6daa
@ -55,6 +55,7 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
browserContext = (BrowserContextImpl) parent;
|
||||
mainFrame = connection.getExistingObject(initializer.getAsJsonObject("mainFrame").get("guid").getAsString());
|
||||
mainFrame.page = this;
|
||||
isClosed = initializer.get("isClosed").getAsBoolean();
|
||||
keyboard = new KeyboardImpl(this);
|
||||
mouse = new MouseImpl(this);
|
||||
touchscreen = new TouchscreenImpl(this);
|
||||
@ -212,6 +213,9 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
|
||||
@Override
|
||||
public void close(CloseOptions options) {
|
||||
if (isClosed) {
|
||||
return;
|
||||
}
|
||||
JsonObject params = options == null ? new JsonObject() : gson().toJsonTree(options).getAsJsonObject();
|
||||
try {
|
||||
sendMessage("close", params);
|
||||
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.OutputStreamWriter;
|
||||
|
||||
import static com.microsoft.playwright.BrowserContext.EventType.PAGE;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestBrowserContextBasic extends TestBase {
|
||||
@Test
|
||||
void shouldNotReportFramelessPagesOnError() {
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
server.setRoute("/empty.html", exchange -> {
|
||||
exchange.sendResponseHeaders(200, 0);
|
||||
try (OutputStreamWriter writer = new OutputStreamWriter(exchange.getResponseBody())) {
|
||||
writer.write("<a href='" + server.EMPTY_PAGE + "' target='_blank'>Click me</a>");
|
||||
}
|
||||
});
|
||||
Page[] popup = {null};
|
||||
context.addListener(PAGE, event -> popup[0] = (Page) event.data());
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
page.click("'Click me'");
|
||||
context.close();
|
||||
if (popup[0] != null) {
|
||||
// This races on Firefox :/
|
||||
assertTrue(popup[0].isClosed());
|
||||
assertNotNull(popup[0].mainFrame());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user