Jeamlit's native app testing framework
Jeamlit provides Playwright end-to-end test utilities to make it simple for developers to build and run automated tests.
Import the test dependencies:
maven (pom.xml
):
<dependency>
<groupId>io.jeamlit</groupId>
<artifactId>jeamlit</artifactId>
<version>0.19.0</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
Warning
The testing utilities depend on JUnit. Please reach out on Github to get help with other testing frameworks.
Test your app
import io.jeamlit.e2e.helpers.PlaywrightUtils;
import static io.jeamlit.e2e.helpers.PlaywrightUtils.WAIT_1_SEC_MAX;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
@Test
public void testMyApp(TestInfo testInfo) {
PlaywrightUtils.runInSharedBrowser(testInfo, app, page -> {
// interact with the app and perform assertions
// example: ensure a dateInput component appears properly
assertThat(page.locator("jt-date-input").first()).isVisible(WAIT_1_SEC_MAX);
});
}
Explanations :
TestInfo
is injected by JUnit.app
is the Jeamlit app as aString
, aPath
or aClass
. See full documentation below.page
is acom.microsoft.playwright.Page
. For more information, visit the Playwright For Java documentationPlaywrightUtils.runInSharedBrowser
takes care of starting a Jeamlit server, launching a headless browser on an available port and navigating to the app page.WAIT_1_SEC_MAX
means the timeout for the check is 1 second. The default timeout in Playwright is often 30 seconds. A lot of option constants with lower timeout values are provided, just typeWAIT_
in your IDE when filling options of a Playwright method, it should suggest all relevant constants fromio.jeamlit.e2e.helpers.PlaywrightUtils
.
The Jeamlit server runs with the test classpath.
Test traces are written in the target/playwright-traces/
folder.
Available methods
// run in a shared browser (recommended, faster)
// The tests run on different pages in the browser, but the browser is shared so cookies, storage, etc... are shared
// Thread safe. Each call launches a Jeamlit server.
PlaywrightUtils.runInSharedBrowser(String testName, Path appFile, Consumer<Page> run);
PlaywrightUtils.runInSharedBrowser(String testName, String app, Consumer<Page> run);
// run in a dedicated browser
// use when you need to test behaviors that depend on the browser cookies, storage, cache
PlaywrightUtils.runInDedicatedBrowser(String testName, Path appFile, Consumer<Page> run);
PlaywrightUtils.runInDedicatedBrowser(String testName, String app, Consumer<Page> run);
PlaywrightUtils.runInDedicatedBrowser(String testName, Class<?> appClass, Consumer<Page> run);
Still have questions?
Go to our discussions forum for helpful information and advice from Jeamlit experts.