0

我已经包含了几行数据驱动的代码,我将从 Excel 工作表中获取详细信息,并将其传递给运行时中的脚本。在这里,我的脚本不会执行,并且在 Eclipse 控制台中返回消息后挂起:

返回单例 bean 'todoClient1' 的缓存实例

下面附上代码和包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);
            }
        }

在此处登录:

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'
4

1 回答 1

0

请参阅以下工作示例如何将 TestNG 数据提供程序与 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 },
        };
    }
}

根据示例,您缺少将数据提供程序参数转换为 Citrus 测试变量的 @CitrusParameters 注释。

于 2017-08-30T15:27:48.323 回答