microsoft / microsoft/playwright-java
[Feature]: JUnit: Allow the user to control the Browser object's lifecycle
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
Add an option that will reset the Browser object after each test so cloud services that use BrowserType.connect can work properly. Example: https://www.browserstack.com/docs/automate/playwright/playwright-capabilities#Java
Example
public class Options {
// existing options
public Boolean closeBrowserAfterEachTest;
public Options setCloseBrowserAfterEachTest(Boolean closeBrowser) {
this.closeBrowserAfterEachTest = closeBrowser;
return this;
}
}
Inside of the existing TestWatcher methods, we can check if the user wants to close the browser after each test and do so. Once the next test starts, the Browser will be re-created by the fixture using the existing options. This will allow a new test session to start in BrowserStack.
@Override
public void testSuccessful(ExtensionContext extensionContext) {
saveTraceWhenOn(extensionContext);
closeBrowserContext();
Options options = OptionsExtension.getOptions(extensionContext);
if(options.closeBrowserAfterEachTest) {
BrowserExtension.closeBrowser();
}
}
Motivation
Cloud testing services like BrowserStack launch new sessions using BrowserType.connect. Each call to connect starts a new test session.
This doesn't work properly with current JUnit fixtures because the Browser object is re-used per thread and so all tests that run on the same thread use the same test session in BrowserStack. This becomes one giant test according to BrowserStack.
My suggestion would allow the user to decide when to re-use the browser, which works great locally, but not so well when using cloud testing services.
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 tracciando le Options dell’estensione JUnit, i metodi TestWatcher esistenti, BrowserExtension.closeBrowser() e il fixture che ricrea il Browser. Conferma come viene letta l’opzione e come funziona attualmente il riutilizzo del browser. Il lavoro è completato quando un’impostazione opt-in chiude il Browser dopo ogni test e il test successivo crea una nuova sessione con le opzioni esistenti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java
- Ambito
- testing
- Tipo di issue
- Funzionalità
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100