microsoft / microsoft/playwright-java
[Feature]: JUnit5: Page and BrowserContext fixture support in BeforeAll/AfterAll methods
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Java
- Sterne
- 1.6k
- Forks
- 298
- Ø Merge
- 3 T. 2 Std.
- Gemergte PRs (30 T.)
- 14
Beschreibung
🚀 Feature Request
Current Page and BrowserContext JUnit fixture implementation prevents using these fixtures in BeforeAll/AfterAll methods while APIRequestContext does not have this restriction. This makes using Page for class-wide setup/teardown actions unnecessarily cumbersome.
Please consider supporting either an isolated Page and BrowserContext for static BeforeAll/AfterAll or even shared ones when used with @TestInstance(TestInstance.Lifecycle.PER_CLASS), if possible.
Example
package tests;
import com.microsoft.playwright.*;
import com.microsoft.playwright.junit.Options;
import com.microsoft.playwright.junit.OptionsFactory;
import com.microsoft.playwright.junit.UsePlaywright;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.regex.Pattern;
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
// re-purposing example from the documentation
@UsePlaywright(PlaywrightTest.CustomOptions.class)
public class PlaywrightTest {
public static class CustomOptions implements OptionsFactory {
@Override
public Options getOptions() {
return new Options()
.setHeadless(true)
.setContextOptions(new Browser.NewContextOptions()
.setBaseURL("https://github.com"))
.setApiRequestOptions(new APIRequest.NewContextOptions()
.setBaseURL("https://playwright.dev"));
}
}
@BeforeAll
public static void setup(APIRequestContext request) {
// this works
APIResponse response = request.get("/");
assertThat(response).isOK();
}
@Test
public void testWithCustomOptions() {
assert true;
}
// @AfterAll
// public static void teardown(Page page) {
// // ParameterResolutionException
// }
@AfterAll
public static void teardown(Browser browser) {
// this kinda works, but base url from CustomOptions is not applied
Page page = browser.newPage();
// navigating to "/", waiting until "load"
page.navigate("/");
assertThat(page).hasURL(Pattern.compile("github"));
}
}
Motivation
There are cases when using browser would be convenient in test setup/teardown context. Right now this cannot be done by using Page or BrowserContext fixtures directly, but using creating new Page from Browser fixture requires fiddling with options.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie mit der JUnit5-Fixture-Implementierung und reproduzieren Sie das Problem mithilfe der statischen BeforeAll- und AfterAll-Methoden des Beispiels. Vergleichen Sie Page und BrowserContext mit den funktionierenden Fällen APIRequestContext und Browser. Als erledigt gilt die Aufgabe, wenn die angeforderten Fixtures mit der unterstützten Lifecycle-Konfiguration funktionieren und dabei die konfigurierten Optionen erhalten bleiben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java
- Bereich
- testing-qa
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100