chore(test): Convert tests to use fixtures (#1521)
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.junit.FixtureTest;
|
||||
import com.microsoft.playwright.junit.UsePlaywright;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.opentest4j.AssertionFailedError;
|
||||
|
||||
@@ -25,21 +27,23 @@ import java.io.Writer;
|
||||
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestAPIResponseAssertions extends TestBase {
|
||||
@FixtureTest
|
||||
@UsePlaywright(TestOptionsFactories.BasicOptionsFactory.class)
|
||||
public class TestAPIResponseAssertions {
|
||||
@Test
|
||||
void passWithResponse() {
|
||||
void passWithResponse(Page page, Server server) {
|
||||
APIResponse res = page.request().get(server.EMPTY_PAGE);
|
||||
assertThat(res).isOK();
|
||||
}
|
||||
|
||||
@Test
|
||||
void passWithNot() {
|
||||
void passWithNot(Page page, Server server) {
|
||||
APIResponse res = page.request().get(server.PREFIX + "/unknown");
|
||||
assertThat(res).not().isOK();
|
||||
}
|
||||
|
||||
@Test
|
||||
void fail() {
|
||||
void fail(Page page, Server server) {
|
||||
APIResponse res = page.request().get(server.PREFIX + "/unknown");
|
||||
AssertionFailedError e = assertThrows(AssertionFailedError.class, () -> assertThat(res).isOK());
|
||||
assertTrue(e.getMessage().contains("→ GET " + server.PREFIX + "/unknown"), "Actual error: " + e.toString());
|
||||
@@ -47,14 +51,14 @@ public class TestAPIResponseAssertions extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldPrintResponseTextIfIdOkFails() {
|
||||
void shouldPrintResponseTextIfIdOkFails(Page page, Server server) {
|
||||
APIResponse res = page.request().get(server.PREFIX + "/unknown");
|
||||
AssertionFailedError e = assertThrows(AssertionFailedError.class, () -> assertThat(res).isOK());
|
||||
assertTrue(e.getMessage().contains("File not found"), "Actual error: " + e.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldOnlyPrintResponseWithTextContentTypeIfIsOkFails() {
|
||||
void shouldOnlyPrintResponseWithTextContentTypeIfIsOkFails(Page page, Server server) {
|
||||
{
|
||||
server.setRoute("/text-content-type", exchange -> {
|
||||
exchange.getResponseHeaders().set("Content-type", "text/plain");
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.assertions.LocatorAssertions;
|
||||
import com.microsoft.playwright.junit.FixtureTest;
|
||||
import com.microsoft.playwright.junit.UsePlaywright;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.opentest4j.AssertionFailedError;
|
||||
|
||||
@@ -24,9 +26,11 @@ import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertTha
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
// Copied from expect-misc.spec.ts > toBeInViewport
|
||||
public class TestAssertThatIsInViewport extends TestBase {
|
||||
@FixtureTest
|
||||
@UsePlaywright(TestOptionsFactories.BasicOptionsFactory.class)
|
||||
public class TestAssertThatIsInViewport {
|
||||
@Test
|
||||
void shouldWork() {
|
||||
void shouldWork(Page page) {
|
||||
page.setContent("<div id=big style=\"height: 10000px;\"></div>\n" +
|
||||
" <div id=small>foo</div>");
|
||||
assertThat(page.locator("#big")).isInViewport();
|
||||
@@ -37,7 +41,7 @@ public class TestAssertThatIsInViewport extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRespectRatioOption() {
|
||||
void shouldRespectRatioOption(Page page) {
|
||||
page.setContent("<style>body, div, html { padding: 0; margin: 0; }</style>\n" +
|
||||
" <div id=big style=\"height: 400vh;\"></div>");
|
||||
assertThat(page.locator("div")).isInViewport();
|
||||
@@ -55,14 +59,14 @@ public class TestAssertThatIsInViewport extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldHaveGoodStack() {
|
||||
void shouldHaveGoodStack(Page page) {
|
||||
AssertionFailedError error = assertThrows(AssertionFailedError.class, () -> assertThat(page.locator("body")).not().isInViewport(new LocatorAssertions.IsInViewportOptions().setTimeout(100)));
|
||||
assertNotNull(error);
|
||||
assertTrue(error.getMessage().contains("Locator expected not to be in viewport"), error.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReportIntersectionEvenIfFullyCoveredByOtherElement() {
|
||||
void shouldReportIntersectionEvenIfFullyCoveredByOtherElement(Page page) {
|
||||
page.setContent("<h1>hello</h1>\n" +
|
||||
" <div style=\"position: relative; height: 10000px; top: -5000px;></div>");
|
||||
assertThat(page.locator("h1")).isInViewport();
|
||||
|
||||
@@ -16,11 +16,15 @@
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.junit.FixtureTest;
|
||||
import com.microsoft.playwright.junit.UsePlaywright;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class TestBeforeunload extends TestBase {
|
||||
@FixtureTest
|
||||
@UsePlaywright(TestOptionsFactories.BasicOptionsFactory.class)
|
||||
public class TestBeforeunload {
|
||||
@Test
|
||||
void shouldBeAbleToNavigateAwayFromPageWithBeforeunload() {
|
||||
void shouldBeAbleToNavigateAwayFromPageWithBeforeunload(Page page, Server server) {
|
||||
page.navigate(server.PREFIX + "/beforeunload.html");
|
||||
// We have to interact with a page so that "beforeunload" handlers
|
||||
// fire.
|
||||
|
||||
+30
-23
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.junit.FixtureTest;
|
||||
import com.microsoft.playwright.junit.UsePlaywright;
|
||||
import com.microsoft.playwright.options.Cookie;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -24,14 +26,18 @@ import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import static com.microsoft.playwright.TestOptionsFactories.isChromium;
|
||||
import static com.microsoft.playwright.TestOptionsFactories.isFirefox;
|
||||
import static com.microsoft.playwright.Utils.assertJsonEquals;
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestBrowserContextAddCookies extends TestBase {
|
||||
@FixtureTest
|
||||
@UsePlaywright(TestOptionsFactories.BasicOptionsFactory.class)
|
||||
public class TestBrowserContextAddCookies {
|
||||
@Test
|
||||
void shouldWork() {
|
||||
void shouldWork(Page page, Server server, BrowserContext context) {
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
context.addCookies(asList(
|
||||
new Cookie("password", "123456").setUrl(server.EMPTY_PAGE)));
|
||||
@@ -47,7 +53,7 @@ public class TestBrowserContextAddCookies extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRoundtripCookie() {
|
||||
void shouldRoundtripCookie(Page page, Server server, BrowserContext context) {
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
// @see https://en.wikipedia.org/wiki/Year_2038_problem
|
||||
Object documentCookie = page.evaluate("() => {\n" +
|
||||
@@ -65,7 +71,7 @@ public class TestBrowserContextAddCookies extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSendCookieHeader() throws ExecutionException, InterruptedException {
|
||||
void shouldSendCookieHeader(Server server, BrowserContext context) throws ExecutionException, InterruptedException {
|
||||
Future<Server.Request> request = server.futureRequest("/empty.html");
|
||||
context.addCookies(asList(
|
||||
new Cookie("cookie", "value").setUrl(server.EMPTY_PAGE)));
|
||||
@@ -76,7 +82,7 @@ public class TestBrowserContextAddCookies extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldIsolateCookiesInBrowserContexts() {
|
||||
void shouldIsolateCookiesInBrowserContexts(Browser browser, BrowserContext context, Server server) {
|
||||
BrowserContext anotherContext = browser.newContext();
|
||||
context.addCookies(asList(
|
||||
new Cookie("isolatecookie", "page1value").setUrl(server.EMPTY_PAGE)));
|
||||
@@ -94,7 +100,7 @@ public class TestBrowserContextAddCookies extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldIsolateSessionCookies() {
|
||||
void shouldIsolateSessionCookies(Server server, BrowserContext context, Browser browser) {
|
||||
server.setRoute("/setcookie.html", exchange -> {
|
||||
exchange.getResponseHeaders().add("Set-Cookie", "session=value");
|
||||
exchange.sendResponseHeaders(200, 0);
|
||||
@@ -122,7 +128,7 @@ public class TestBrowserContextAddCookies extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldIsolatePersistentCookies() {
|
||||
void shouldIsolatePersistentCookies(Server server, BrowserContext context, Browser browser) {
|
||||
server.setRoute("/setcookie.html", exchange -> {
|
||||
exchange.getResponseHeaders().add("Set-Cookie", "persistent=persistent-value; max-age=3600");
|
||||
exchange.sendResponseHeaders(200, 0);
|
||||
@@ -147,7 +153,7 @@ public class TestBrowserContextAddCookies extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldIsolateSendCookieHeader() throws ExecutionException, InterruptedException {
|
||||
void shouldIsolateSendCookieHeader(BrowserContext context, Server server, Browser browser) throws ExecutionException, InterruptedException {
|
||||
context.addCookies(asList(
|
||||
new Cookie("sendcookie", "value").setUrl(server.EMPTY_PAGE)));
|
||||
{
|
||||
@@ -158,19 +164,20 @@ public class TestBrowserContextAddCookies extends TestBase {
|
||||
assertEquals(asList("sendcookie=value"), cookies);
|
||||
}
|
||||
{
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
BrowserContext newContext = browser.newContext();
|
||||
Page page = newContext.newPage();
|
||||
Future<Server.Request> request = server.futureRequest("/empty.html");
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
List<String> cookies = request.get().headers.get("cookie");
|
||||
assertNull(cookies);
|
||||
context.close();
|
||||
newContext.close();
|
||||
}
|
||||
}
|
||||
@Test
|
||||
void shouldIsolateCookiesBetweenLaunches() {
|
||||
void shouldIsolateCookiesBetweenLaunches(Playwright playwright, Server server) {
|
||||
// test.slow();
|
||||
// TODO: const browser1 = browserType.launch(browserOptions);
|
||||
BrowserType browserType = Utils.getBrowserTypeFromEnv(playwright);
|
||||
Browser browser1 = browserType.launch();
|
||||
BrowserContext context1 = browser1.newContext();
|
||||
context1.addCookies(asList(new Cookie("cookie-in-context-1", "value")
|
||||
@@ -187,7 +194,7 @@ public class TestBrowserContextAddCookies extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSetMultipleCookies() {
|
||||
void shouldSetMultipleCookies(Page page, BrowserContext context, Server server) {
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
context.addCookies(asList(
|
||||
new Cookie("multiple-1", "123456").setUrl(server.EMPTY_PAGE),
|
||||
@@ -200,7 +207,7 @@ public class TestBrowserContextAddCookies extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldHaveExpiresSetTo1ForSessionCookies() {
|
||||
void shouldHaveExpiresSetTo1ForSessionCookies(BrowserContext context, Server server) {
|
||||
context.addCookies(asList(
|
||||
new Cookie("expires", "123456").setUrl(server.EMPTY_PAGE)));
|
||||
List<Cookie> cookies = context.cookies();
|
||||
@@ -208,7 +215,7 @@ public class TestBrowserContextAddCookies extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSetCookieWithReasonableDefaults() {
|
||||
void shouldSetCookieWithReasonableDefaults(BrowserContext context, Server server) {
|
||||
context.addCookies(asList(
|
||||
new Cookie("defaults", "123456").setUrl(server.EMPTY_PAGE)));
|
||||
List<Cookie> cookies = context.cookies();
|
||||
@@ -225,7 +232,7 @@ public class TestBrowserContextAddCookies extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSetACookieWithAPath() {
|
||||
void shouldSetACookieWithAPath(Page page, Server server, BrowserContext context) {
|
||||
page.navigate(server.PREFIX + "/grid.html");
|
||||
context.addCookies(asList(new Cookie("gridcookie", "GRID")
|
||||
.setDomain("localhost")
|
||||
@@ -249,7 +256,7 @@ public class TestBrowserContextAddCookies extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotSetACookieWithBlankPageURL() {
|
||||
void shouldNotSetACookieWithBlankPageURL(BrowserContext context, Server server) {
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> context.addCookies(asList(
|
||||
new Cookie("example-cookie", "best").setUrl(server.EMPTY_PAGE),
|
||||
new Cookie("example-cookie-blank", "best").setUrl("about:blank")
|
||||
@@ -258,7 +265,7 @@ public class TestBrowserContextAddCookies extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotSetACookieOnADataURLPage() {
|
||||
void shouldNotSetACookieOnADataURLPage(BrowserContext context) {
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> context.addCookies(asList(
|
||||
new Cookie("example-cookie", "best").setUrl("data:,Hello%2C%20World!")
|
||||
)));
|
||||
@@ -266,7 +273,7 @@ public class TestBrowserContextAddCookies extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldDefaultToSettingSecureCookieForHTTPSWebsites() {
|
||||
void shouldDefaultToSettingSecureCookieForHTTPSWebsites(Page page, Server server, BrowserContext context) {
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
String SECURE_URL = "https://example.com";
|
||||
context.addCookies(asList(
|
||||
@@ -278,7 +285,7 @@ public class TestBrowserContextAddCookies extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldBeAbleToSetUnsecureCookieForHTTPWebsite() {
|
||||
void shouldBeAbleToSetUnsecureCookieForHTTPWebsite(Page page, Server server, BrowserContext context) {
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
String HTTP_URL = "http://example.com";
|
||||
context.addCookies(asList(
|
||||
@@ -290,7 +297,7 @@ public class TestBrowserContextAddCookies extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSetACookieOnADifferentDomain() {
|
||||
void shouldSetACookieOnADifferentDomain(Page page, Server server, BrowserContext context) {
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
context.addCookies(asList(
|
||||
new Cookie("example-cookie", "best").setUrl("https://www.example.com")
|
||||
@@ -309,7 +316,7 @@ public class TestBrowserContextAddCookies extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSetCookiesForAFrame() {
|
||||
void shouldSetCookiesForAFrame(Page page, Server server, BrowserContext context) {
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
context.addCookies(asList(
|
||||
new Cookie("frame-cookie", "value").setUrl(server.PREFIX)
|
||||
@@ -327,7 +334,7 @@ public class TestBrowserContextAddCookies extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotBlockThirdPartyCookies() {
|
||||
void shouldNotBlockThirdPartyCookies(Page page, Server server, BrowserContext context) {
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
page.evaluate("src => {\n" +
|
||||
" let fulfill;\n" +
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import com.microsoft.playwright.junit.FixtureTest;
|
||||
import com.microsoft.playwright.junit.UsePlaywright;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
@@ -23,9 +25,11 @@ import java.net.MalformedURLException;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
public class TestBrowserContextBaseUrl extends TestBase {
|
||||
@FixtureTest
|
||||
@UsePlaywright(TestOptionsFactories.BasicOptionsFactory.class)
|
||||
public class TestBrowserContextBaseUrl {
|
||||
@Test
|
||||
void shouldConstructANewURLWhenABaseURLInBrowserNewContextIsPassedToPageGoto() throws MalformedURLException {
|
||||
void shouldConstructANewURLWhenABaseURLInBrowserNewContextIsPassedToPageGoto(Browser browser, Server server) {
|
||||
try (BrowserContext context = browser.newContext(new Browser.NewContextOptions().setBaseURL(server.PREFIX))) {
|
||||
Page page = context.newPage();
|
||||
assertEquals(server.EMPTY_PAGE, page.navigate("/empty.html").url());
|
||||
@@ -33,13 +37,13 @@ public class TestBrowserContextBaseUrl extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldConstructANewURLWhenABaseURLInBrowserNewPageIsPassedToPageGoto() {
|
||||
void shouldConstructANewURLWhenABaseURLInBrowserNewPageIsPassedToPageGoto(Browser browser, Server server) {
|
||||
try (Page page = browser.newPage(new Browser.NewPageOptions().setBaseURL(server.PREFIX))) {
|
||||
assertEquals(server.EMPTY_PAGE, page.navigate("/empty.html").url());
|
||||
}
|
||||
}
|
||||
@Test
|
||||
void shouldConstructTheURLsCorrectlyWhenABaseURLWithoutATrailingSlashInBrowserNewPageIsPassedToPageGoto() {
|
||||
void shouldConstructTheURLsCorrectlyWhenABaseURLWithoutATrailingSlashInBrowserNewPageIsPassedToPageGoto(Browser browser, Server server) {
|
||||
try (Page page = browser.newPage(new Browser.NewPageOptions().setBaseURL(server.PREFIX + "/url-construction"))) {
|
||||
assertEquals(server.PREFIX + "/mypage.html", page.navigate("mypage.html").url());
|
||||
assertEquals(server.PREFIX + "/mypage.html", page.navigate("./mypage.html").url());
|
||||
@@ -48,7 +52,7 @@ public class TestBrowserContextBaseUrl extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldConstructTheURLsCorrectlyWhenABaseURLWithATrailingSlashInBrowserNewPageIsPassedToPageGoto() {
|
||||
void shouldConstructTheURLsCorrectlyWhenABaseURLWithATrailingSlashInBrowserNewPageIsPassedToPageGoto(Browser browser, Server server) {
|
||||
try (Page page = browser.newPage(new Browser.NewPageOptions().setBaseURL(server.PREFIX + "/url-construction/"))) {
|
||||
assertEquals(server.PREFIX + "/url-construction/mypage.html", page.navigate("mypage.html").url());
|
||||
assertEquals(server.PREFIX + "/url-construction/mypage.html", page.navigate("./mypage.html").url());
|
||||
@@ -59,7 +63,7 @@ public class TestBrowserContextBaseUrl extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotConstructANewURLWhenValidURLsArePassed() {
|
||||
void shouldNotConstructANewURLWhenValidURLsArePassed(Browser browser, Server server) {
|
||||
try (Page page = browser.newPage(new Browser.NewPageOptions().setBaseURL("http://microsoft.com"))) {
|
||||
assertEquals(server.EMPTY_PAGE, page.navigate(server.EMPTY_PAGE).url());
|
||||
|
||||
@@ -72,7 +76,7 @@ public class TestBrowserContextBaseUrl extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldBeAbleToMatchAURLRelativeToItsGivenURLWithUrlMatcher() {
|
||||
void shouldBeAbleToMatchAURLRelativeToItsGivenURLWithUrlMatcher(Browser browser, Server server) {
|
||||
try (Page page = browser.newPage(new Browser.NewPageOptions().setBaseURL(server.PREFIX + "/foobar/"))) {
|
||||
page.navigate("/kek/index.html");
|
||||
page.waitForURL("/kek/index.html");
|
||||
|
||||
@@ -16,32 +16,37 @@
|
||||
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import com.microsoft.playwright.junit.FixtureTest;
|
||||
import com.microsoft.playwright.junit.UsePlaywright;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.microsoft.playwright.TestOptionsFactories.isFirefox;
|
||||
import static com.microsoft.playwright.TestOptionsFactories.isWebKit;
|
||||
import static com.microsoft.playwright.Utils.verifyViewport;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestBrowserContextBasic extends TestBase {
|
||||
@FixtureTest
|
||||
@UsePlaywright(TestOptionsFactories.BasicOptionsFactory.class)
|
||||
public class TestBrowserContextBasic {
|
||||
@Test
|
||||
void shouldCreateNewContext() {
|
||||
assertEquals(1, browser.contexts().size());
|
||||
void shouldCreateNewContext(Browser browser) {
|
||||
assertEquals(0, browser.contexts().size());
|
||||
BrowserContext context = browser.newContext();
|
||||
assertEquals(2, browser.contexts().size());
|
||||
assertEquals(1, browser.contexts().size());
|
||||
assertTrue(browser.contexts().indexOf(context) != -1);
|
||||
assertEquals(context.browser(), browser);
|
||||
context.close();
|
||||
assertEquals(1, browser.contexts().size());
|
||||
assertEquals(0, browser.contexts().size());
|
||||
assertEquals(context.browser(), browser);
|
||||
}
|
||||
|
||||
@Test
|
||||
void windowOpenShouldUseParentTabContext() {
|
||||
void windowOpenShouldUseParentTabContext(Browser browser, Server server) {
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
@@ -51,7 +56,7 @@ public class TestBrowserContextBasic extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldIsolateLocalStorageAndCookies() {
|
||||
void shouldIsolateLocalStorageAndCookies(Browser browser, Server server) {
|
||||
// Create two incognito contexts.
|
||||
BrowserContext context1 = browser.newContext();
|
||||
BrowserContext context2 = browser.newContext();
|
||||
@@ -92,11 +97,11 @@ public class TestBrowserContextBasic extends TestBase {
|
||||
context1.close();
|
||||
context2.close();
|
||||
|
||||
assertEquals(1, browser.contexts().size());
|
||||
assertEquals(0, browser.contexts().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldPropagateDefaultViewportToThePage() {
|
||||
void shouldPropagateDefaultViewportToThePage(Browser browser) {
|
||||
BrowserContext context = browser.newContext(new Browser.NewContextOptions().setViewportSize(456, 789));
|
||||
Page page = context.newPage();
|
||||
verifyViewport(page, 456, 789);
|
||||
@@ -108,7 +113,7 @@ public class TestBrowserContextBasic extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRespectDeviceScaleFactor() {
|
||||
void shouldRespectDeviceScaleFactor(Browser browser) {
|
||||
BrowserContext context = browser.newContext(new Browser.NewContextOptions().setDeviceScaleFactor(3.0));
|
||||
Page page = context.newPage();
|
||||
assertEquals(3, page.evaluate("window.devicePixelRatio"));
|
||||
@@ -117,7 +122,7 @@ public class TestBrowserContextBasic extends TestBase {
|
||||
|
||||
|
||||
@Test
|
||||
void shouldNotAllowDeviceScaleFactorWithNullViewport() {
|
||||
void shouldNotAllowDeviceScaleFactorWithNullViewport(Browser browser) {
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> {
|
||||
browser.newContext(new Browser.NewContextOptions().setDeviceScaleFactor(1.0).setViewportSize(null));
|
||||
});
|
||||
@@ -125,7 +130,7 @@ public class TestBrowserContextBasic extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotAllowIsMobileWithNullViewport() {
|
||||
void shouldNotAllowIsMobileWithNullViewport(Browser browser) {
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> {
|
||||
browser.newContext(new Browser.NewContextOptions().setIsMobile(true).setViewportSize(null));
|
||||
});
|
||||
@@ -133,13 +138,13 @@ public class TestBrowserContextBasic extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void closeShouldWorkForEmptyContext() {
|
||||
void closeShouldWorkForEmptyContext(Browser browser) {
|
||||
BrowserContext context = browser.newContext();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void closeShouldAbortFutureEvent() {
|
||||
void closeShouldAbortFutureEvent(Browser browser) {
|
||||
BrowserContext context = browser.newContext();
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> {
|
||||
context.waitForPage(() -> context.close());
|
||||
@@ -148,7 +153,7 @@ public class TestBrowserContextBasic extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void closeShouldBeCallableTwice() {
|
||||
void closeShouldBeCallableTwice(Browser browser) {
|
||||
BrowserContext context = browser.newContext();
|
||||
context.close();
|
||||
context.close();
|
||||
@@ -156,7 +161,7 @@ public class TestBrowserContextBasic extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotReportFramelessPagesOnError() {
|
||||
void shouldNotReportFramelessPagesOnError(Browser browser, Server server) {
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
server.setRoute("/empty.html", exchange -> {
|
||||
@@ -181,7 +186,7 @@ public class TestBrowserContextBasic extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnAllOfThePages() {
|
||||
void shouldReturnAllOfThePages(Browser browser) {
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
Page second = context.newPage();
|
||||
@@ -193,7 +198,7 @@ public class TestBrowserContextBasic extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCloseAllBelongingPagesOnceClosingContext() {
|
||||
void shouldCloseAllBelongingPagesOnceClosingContext(Browser browser) {
|
||||
BrowserContext context = browser.newContext();
|
||||
context.newPage();
|
||||
assertEquals(1, context.pages().size());
|
||||
@@ -202,7 +207,7 @@ public class TestBrowserContextBasic extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldDisableJavascript() {
|
||||
void shouldDisableJavascript(Browser browser) {
|
||||
{
|
||||
BrowserContext context = browser.newContext(new Browser.NewContextOptions().setJavaScriptEnabled(false));
|
||||
Page page = context.newPage();
|
||||
@@ -225,7 +230,7 @@ public class TestBrowserContextBasic extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldBeAbleToNavigateAfterDisablingJavascript() {
|
||||
void shouldBeAbleToNavigateAfterDisablingJavascript(Browser browser, Server server) {
|
||||
BrowserContext context = browser.newContext(new Browser.NewContextOptions().setJavaScriptEnabled(false));
|
||||
Page page = context.newPage();
|
||||
page.navigate(server.EMPTY_PAGE);
|
||||
@@ -233,7 +238,7 @@ public class TestBrowserContextBasic extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldWorkWithOfflineOption() {
|
||||
void shouldWorkWithOfflineOption(Browser browser, Server server) {
|
||||
BrowserContext context = browser.newContext(new Browser.NewContextOptions().setOffline(true));
|
||||
Page page = context.newPage();
|
||||
if (isFirefox()) {
|
||||
@@ -254,7 +259,7 @@ public class TestBrowserContextBasic extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldEmulateNavigatorOnLine() {
|
||||
void shouldEmulateNavigatorOnLine(Browser browser) {
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
assertEquals(true, page.evaluate("() => window.navigator.onLine"));
|
||||
@@ -266,7 +271,7 @@ public class TestBrowserContextBasic extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldWaitForCondition() {
|
||||
void shouldWaitForCondition(Page page, BrowserContext context) {
|
||||
List<String> messages = new ArrayList<>();
|
||||
page.onConsoleMessage(m -> messages.add(m.text()));
|
||||
page.evaluate("setTimeout(() => {\n" +
|
||||
@@ -278,13 +283,14 @@ public class TestBrowserContextBasic extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void waitForConditionTimeout() {
|
||||
void waitForConditionTimeout(BrowserContext context) {
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class,
|
||||
() -> context.waitForCondition(() -> false, new BrowserContext.WaitForConditionOptions().setTimeout(100)));
|
||||
assertTrue(e.getMessage().contains("Timeout"), e.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void waitForConditionPageClosed() {
|
||||
void waitForConditionPageClosed(BrowserContext context) {
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class,
|
||||
() -> context.waitForCondition(() -> {
|
||||
context.close();
|
||||
@@ -294,7 +300,7 @@ public class TestBrowserContextBasic extends TestBase {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldPropagateCloseReasonToPendingActions() {
|
||||
void shouldPropagateCloseReasonToPendingActions(Browser browser) {
|
||||
BrowserContext context = browser.newContext();
|
||||
Page page = context.newPage();
|
||||
PlaywrightException e = assertThrows(PlaywrightException.class, () -> page.waitForPopup(() -> {
|
||||
|
||||
@@ -55,4 +55,12 @@ public class TestOptionsFactories {
|
||||
public static boolean isChromium() {
|
||||
return getBrowserName().equals("chromium");
|
||||
}
|
||||
|
||||
public static boolean isFirefox() {
|
||||
return getBrowserName().equals("firefox");
|
||||
}
|
||||
|
||||
public static boolean isWebKit() {
|
||||
return getBrowserName().equals("webkit");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user