mirror of
https://github.com/microsoft/playwright-java.git
synced 2025-09-08 21:01:00 +00:00
chore: unflake tests (#93)
This commit is contained in:
parent
5e3fc5b78e
commit
142a626567
@ -47,9 +47,11 @@ public class TestHar extends TestBase {
|
|||||||
page = context.newPage();
|
page = context.newPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonObject log() throws FileNotFoundException {
|
JsonObject log() throws IOException {
|
||||||
context.close();
|
context.close();
|
||||||
return new Gson().fromJson(new FileReader(harFile.toFile()), JsonObject.class).getAsJsonObject("log");
|
try (FileReader json = new FileReader(harFile.toFile())) {
|
||||||
|
return new Gson().fromJson(json, JsonObject.class).getAsJsonObject("log");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dispose() throws IOException {
|
void dispose() throws IOException {
|
||||||
@ -79,7 +81,7 @@ public class TestHar extends TestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldHaveVersionAndCreator() throws FileNotFoundException {
|
void shouldHaveVersionAndCreator() throws IOException {
|
||||||
pageWithHar.page.navigate(server.EMPTY_PAGE);
|
pageWithHar.page.navigate(server.EMPTY_PAGE);
|
||||||
JsonObject log = pageWithHar.log();
|
JsonObject log = pageWithHar.log();
|
||||||
assertEquals("1.2", log.get("version").getAsString());
|
assertEquals("1.2", log.get("version").getAsString());
|
||||||
@ -87,7 +89,7 @@ public class TestHar extends TestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldHaveBrowser() throws FileNotFoundException {
|
void shouldHaveBrowser() throws IOException {
|
||||||
pageWithHar.page.navigate(server.EMPTY_PAGE);
|
pageWithHar.page.navigate(server.EMPTY_PAGE);
|
||||||
JsonObject log = pageWithHar.log();
|
JsonObject log = pageWithHar.log();
|
||||||
assertEquals(browserType.name(), log.getAsJsonObject("browser").get("name").getAsString().toLowerCase());
|
assertEquals(browserType.name(), log.getAsJsonObject("browser").get("name").getAsString().toLowerCase());
|
||||||
@ -95,7 +97,7 @@ public class TestHar extends TestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldHavePages() throws FileNotFoundException {
|
void shouldHavePages() throws IOException {
|
||||||
pageWithHar.page.navigate("data:text/html,<title>Hello</title>");
|
pageWithHar.page.navigate("data:text/html,<title>Hello</title>");
|
||||||
// For data: load comes before domcontentloaded...
|
// For data: load comes before domcontentloaded...
|
||||||
Deferred<Void> loadEvent = pageWithHar.page.waitForLoadState(Page.LoadState.DOMCONTENTLOADED);
|
Deferred<Void> loadEvent = pageWithHar.page.waitForLoadState(Page.LoadState.DOMCONTENTLOADED);
|
||||||
@ -131,12 +133,10 @@ public class TestHar extends TestBase {
|
|||||||
JsonObject pageEntry = log.getAsJsonArray("pages").get(0).getAsJsonObject();
|
JsonObject pageEntry = log.getAsJsonArray("pages").get(0).getAsJsonObject();
|
||||||
assertEquals("page_0", pageEntry.get("id").getAsString());
|
assertEquals("page_0", pageEntry.get("id").getAsString());
|
||||||
assertEquals("Hello", pageEntry.get("title").getAsString());
|
assertEquals("Hello", pageEntry.get("title").getAsString());
|
||||||
|
|
||||||
Files.deleteIfExists(harPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldIncludeRequest() throws FileNotFoundException {
|
void shouldIncludeRequest() throws IOException {
|
||||||
pageWithHar.page.navigate(server.EMPTY_PAGE);
|
pageWithHar.page.navigate(server.EMPTY_PAGE);
|
||||||
JsonObject log = pageWithHar.log();
|
JsonObject log = pageWithHar.log();
|
||||||
assertEquals(1, log.getAsJsonArray("entries").size());
|
assertEquals(1, log.getAsJsonArray("entries").size());
|
||||||
@ -157,7 +157,7 @@ public class TestHar extends TestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldIncludeResponse() throws FileNotFoundException {
|
void shouldIncludeResponse() throws IOException {
|
||||||
pageWithHar.page.navigate(server.EMPTY_PAGE);
|
pageWithHar.page.navigate(server.EMPTY_PAGE);
|
||||||
JsonObject log = pageWithHar.log();
|
JsonObject log = pageWithHar.log();
|
||||||
JsonObject entry = log.getAsJsonArray("entries").get(0).getAsJsonObject();
|
JsonObject entry = log.getAsJsonArray("entries").get(0).getAsJsonObject();
|
||||||
|
@ -69,14 +69,17 @@ public class TestPageWaitForNavigation extends TestBase {
|
|||||||
@Test
|
@Test
|
||||||
void shouldWorkWithClickingOnLinksWhichDoNotCommitNavigation() throws InterruptedException {
|
void shouldWorkWithClickingOnLinksWhichDoNotCommitNavigation() throws InterruptedException {
|
||||||
page.navigate(server.EMPTY_PAGE);
|
page.navigate(server.EMPTY_PAGE);
|
||||||
|
Deferred<Response> event = page.waitForNavigation();
|
||||||
page.setContent("<a href='" + httpsServer.EMPTY_PAGE + "'>foobar</a>");
|
page.setContent("<a href='" + httpsServer.EMPTY_PAGE + "'>foobar</a>");
|
||||||
try {
|
try {
|
||||||
Deferred<Response> event = page.waitForNavigation();
|
|
||||||
page.click("a");
|
page.click("a");
|
||||||
event.get();
|
event.get();
|
||||||
fail("did not throw");
|
fail("did not throw");
|
||||||
} catch (PlaywrightException e) {
|
} catch (PlaywrightException e) {
|
||||||
assertTrue(e.getMessage().contains(expectedSSLError(browserType.name())), e.getMessage());
|
if (!e.getMessage().contains(expectedSSLError(browserType.name()))) {
|
||||||
|
e.printStackTrace(System.err);
|
||||||
|
fail("Unexpected exception: '" + e.getMessage() + "'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,8 +140,8 @@ public class TestWebSocket extends TestBase {
|
|||||||
" ws.addEventListener('message', () => { ws.close(); });\n" +
|
" ws.addEventListener('message', () => { ws.close(); });\n" +
|
||||||
" }", webSocketServer.getPort());
|
" }", webSocketServer.getPort());
|
||||||
waitForCondition(socketClosed);
|
waitForCondition(socketClosed);
|
||||||
assertEquals("open", log.get(0));
|
assertEquals("open", log.get(0), "Events: " + log);
|
||||||
assertEquals("close", log.get(3));
|
assertEquals("close", log.get(3), "Events: " + log);
|
||||||
log.sort(String::compareTo);
|
log.sort(String::compareTo);
|
||||||
assertEquals(asList("close", "open", "received<incoming>", "sent<outgoing>"), log);
|
assertEquals(asList("close", "open", "received<incoming>", "sent<outgoing>"), log);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user