Package io.jmix.ui.testassist.junit
Class JmixUiTestExtension
java.lang.Object
io.jmix.ui.testassist.junit.JmixUiTestExtension
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterEachCallback,org.junit.jupiter.api.extension.BeforeEachCallback,org.junit.jupiter.api.extension.Extension,org.junit.jupiter.api.extension.ParameterResolver
public class JmixUiTestExtension
extends Object
implements org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.ParameterResolver
Extension starts Vaadin UI before each test and configures screen packages,
main screen id, username to perform authentication. For instance:
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {DemoApplication.class, UiTestAssistConfiguration.class})
public class UserBrowseTest {
@RegisterExtension
protected JmixUiTestExtension uiTestExtension = new JmixUiTestExtension()
.withAuthenticatedUser("admin")
.withScreenBasePackages("com.company.demo.screen")
.withMainScreenId("MainScreen");
@Test
protected void openUserBrowse(Screens screens) {
UserBrowse screen = screens.create(UserBrowse.class);
screen.show();
}
}
Screens bean can be obtained from method parameters or via BeanFactory.getBean(Class).- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterEach(org.junit.jupiter.api.extension.ExtensionContext context) voidbeforeEach(org.junit.jupiter.api.extension.ExtensionContext context) protected org.springframework.context.ApplicationContextgetApplicationContext(org.junit.jupiter.api.extension.ExtensionContext context) protected AppUIgetAppUI(org.junit.jupiter.api.extension.ExtensionContext context) String[]protected org.junit.jupiter.api.extension.ExtensionContext.StoregetStore(org.junit.jupiter.api.extension.ExtensionContext context) protected voidopenMainScreen(org.junit.jupiter.api.extension.ExtensionContext context) protected voidregisterScreenBasePackages(org.junit.jupiter.api.extension.ExtensionContext context) protected voidremoveAuthentication(org.junit.jupiter.api.extension.ExtensionContext context) resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) protected voidsetupAuthentication(org.junit.jupiter.api.extension.ExtensionContext context) protected voidsetupVaadinUi(org.junit.jupiter.api.extension.ExtensionContext context) booleansupportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) withAuthenticatedUser(String username) Sets username that should be authenticated before each test.withMainScreenId(String mainScreenId) Sets main screen id that should be opened before each test.withScreenBasePackages(String... screenBasePackages) Sets screen packages.
-
Field Details
-
APP_UI
- See Also:
-
SCREEN_PACKAGES
- See Also:
-
authenticatedUser
-
mainScreenId
-
screenBasePackages
-
-
Constructor Details
-
JmixUiTestExtension
public JmixUiTestExtension()
-
-
Method Details
-
getAuthenticatedUser
- Returns:
- username or
nullif not set
-
withAuthenticatedUser
Sets username that should be authenticated before each test. If username is not set, authentication will be performed by system user.- Parameters:
username- username- Returns:
- current instance
-
getMainScreenId
- Returns:
- main screen id or
nullif not set
-
withMainScreenId
Sets main screen id that should be opened before each test. The screen with given id should be placed under the package provided bywithScreenBasePackages(String...).If main screen id is not set, the
UiProperties.getMainScreenId()will be used.- Parameters:
mainScreenId- main screen id- Returns:
- current instance
-
getScreenBasePackages
- Returns:
- screen packages or
nullif not set
-
withScreenBasePackages
Sets screen packages. Screens under these packages will be available in test. If packages are not set, all application screens will be available depending on the test's configuration.- Parameters:
screenBasePackages- screen packages- Returns:
- current instance
-
beforeEach
- Specified by:
beforeEachin interfaceorg.junit.jupiter.api.extension.BeforeEachCallback- Throws:
Exception
-
afterEach
- Specified by:
afterEachin interfaceorg.junit.jupiter.api.extension.AfterEachCallback- Throws:
Exception
-
supportsParameter
public boolean supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException - Specified by:
supportsParameterin interfaceorg.junit.jupiter.api.extension.ParameterResolver- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-
resolveParameter
public Object resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException - Specified by:
resolveParameterin interfaceorg.junit.jupiter.api.extension.ParameterResolver- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-
setupAuthentication
protected void setupAuthentication(org.junit.jupiter.api.extension.ExtensionContext context) -
removeAuthentication
protected void removeAuthentication(org.junit.jupiter.api.extension.ExtensionContext context) -
setupVaadinUi
protected void setupVaadinUi(org.junit.jupiter.api.extension.ExtensionContext context) -
getApplicationContext
protected org.springframework.context.ApplicationContext getApplicationContext(org.junit.jupiter.api.extension.ExtensionContext context) -
getStore
protected org.junit.jupiter.api.extension.ExtensionContext.Store getStore(org.junit.jupiter.api.extension.ExtensionContext context) -
getAppUI
-
registerScreenBasePackages
protected void registerScreenBasePackages(org.junit.jupiter.api.extension.ExtensionContext context) -
openMainScreen
protected void openMainScreen(org.junit.jupiter.api.extension.ExtensionContext context)
-