How to use testNG @Parameters in @BeforeSuite to read resource file

后端 未结 2 1951
广开言路
广开言路 2021-01-01 08:06

I am using testNG with Selenium webdriver2.0.

In my testNG.xml I have



        
2条回答
  •  悲&欢浪女
    2021-01-01 08:32

    Looks like your config-file parameter is not defined at the level. There are several ways to solve this: 1. Make sure the element is defined within tag but outside of any :

     
       
       
          
       
     
    

    2. If you want to have the default value for the parameter in the Java code despite the fact it is specified in testng.xml or not, you can add @Optional annotation to the method parameter:

    @BeforeSuite
    @Parameters( {"config-file"} )
    public void initFramework(@Optional("src/test/resources/config.properties/") String configfile) {
        //method implementation here
    }
    

    EDIT (based on posted testng.xml):

    Option 1:

    
      
      
        
          
            
            
          
        
        
          
        
       
    
    

    Option 2:

    @BeforeTest
    @Parameters( {"config-file"} )
    public void initFramework(@Optional("src/test/resources/config.properties/") String configfile) {
        //method implementation here
    }
    

    In any case, I would recommend not having two parameters with almost identical names, identical values, and different scope.

提交回复
热议问题