public void validateLMInterfaceBarcodeToMachine(){
String text = data.get(dataKey);
System.out.println("input: "+text);
String [] barcodeToMachine= text.split(";");
String inputBarcode = barcodeToMachine[0];
String inputType = barcodeToMachine[1];
try {
String barcode = driver.findElement(By.xpath(prop.getProperty("PanelTracking.LMInterface.validateBarcodeToMachine_xpath"))).getText();
if (barcode.equals(inputBarcode)) {
System.out.println("barcode to machine is displayed in LM interface configure");
test.log(Status.PASS, "barcode to machine is displayed in LM interface configure");
} else {
System.out.println("barcode to machine is not displayed in LM interface configure");
test.log(Status.FAIL, "barcode to machine is not displayed in LM interface configure");
}
}catch (Exception e){
System.out.println("barcode to machine is not displayed in LM interface configure");
test.log(Status.FAIL, "barcode to machine is not displayed in LM interface configure");
}
try{
Select select= new Select(driver.findElement(By.xpath(prop.getProperty("PanelTracking.LMInterface.validateBarcodeToMachineType_xpath"))));//new一个select对象,里面有封装好的下拉框操作方法
List<WebElement> webElements = select.getOptions();//获取下拉列表所有选项存入list
List<String> values = new ArrayList<>();
for(WebElement webElement:webElements){//获取各个选项里的字符串,并放入新建list里
values.add(webElement.getText());
}
String list = values.stream().collect(Collectors.joining(","));//将list转换成用“,”隔开的字符串
if (list.equals(inputType)) {
System.out.println("barcode to machine choice is displayed in LM interface configure");
test.log(Status.PASS,"barcode to machine choice is displayed in LM interface configure");
}
else {
System.out.println("barcode to machine choice is not displayed in LM interface configure");
test.log(Status.FAIL,"barcode to machine choice is not displayed in LM interface configure");
}
}catch (Exception e){
System.out.println("barcode to machine choice is not displayed in LM interface configure");
test.log(Status.FAIL,"barcode to machine choice is not displayed in LM interface configure");
}
}
Java selenium验证下拉框内容
于 2020-01-20 10:45:41 首次发布