我在 C:\Test\
目录中有一个名为 test.properties
的属性文件。
在 Property 文件中,我有 property ID 和 Property 值,如下所示:
TestID=Test1,Test2,Test3,Tes4 upto 10
通过使用 Java 代码,我如何从属性文件中选取任意 5 个随机值,然后需要验证这些值在 FE 中可用。
我是 Java 的初学者,请帮我写一些示例代码
我试过的代码如下:
@Test()
public void test() throws Exception{
Properties APPTEXT = new Properties();
Log.info("Getting Input from the Property file");
FileInputStream fs = new FileInputStream("C:\\FilterSection\\dropdown.properties");
APPTEXT.load(fs);
System.out.println ("" +APPTEXT);
Log.info("1. Verifying the Test drop down values are matching in both property file and UI");
String[] expectedDropDownItemsInArray = APPTEXT.getProperty("TestId").trim().split(",");
Random r = new Random();
//System.out.println(expectedDropDownItemsInArray.length);
ArrayList<String> expectedDropDownItems = new ArrayList<String>();
for(int i=0; i<expectedDropDownItemsInArray.length; i++)
expectedDropDownItems.add(expectedDropDownItemsInArray[i]);
System.out.println(expectedDropDownItems+"" );
Thread.sleep(6000);
最佳答案
您读取值并将它们存储在 List<String>
中.然后你使用
Collections.shuffle(list);
然后从列表中取出前 5 个元素。
关于java - 如何使用 Java 从属性文件中选择一组 5 个随机值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22854719/