2017-08-30 42 views
0

我已經包含了數據驅動的幾行代碼,我將從Excel工作表中讀取詳細信息,並在運行時傳遞給腳本。在這裏我的腳本將不執行,它在Eclipse控制檯返回消息後掛起:執行數據驅動方法時我的執行暫停

返回附在下面的代碼singleton的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 [[email protected]5a5d9c] 
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 [[[email protected] 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: [[email protected] 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 [[email protected] testClass = UnSuccessFullLogin, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [[email protected] 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 [[[email protected] testClass = UnSuccessFullLogin, testInstance = [email protected], testMethod = [null], testException = [null], mergedContextConfiguration = [[email protected] 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 [[[email protected] 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: [[email protected] 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' 

回答

0

請看下面的工作示例如何使用柑橘TestNG的數據提供者:

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 }, 
     }; 
    } 
} 

根據試樣你缺少的@CitrusParameters註釋將數據提供者參數轉換爲Citrus測試變量。