-
Notifications
You must be signed in to change notification settings - Fork 11
Seperate Browser Sessions
This feature allows you to manage separate browser instances for test setup (@Before
) and cleanup (@After
) methods using dedicated annotations.
This is particularly useful when a proper clean up is essential for your testing or when you need to start testing after the set up in a clean session.
An unsolved problem for each testautomation are crashing browser instances. It happens rarely, nowadays but it does and when it does everything which should happen after the browser is closed can't be done. To ensure a proper cleanup of your test system, Neodymium offers a way to use seperate browsers with a clean session to perform setup and cleanup tasks.
Indicates that a new browser instance should be created specifically for the @Before
method execution.
@StartNewBrowserForSetUp
@BeforeEach
public void setUp() {
// This will run in a separate browser instance
// Browser will be automatically closed after setup
}
Indicates that a new browser instance should be created specifically for the @After
method execution.
@StartNewBrowserForCleanUp
@AfterEach
public void cleanUp() {
// This will run in a separate browser instance
// Browser will be automatically closed after cleanup
}
public class TestExample {
@StartNewBrowserForSetUp
@BeforeEach
public void setUp() {
// Setup code using dedicated browser
open("http://example.com");
// Perform setup operations
}
@NeodymiumTest
public void testFeature() {
// Main test code using main browser instance
}
@StartNewBrowserForCleanUp
@AfterEach
public void cleanUp() {
// Cleanup code using dedicated browser
open("http://example.com/cleanup");
// Perform cleanup operations
}
}
public class ComplexTestExample {
@StartNewBrowserForSetUp
@BeforeEach
public void prepareTestData() {
// Setup complex test data
open("http://admin.example.com");
// Create necessary test data
}
@NeodymiumTest
public void testUserFlow() {
// Test runs in its own browser instance
open("http://example.com");
// Test user flow
}
@StartNewBrowserForCleanUp
@AfterEach
public void removeTestData() {
// Clean up in separate browser
open("http://admin.example.com");
// Remove test data
}
}
This feature supports JUnit4 as well as JUnit5. The examples abofe can be easily transfered to JUnit4 by changing from @BeforeEach
to @Before
and @AfterEach
to @After
.
-
Browser Lifecycle
- Each annotated method receives a fresh browser instance
- Browser instances are automatically closed after method execution
-
Best Practices
- Use separate browsers when setup/cleanup requires different user sessions or the additional safety net for browser crashes.
- Consider performance implications of creating multiple browser instances
- Ensure proper error handling in setup and cleanup methods
-
Limitations
- @BeforeAll and @AfterAll (or for JUnit 4 @BeforeClass and @AfterClass) are NOT covered with this, due to the general Neodymium lifecycle.
- Browser state is not shared between different instances
- Each new browser instance requires additional system resources, but there are no browsers running in parallel
- Setup time may increase due to multiple browser launches
Overview
Neodymium features
- Neodymium configuration properties
- Neodymium context
- Utility classes
- Test data provider
- Test Environments
- Multi browser support
- Applitools Plugin
- Localization
- Highlight and Wait
- Advanced Screenshots
- Seperate Browser Sessions for Setup and Cleanup
Best practices and used frameworks
Special