chore: unflake tests (#93)

This commit is contained in:
Yury Semikhatsky 2020-12-07 17:58:35 -08:00 committed by GitHub
parent 5e3fc5b78e
commit 142a626567
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 13 deletions

View File

@ -47,9 +47,11 @@ public class TestHar extends TestBase {
page = context.newPage();
}
JsonObject log() throws FileNotFoundException {
JsonObject log() throws IOException {
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 {
@ -79,7 +81,7 @@ public class TestHar extends TestBase {
}
@Test
void shouldHaveVersionAndCreator() throws FileNotFoundException {
void shouldHaveVersionAndCreator() throws IOException {
pageWithHar.page.navigate(server.EMPTY_PAGE);
JsonObject log = pageWithHar.log();
assertEquals("1.2", log.get("version").getAsString());
@ -87,7 +89,7 @@ public class TestHar extends TestBase {
}
@Test
void shouldHaveBrowser() throws FileNotFoundException {
void shouldHaveBrowser() throws IOException {
pageWithHar.page.navigate(server.EMPTY_PAGE);
JsonObject log = pageWithHar.log();
assertEquals(browserType.name(), log.getAsJsonObject("browser").get("name").getAsString().toLowerCase());
@ -95,7 +97,7 @@ public class TestHar extends TestBase {
}
@Test
void shouldHavePages() throws FileNotFoundException {
void shouldHavePages() throws IOException {
pageWithHar.page.navigate("data:text/html,<title>Hello</title>");
// For data: load comes before 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();
assertEquals("page_0", pageEntry.get("id").getAsString());
assertEquals("Hello", pageEntry.get("title").getAsString());
Files.deleteIfExists(harPath);
}
@Test
void shouldIncludeRequest() throws FileNotFoundException {
void shouldIncludeRequest() throws IOException {
pageWithHar.page.navigate(server.EMPTY_PAGE);
JsonObject log = pageWithHar.log();
assertEquals(1, log.getAsJsonArray("entries").size());
@ -157,7 +157,7 @@ public class TestHar extends TestBase {
}
@Test
void shouldIncludeResponse() throws FileNotFoundException {
void shouldIncludeResponse() throws IOException {
pageWithHar.page.navigate(server.EMPTY_PAGE);
JsonObject log = pageWithHar.log();
JsonObject entry = log.getAsJsonArray("entries").get(0).getAsJsonObject();

View File

@ -69,14 +69,17 @@ public class TestPageWaitForNavigation extends TestBase {
@Test
void shouldWorkWithClickingOnLinksWhichDoNotCommitNavigation() throws InterruptedException {
page.navigate(server.EMPTY_PAGE);
Deferred<Response> event = page.waitForNavigation();
page.setContent("<a href='" + httpsServer.EMPTY_PAGE + "'>foobar</a>");
try {
Deferred<Response> event = page.waitForNavigation();
page.click("a");
event.get();
fail("did not throw");
} 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() + "'");
}
}
}

View File

@ -140,8 +140,8 @@ public class TestWebSocket extends TestBase {
" ws.addEventListener('message', () => { ws.close(); });\n" +
" }", webSocketServer.getPort());
waitForCondition(socketClosed);
assertEquals("open", log.get(0));
assertEquals("close", log.get(3));
assertEquals("open", log.get(0), "Events: " + log);
assertEquals("close", log.get(3), "Events: " + log);
log.sort(String::compareTo);
assertEquals(asList("close", "open", "received<incoming>", "sent<outgoing>"), log);
}