gpt4 book ai didi

java - 有没有办法获取xml文件中的Bean ID

转载 作者:行者123 更新时间:2023-12-01 09:37:42 26 4
gpt4 key购买 nike

我正在研究 Selenium 自动化。我的团队使用 xml 文件作为测试数据。 xml 文件中的测试数据将作为 beans 和属性。

每个 bean 将是一个测试用例的数据。

现在,我们使用每个 bean 创建每个 @Test 方法,如下所示:

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

现在在测试用例中我们将使用“postpaidTC1”bean 的数据。

对于另一个测试用例,我们编写另一个 @Test 方法

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

我想知道,不是为 xml 中的 bean 创建许多 @Test 方法,而是通过获取 BeanID 来使用单个 @Test 方法作为循环来运行 xml 中的所有 bean(测试数据)。

我的Xml如下:

<?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="samyak@tt.com"/>
<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="samyak@tt.com"/>
<property name="plan" value="POSTPAID ADV REN"/>

</bean>

</beans>

最佳答案

也许你可以做到

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

然后迭代 beanMap

关于java - 有没有办法获取xml文件中的Bean ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38719478/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com