gpt4 book ai didi

java - 我想动态更新 gui.properties 文件的键值对

转载 作者:行者123 更新时间:2023-12-01 10:40:39 26 4
gpt4 key购买 nike

我正在研究 Selenium 自动化。我需要在运行时更新 GUI.properties 键值对。我尝试了以下代码,但没有反射(reflect)更改。

Properties p = new Properties();
try {
p.load(PropertyMap.class.getResourceAsStream("/gui.properties"));
p.setProperty(key, value);
return p;

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

在调用方法中,我是这样调用的

PropertyMap.setProperties("SoftwareLifecycleStage.Selectors", "Concept");

clickOnFieldIfValueIsNotNull(getSelectorsXPath(properties.getProperty("Myssi.SoftwareLifecycleStage.Selectors")), "LifecycleStageSelectors");

上面的方法clickonfieldifvalueisnotnull是一个通用方法,它只是通过xpath点击给定的元素,而getSelectorsXPath只是给出该元素的 xpath

我也尝试了以下代码...

Properties p = new Properties();
try {
PropertiesConfiguration config = new PropertiesConfiguration("src/test/resources/gui.properties");
config.setProperty(key, value);
} catch (ConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

请帮助我吗?

更新:-

添加

Config.save(); is worked for me... But the problem I am facing is After saving the file, I have given Thread.sleep(2000); to just reflect the changes, But it is not picking up the changed values for the next lines. I tried removing thread.sleep, but the same repeating.... After the execution of test, I have checked the gui.properties, the corresponding values have changed...

最佳答案

是否需要调用config.save();最后的方法?

Properties p = new Properties();
try {
PropertiesConfiguration config = new PropertiesConfiguration("src/test/resources/gui.properties");
config.setProperty(key, value);
// call save?
config.save();
} catch (ConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

关于java - 我想动态更新 gui.properties 文件的键值对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34433606/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com