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 Details

  • Constructor Details

    • JmixUiTestExtension

      public JmixUiTestExtension()
  • Method Details

    • getAuthenticatedUser

      @Nullable public String getAuthenticatedUser()
      Returns:
      username or null if not set
    • withAuthenticatedUser

      public JmixUiTestExtension withAuthenticatedUser(@Nullable String username)
      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

      @Nullable public String getMainScreenId()
      Returns:
      main screen id or null if not set
    • withMainScreenId

      public JmixUiTestExtension withMainScreenId(@Nullable String mainScreenId)
      Sets main screen id that should be opened before each test. The screen with given id should be placed under the package provided by withScreenBasePackages(String...).

      If main screen id is not set, the UiProperties.getMainScreenId() will be used.

      Parameters:
      mainScreenId - main screen id
      Returns:
      current instance
    • getScreenBasePackages

      @Nullable public String[] getScreenBasePackages()
      Returns:
      screen packages or null if not set
    • withScreenBasePackages

      public JmixUiTestExtension withScreenBasePackages(@Nullable String... screenBasePackages)
      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

      public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      beforeEach in interface org.junit.jupiter.api.extension.BeforeEachCallback
      Throws:
      Exception
    • afterEach

      public void afterEach(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      afterEach in interface org.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:
      supportsParameter in interface org.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:
      resolveParameter in interface org.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

      protected AppUI getAppUI(org.junit.jupiter.api.extension.ExtensionContext context)
    • registerScreenBasePackages

      protected void registerScreenBasePackages(org.junit.jupiter.api.extension.ExtensionContext context)
    • openMainScreen

      protected void openMainScreen(org.junit.jupiter.api.extension.ExtensionContext context)