未从Selenium网络驱动程序中的配置文件接收到正确的值
Not receiving correct value from Config file in Selenium webdriver
将配置文件中的数据作为test_data_path = C:''Sudheer''Sudheer''Selinium scripts''Webdriverscrip''Automation_Project''TestData''Nlpapplication.xlsx
当我运行下面的脚本时,结果显示缺少一个斜杠
C:'Sudheer'Sudheer'Selinium scripts'Webdriverscrip'Automation_Project'TestData'Nlpapplication.xlsx
public class Testconfigvalues {
public static void main(String[] args) throws IOException {
FileInputStream fs = null;
fs = new FileInputStream(System.getProperty("user.dir")+"''config.properties");
Properties property=new Properties();
property.load(fs);
String data_test_data_path = property.getProperty("test_data_path");
System.out.println("value is " +data_test_data_path);
}
}
您应该覆盖函数加载函数,因为它正在转义''字符。
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Properties;
public class NetbeansProperties extends Properties {
@Override
public synchronized void load(Reader reader) throws IOException {
BufferedReader bfr = new BufferedReader(reader);
ByteArrayOutputStream out = new ByteArrayOutputStream();
String readLine = null;
while ((readLine = bfr.readLine()) != null) {
out.write(readLine.replace("''", "''''").getBytes());
out.write("'n".getBytes());
}
InputStream is = new ByteArrayInputStream(out.toByteArray());
super.load(is);
}
@Override
public void load(InputStream is) throws IOException {
load(new InputStreamReader(is));
}
}
类从配置文件读取数据:
import java.io.FileInputStream;
import java.io.IOException;
public class ReadConfig {
public static void main(String[] args) throws IOException {
FileInputStream fs = null;
fs = new FileInputStream(System.getProperty("user.dir") + "''config.properties");
NetbeansProperties property = new NetbeansProperties();
property.load(fs);
String data_test_data_path = property.getProperty("test_data_path");
System.out.println("value is " + data_test_data_path);
}
}
相关文章:
- 使用javascript配置文件作为handlebas博客模板,但配置不是't工作正常
- 我可以访问量角器配置文件中的参数吗
- 如何从配置文件中设置Angular值
- SoundCloud API-基于系统中的ID创建用户配置文件
- 先在Angular中加载配置文件,然后再加载其他文件
- 正在读取节点中的配置文件
- 检查蒸汽配置文件url是否有效
- 将配置文件文件夹移动到sdcardfirefoxmobile14.0
- 可能有一个javascript和php的配置文件
- 对CommonJS配置文件使用全局变量
- 未从Selenium网络驱动程序中的配置文件接收到正确的值
- 使用AddThis-config-data_ga_property向两个Google Analytics配置文件报告
- 如何使用浏览器“需要”配置文件,但不将此文件包含在捆绑包中
- Webdriver:用于动态禁用/启用JavaScript弹出窗口的Firefox配置文件
- 如何从 Webjar 解析多个 RequireJS 配置文件
- 通过oauth令牌passport.js访问用户配置文件
- mongodb用户配置文件添加输入时出现问题
- 如何使用ian:accounts-ui-botstrap-3根据Meteor中的用户输入设置配置文件字段值
- 设置Selenium Firefox配置文件
- 如何在c# Selenium中向FirefoxDriverService添加配置文件规范?