12 Replies Latest reply on Apr 12, 2016 5:06 AM by mjobanek

    How to use CDI and before/after with UI tests?

    chschulz

      Hello,

       

      I am wondering if there is a way to use CDI in UI tests to be able to generate and delete test data in corresponding test phases.

       

      I have tried following code. It makes no difference if I am using the @RunAsClient annotation on class or method level.

       

      Is the only method to autogenerate data a Startup Bean or similar?

      The injected bean is null if it is called in before/after.

       

      @RunWith(Arquillian.class)
      public class ListControllerUiTest {
        @Drone
        private WebDriver browser;
      
      
        @Inject
        private TestDataProvider dataProvider;
      
      
        @Deployment
        public static WebArchive createDeployment() {
          ...
        }
      
      
        @Before
        public void insertData() {
          dataProvider.insertData(); // NPE
        }
      
        @After
        public void clearData() {
          dataProvider.clearData(); // NPE
        }
      
      
        @Test
        @RunAsClient
        public void showList(@InitialPage final ListPage page) {
          ...
        }