Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Java从属性文件中选择一组5个随机值?_Java_Selenium_Random_Selenium Webdriver - Fatal编程技术网

如何使用Java从属性文件中选择一组5个随机值?

如何使用Java从属性文件中选择一组5个随机值?,java,selenium,random,selenium-webdriver,Java,Selenium,Random,Selenium Webdriver,我在C:\test\目录中有一个名为test.properties的属性文件 在属性文件中,我有如下属性ID和属性值: TestID=Test1,Test2,Test3,Tes4 upto 10 @Test() public void test() throws Exception{ Properties APPTEXT = new Properties(); Log.info("Getting Input from the Property file"); FileInputStream

我在
C:\test\
目录中有一个名为
test.properties
的属性文件

在属性文件中,我有如下属性ID和属性值:

TestID=Test1,Test2,Test3,Tes4 upto 10
@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);
通过使用Java代码,我如何从属性文件中选择任意5个随机值,然后需要验证这些值在FE中是否可用

我是Java的初学者请帮助我编写一些示例代码

我尝试的代码如下:

TestID=Test1,Test2,Test3,Tes4 upto 10
@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);
@Test()
public void test()引发异常{
Properties APPTEXT=新属性();
Log.info(“从属性文件获取输入”);
FileInputStream fs=新的FileInputStream(“C:\\FilterSection\\dropdown.properties”);
APPTEXT.load(fs);
System.out.println(“+APPTEXT”);
Log.info(“1.验证属性文件和UI中的测试下拉列表值是否匹配”);
字符串[]expectedDropDownItemsInArray=APPTEXT.getProperty(“TestId”).trim().split(“,”);
随机r=新随机();
//System.out.println(expectedDropDownItemsInArray.length);
ArrayList expectedDropDownItems=新ArrayList();
对于(int i=0;i使用随机函数
Random rand=新的Random()

int idx=rand.nextInt(Array.length);
String random=(Array[idx]);

读取值并将其存储在
列表中

Collections.shuffle(list);

然后从列表中选取前5个元素。

有什么需要详细说明的?你如何尝试实现我的建议?为什么需要洗牌?我想要的解决方案首先需要直接从属性文件中选取任意五个值,然后需要存储并签入UI或直接签入UI。你能告诉我如何用示例代码选择一些随机值任何人都可以给我相关的示例代码,这样我就可以轻松理解。