匿名用户
1级
2016-08-25 回答
做自动测试时,使用yaml文件做界面要素配置,出现一个问题,经过自己的尝试实现了xpath方式的读取。把代码分项出来。尤其是在使用xpath是,会出现yaml读取出错的情况。此时需要将xpath的内容使用双引号括起来。代码如下
6
logout: type:name value:logoutlogoutConfirm: type:xpath value:"//*[@id='queding']//td/*//button"
来自CODE的代码片
snippet_file_0.txt
读取yaml文件的java代码如下
package com.bfm.utilities;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.util.HashMap;import org.ho.yaml.Yaml;/*该类为获取yaml文件中的内容*/public class YamlReader { private HashMap> yml; @SuppressWarnings("unchecked")public HashMap> getYamlFile(String yamlFile) { File f = new File(yamlFile); try { this.yml = (HashMap>) Yaml.loadType(new FileInputStream(f.getAbsolutePath()), HashMap.class); } catch (FileNotFoundException e) { e.printStackTrace(); } return this.yml; } public static void main (String args[]){ YamlReader yr = new YamlReader(); yr.getYamlFile("E:\\workspace\\bfm\\src\\com\\bfm\\pageElements\\mainPageElements.yaml"); }}