microsoft / microsoft/playwright-java
[Feature]: JUnit5: Page and BrowserContext fixture support in BeforeAll/AfterAll methods
Nessuno ha ancora preso questa issue.
- Lingua principale
- Java
- Stelle
- 1.6k
- Fork
- 298
- Merge medio
- 3g 2h
- PR unite (30g)
- 14
Descrizione
🚀 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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con l’implementazione della fixture JUnit5 e riproduci il problema usando i metodi statici BeforeAll e AfterAll dell’esempio. Confronta Page e BrowserContext con i casi funzionanti APIRequestContext e Browser. Il lavoro è completato quando le fixture richieste funzionano con la configurazione del ciclo di vita supportata, preservando le opzioni configurate.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java
- Ambito
- testing-qa
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100