My execution halts while implemented the Data Driven Approach

143 views Asked by At

I have included few lines of code for data driven, where I will fetch the details from a Excel sheet and it will pass to the script in Run Time. Here my script won't execute and it hangs after returning the message in Eclipse Console:

Returning cached instance of singleton bean 'todoClient1'

Below attached the Code and package com.consol.citrus.integration.Demo.

 import java.util.Hashtable;

    import org.apache.log4j.helpers.SyslogWriter;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.context.annotation.ImportResource;
    import org.springframework.http.HttpStatus;
    import org.springframework.web.bind.annotation.ResponseStatus;
    import org.testng.SkipException;
    import org.testng.annotations.DataProvider;
    import org.testng.annotations.Test;
    import org.springframework.http.client.ClientHttpRequestInterceptor;
    import com.consol.citrus.TestCaseMetaInfo.Status;
    import com.consol.citrus.annotations.CitrusTest;
    import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;
    import com.consol.citrus.http.client.HttpClient;
    import com.consol.citrus.message.MessageType;



    public class UnSuccessFullLogin extends TestNGCitrusTestDesigner {

          @Autowired (required=true)
          @Qualifier("todoClient1")   
            private HttpClient todoClient1;

          public Xls_Reader xls=new Xls_Reader(Constants.DATA_XLS_PATH);
            String testCaseName="UnSuccessFullLogin";
            public String actualResult="";  


            @CitrusTest
            @Test(dataProvider="getData")
            public void TestPost(Hashtable<String, String> data) {

                echo("i am entered");
                variable("Uname", "admin2");
                variable("Pwd", "admin");
                if(!DataUtil.isTestExecutable(xls, testCaseName) ||  data.get(Constants.RUNMODE_COL).equals("N")){
                        throw new SkipException("Skipping the test as Rnumode is N");
                    } 
                http()

                    .client(todoClient1)            
                    .send()
                    .post("/rest/api/user/login")
                    .contentType("application/json")
                   // .payload("{ \"userName\": \"${uN}\", \"password\": \"${pwd}\"}");
                    .payload("{ \"userName\": \"${Uname}\", \"password\": \"${Pwd}\"}");




                http()
                    .client(todoClient1)
                    .receive()
                    .response(HttpStatus.ACCEPTED)
                   .validate("$.statusCode", "400");

            }
            @DataProvider
            public Object[][] getData()
            {
                return DataUtil.getData(xls, testCaseName);
            }
        }

Log Here:

17:37:56,650 DEBUG tListableBeanFactory| Creating shared instance of singleton bean 'todoClient'
17:37:56,650 DEBUG tListableBeanFactory| Creating instance of bean 'todoClient'
17:37:56,651 DEBUG tListableBeanFactory| Returning cached instance of singleton bean 'todoClientConfiguration'
17:37:56,675 DEBUG tListableBeanFactory| Eagerly caching bean 'todoClient' to allow for resolving potential circular references
17:37:56,690 DEBUG tListableBeanFactory| Finished creating instance of bean 'todoClient'
17:37:56,690 DEBUG tListableBeanFactory| Creating shared instance of singleton bean 'todoClient1Configuration'
17:37:56,690 DEBUG tListableBeanFactory| Creating instance of bean 'todoClient1Configuration'
17:37:56,691 DEBUG tListableBeanFactory| Eagerly caching bean 'todoClient1Configuration' to allow for resolving potential circular references
17:37:56,697 DEBUG tListableBeanFactory| Finished creating instance of bean 'todoClient1Configuration'
17:37:56,697 DEBUG tListableBeanFactory| Creating shared instance of singleton bean 'todoClient1'
17:37:56,697 DEBUG tListableBeanFactory| Creating instance of bean 'todoClient1'
17:37:56,697 DEBUG tListableBeanFactory| Returning cached instance of singleton bean 'todoClient1Configuration'
17:37:56,699 DEBUG tListableBeanFactory| Eagerly caching bean 'todoClient1' to allow for resolving potential circular references
17:37:56,699 DEBUG tListableBeanFactory| Finished creating instance of bean 'todoClient1'
17:37:56,699 DEBUG tListableBeanFactory| Returning cached instance of singleton bean 'globalVariables'
17:37:56,699 DEBUG tListableBeanFactory| Returning cached instance of singleton bean 'com.consol.citrus.report.MessageTracingTestListener#1'
17:37:56,700 DEBUG tListableBeanFactory| Returning cached instance of singleton bean 'org.springframework.context.event.internalEventListenerFactory'
17:37:56,851 DEBUG icApplicationContext| Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor@655a5d9c]
17:37:56,852 DEBUG tListableBeanFactory| Returning cached instance of singleton bean 'lifecycleProcessor'
17:37:56,856 DEBUG rcesPropertyResolver| Could not find key 'spring.liveBeansView.mbeanDomain' in any property source
17:37:56,866 DEBUG ontextLoaderDelegate| Storing ApplicationContext in cache under key [[MergedContextConfiguration@7bd7d6d6 testClass = UnSuccessFullLogin, locations = '{}', classes = '{class com.consol.citrus.config.CitrusSpringConfig}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextCustomizers = set[[empty]], contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]]
17:37:56,866 DEBUG        context.cache| Spring test ApplicationContext cache statistics: [DefaultContextCache@1a6f2363 size = 1, maxSize = 32, parentContextCount = 0, hitCount = 0, missCount = 1]
17:37:56,939 DEBUG on.InjectionMetadata| Processing injected element of bean 'com.consol.citrus.integration.Demo.UnSuccessFullLogin': AutowiredFieldElement for private com.consol.citrus.http.client.HttpClient com.consol.citrus.integration.Demo.UnSuccessFullLogin.todoClient1
17:37:56,942 DEBUG tListableBeanFactory| Returning cached instance of singleton bean 'todoClient1'
17:37:56,942 DEBUG ionBeanPostProcessor| Autowiring by type from bean name 'com.consol.citrus.integration.Demo.UnSuccessFullLogin' to bean named 'todoClient1'
17:37:56,947 DEBUG tListableBeanFactory| Returning cached instance of singleton bean 'testSuiteListeners'
17:37:56,947 DEBUG tListableBeanFactory| Returning cached instance of singleton bean 'testContextFactory'
5876 [main] INFO com.consol.citrus.Citrus - 
5876 [main] INFO com.consol.citrus.Citrus - ------------------------------------------------------------------------
5876 [main] INFO com.consol.citrus.Citrus -        .__  __                       
5876 [main] INFO com.consol.citrus.Citrus -   ____ |__|/  |________ __ __  ______
5876 [main] INFO com.consol.citrus.Citrus - _/ ___\|  \   __\_  __ \  |  \/  ___/
5876 [main] INFO com.consol.citrus.Citrus - \  \___|  ||  |  |  | \/  |  /\___ \ 
5876 [main] INFO com.consol.citrus.Citrus -  \___  >__||__|  |__|  |____//____  >
5876 [main] INFO com.consol.citrus.Citrus -      \/                           \/
5876 [main] INFO com.consol.citrus.Citrus - 
5876 [main] INFO com.consol.citrus.Citrus - C I T R U S  T E S T S  2.7.2
5876 [main] INFO com.consol.citrus.Citrus - 
5876 [main] INFO com.consol.citrus.Citrus - ------------------------------------------------------------------------
5876 [main] INFO com.consol.citrus.Citrus - 
5876 [main] INFO com.consol.citrus.Citrus - 
5876 [main] INFO com.consol.citrus.Citrus - BEFORE TEST SUITE: SUCCESS
5876 [main] INFO com.consol.citrus.Citrus - ------------------------------------------------------------------------
5876 [main] INFO com.consol.citrus.Citrus - 
17:37:56,974 DEBUG estExecutionListener| Before test class: context [DefaultTestContext@740fb309 testClass = UnSuccessFullLogin, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [MergedContextConfiguration@7bd7d6d6 testClass = UnSuccessFullLogin, locations = '{}', classes = '{class com.consol.citrus.config.CitrusSpringConfig}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextCustomizers = set[[empty]], contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]], class annotated with @DirtiesContext [false] with mode [null].
17:37:56,975 DEBUG estExecutionListener| Performing dependency injection for test context [[DefaultTestContext@740fb309 testClass = UnSuccessFullLogin, testInstance = com.consol.citrus.integration.Demo.UnSuccessFullLogin@5524cca1, testMethod = [null], testException = [null], mergedContextConfiguration = [MergedContextConfiguration@7bd7d6d6 testClass = UnSuccessFullLogin, locations = '{}', classes = '{class com.consol.citrus.config.CitrusSpringConfig}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextCustomizers = set[[empty]], contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]]].
17:37:56,975 DEBUG ontextLoaderDelegate| Retrieved ApplicationContext from cache with key [[MergedContextConfiguration@7bd7d6d6 testClass = UnSuccessFullLogin, locations = '{}', classes = '{class com.consol.citrus.config.CitrusSpringConfig}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextCustomizers = set[[empty]], contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]]
17:37:56,975 DEBUG        context.cache| Spring test ApplicationContext cache statistics: [DefaultContextCache@1a6f2363 size = 1, maxSize = 32, parentContextCount = 0, hitCount = 1, missCount = 1]
17:37:56,976 DEBUG on.InjectionMetadata| Processing injected element of bean 'com.consol.citrus.integration.Demo.UnSuccessFullLogin': AutowiredFieldElement for private com.consol.citrus.http.client.HttpClient com.consol.citrus.integration.Demo.UnSuccessFullLogin.todoClient1
17:37:56,976 DEBUG tListableBeanFactory| Returning cached instance of singleton bean 'todoClient1'
1

There are 1 answers

0
Christoph Deppisch On BEST ANSWER

Please see the following working sample how to use TestNG data provider with Citrus:

public class DataProviderJavaIT extends TestNGCitrusTestDesigner {

    @CitrusTest
    @CitrusParameters( {"message", "delay"} )
    @Test(dataProvider = "sampleDataProvider")
    public void dataProvider(String message, Long sleep) {
        echo(message);
        sleep(sleep);

        echo("${message}");
        echo("${delay}");
    }

    @DataProvider
    public Object[][] sampleDataProvider() {
        return new Object[][] {
                { "Hello World!", 300L },
                { "Hallo Welt!", 1000L },
                { "Hallo Citrus!", 500L },
        };
    }
}

According to the sample you are missing the @CitrusParameters annotation that translates data provider arguments to Citrus test variables.