Sarada Akurathi
Sarada Akurathi

Reputation: 1188

Is there a way to get the Bean ID in the xml file

I am working on selenium automation. My team using xml file for test data. Test data in xml file will be as beans and properties.

Each bean will be data for one testcase.

Now, we are creating each @Test method with each bean like below:

ApplicationContext ctx = new ClassPathXmlApplicationContext("/PostPaidRegistration.xml");
        RegistrationBean user = (RegistrationBean)ctx.getBean("postpaidTC1");

now in the testcase we will use the data of "postpaidTC1" bean.

for another testcase we write another @Test method as

ApplicationContext ctx = new ClassPathXmlApplicationContext("/PostPaidRegistration.xml");
        RegistrationBean user = (RegistrationBean)ctx.getBean("postpaidTC2");

I want to know, instead of creating many @Test methods for beans in the xml, any way to run all the beans(Test Data) in the xml with single @Test method as loop by getting BeanID .

My Xml is like below:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mongo="http://www.springframework.org/schema/data/mongo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/data/mongo 
    http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
    http://www.springframework.org/schema/data/repository
    http://www.springframework.org/schema/data/repository/spring-repository-1.0.xsd
    http://www.springframework.org/schema/data/jpa 
   http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd">
<bean id="postpaidTC1" class="com.tecnotree.CLM.beans.RegistrationBean">

    <property name="service" value="GSM SERVICE" />
    <property name="subService" value="Voice"/>
    <property name="technology" value="gsm"/>
    <property name="plan" value="POSTPAID ADV REN"/>
    <property name="mCategory" value="POSTPAID NORMAL 2"/>
    <property name="mSelection" value="Automatic"/>
    <property name="firstName" value="Sarada"/>
    <property name="middleName" value="M" />
    <property name="lastName" value="Akurathi"/>
    <property name ="dob" value="19/02/1989"/>
    <property name ="prefLang" value="ENGLISH"/>
    <property name ="prefMedium" value="Email"/>
    <property name ="prefMediumValue" value="[email protected]"/>
    <property name ="streetName" value="Gandhi Nagar"/>
    <property name ="buildingNumber" value="12"/>
    <property name ="docPurpose" value="Proof Identity"/>
    <property name ="docType" value="PANCARD"/>
    <property name ="docId" value="VETY3D343"/>
    <property name ="docPlaceOfIssue" value="Chennai"/>
    <property name ="billCycle" value="5th TO 4th MONTHLY BILL CYCLE"/>
</bean>
<bean id="postpaidTC2" class="com.tecnotree.CLM.beans.RegistrationBean">

    <property name="firstName" value="Suneetha"/>
    <property name="lastName" value="ss"/>
    <property name ="dob" value="19/02/1989"/>
    <property name ="prefLang" value="ENGLISH"/>
    <property name ="prefMedium" value="Email"/>
    <property name ="prefMediumValue" value="[email protected]"/>
    <property name="plan" value="POSTPAID ADV REN"/>

</bean>

</beans>

Upvotes: 0

Views: 634

Answers (1)

sinujohn
sinujohn

Reputation: 2604

Probably you could do

Map<String, RegistrationBean> beanMap = ctx.getBeansOfType(RegistrationBean.class)

and then iterate through the beanMap

Upvotes: 1

Related Questions