我已经编写了如何从属性文件中读取选项的代码。但我不知道如何验证UI下拉中的相同值。
请任何人帮我一样的代码:
@Test()
public void Filterselection_1() throws Exception{
try {
FileInputStream fstream = new FileInputStream("C:/FilterSection/visualization.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
答案 0 :(得分:0)
尝试下面给出的代码
如果值列表不为空,即它包含属性文件中不存在的值,则打印消息说明相同。
@Test()
public void Filterselection_1() throws Exception{
try {
//Find the drop down
Select select = new Select(DropDownElement);
//Get all options to a List
List<WebElement> options = select.getOptions();
//Iterate through the list and create a list of String containing all the values
List<String> valueList = new ArrayList<String>();
for (Webelement option : options) {
valueList.add(option.getText());
}
FileInputStream fstream = new FileInputStream("C:/FilterSection/visualization.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
//find whether the value is present in the value list
if (valueList.contains(strLine)) {
valueList.remove(strLine);
} else {
System.out.println(strLine + "not found in the drop down");
}
}
//Close the input stream
in.close();
//check if valueList is empty (it will be empty if all the values
//in the dropdown are present in the property file)
if (!valueList.isEmpty()) {
Ststem.out.println("The following values present in the dropdown are not present in the property file : ");
for (String s : valueList) {
System.out.prinyln(s);
}
}
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
如果这有助于您,请告诉我。