Pass parameter variables from bean.xml to TestNG as a list

67 views
Skip to first unread message

Pavao Lukušić

unread,
May 27, 2021, 2:29:39 PM5/27/21
to testng-dev

I am fairly new in writing TestNG test cases and was wondering if there is a possibility to pass "object like" parameters in bean file to the test part?

For example: In bean file I have :

 ```
<parameter name="movieType1" value="Horror" /> 
<parameter name="numberOfMovies" value="150" /> 
<parameter name="totalEarnings" value="365789764" />
 <parameter name="movieType2" value="Action" /> 
<parameter name="numberOfMovies2" value="365555" />
 <parameter name="totalEarnings2" value="879784545642132" /> 

 more movie types, etc
 ```

Is there a way to create ban file in which I can pass variables as some kind of list of some class, like :
```
<movies>
           <movieType1>
                      <name value=horror> 
                      <numberOfMovies value=150> 
                       <total earnings value=365789764> 
            </movieType1> 
             <movieType2> 
                      <name value=aciton> 
                      <numberOfMovies value=365555> 
                      <total earnings value=879784545642132>
              </movieType2> 
 </movies> 
```
I know I can get each parameters in code like this :
```
@BeforeSuite @Parameters({ "movieType1", "numberOfMovies" , "totalEarnings", etc..}) private void beforeSuite(String movieType1, String numberOfMovies, String totalEarnings)
```

But what if I would like to enter 100 of movie types? I would need to write all variables (movieType1 ... MovieType100) inside of @Parameters tag ?

Is there a smarter way to pass those elements? (I really need to pass it from bean.xml file)

Any help would be really appreciated.

⇜Krishnan Mahadevan⇝

unread,
May 28, 2021, 2:02:46 AM5/28/21
to testn...@googlegroups.com
Are these parameters intended to be used by test methods or configurations ?

If they are test methods, then you can very well leverage a data provider ("@DataProvider") and have it feed off of the bean.xml file and work with it.

If they are configuration methods, then I am not sure if you have a lot of options.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/


--
You received this message because you are subscribed to the Google Groups "testng-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-dev/80391b1a-24c1-4141-8656-257c7929e06fn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages