使用某些键从java.properties文件加载映射

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用某些键从java.properties文件加载映射相关的知识,希望对你有一定的参考价值。

我一直在寻找,但找不到答案。我使用java .properties文件作为我的测试数据。我需要一种方法来遍历.properties文件并创建仅某些键的映射。我想要的.properties文件部分的结构是:

emulator.android.driver.URL = https://emulator.com:443/wd/hub
emulator.Android.driver.appiumVersion = 1.7.1
emulator.Android.driver.deviceOrientation = portrait
emulator.Android.driver.browserName = ""
emulator.Android.driver.app = myApp.apk
emulator.Android.driver.platformName = Android
emulator.Android.driver.platformVersion = 6.0
emulator.Android.driver.name = sSuiteName
emulator.Android.driver.deviceName = Android Emulator
emulator.Android.driver.appPackage=com.app.android.debug
emulator.Android.driver.appActivity=com.app.android.LaunchActivity
emulator.ios.driver.URL = https://emulator.com:443/wd/hub
emulator.iOS.driver.appiumVersion = 1.7.1
emulator.iOS.driver.deviceOrientation = portrait
emulator.iOS.driver.browserName = ""
emulator.iOS.driver.app = myApp.zip
emulator.iOS.driver.platformName = iOS
emulator.iOS.driver.platformVersion = 10.2
emulator.iOS.driver.deviceName = iPhone Simulator
emulator.iOS.driver.bundleId=com.qa
live.Android.driver.URL = https://live.com/wd/hub
live.Android.driver.apiKey = myKey
live.Android.driver.appiumVersion = 1.7.1
live.Android.driver.deviceOrientation = portrait
live.Android.driver.browserName = ""
live.Android.driver.app = myApp.apk
live.Android.driver.platformName = Android
live.Android.driver.platformVersion = 6.0
live.Android.driver.appPackage=com.app.android.debug
live.Android.driver.appActivity=com.app.android.LaunchActivity
live.iOS.driver.URL = https://live.com/wd/hub
live.iOS.driver.apiKey = myKey
live.iOS.driver.appiumVersion = 1.7.1
live.iOS.driver.deviceOrientation = portrait
live.iOS.driver.browserName = ""
live.iOS.driver.app = myApp.zip
live.iOS.driver.platformName = iOS
live.iOS.driver.platformVersion = 10.2
live.iOS.driver.name = sSuiteName
live.iOS.driver.bundleId=com.qa

注意:此文件中还有其他属性,但我只想要上述内容。我的目标是提取所有属性,如emulator.Android.driver。*删除emulator.Android.driver。并结束地图。例如,假设我想提取在iOS上运行的模拟器的属性。我最终会得到一张包含以下内容的地图:

URL = https://emulator.com:443/wd/hub
appiumVersion = 1.7.1
deviceOrientation = portrait
browserName = ""
app = myApp.zip
platformName = iOS
platformVersion = 10.2
deviceName = iPhone Simulator
bundleId=com.qa

下一次运行我可能会选择与Android一起使用,最后应该包含以下地图:

URL = https://live.com/wd/hub
apiKey = myKey
appiumVersion = 1.7.1
deviceOrientation = portrait
browserName = ""
app = myApp.apk
platformName = Android
platformVersion = 6.0
appPackage=com.app.android.debug
appActivity=com.app.android.LaunchActivity

谁能指出我正确的方向?

答案

明白了。这是结果代码。

    sSearchString = "emulator.Android.driver.";
    mDriverProperties = new HashMap<String, String>();
    Set<String> sKeys = pTestProperties.stringPropertyNames();
    for (String sKey : sKeys)
    {
        if (sKey.startsWith(sSearchString))
        {
            sKey = sKey.substring(sKey.lastIndexOf(".") + 1);
            mDriverProperties.put(sKey, pTestProperties.getProperty(sSearchString + sKey));
        }
    }

以上是关于使用某些键从java.properties文件加载映射的主要内容,如果未能解决你的问题,请参考以下文章

java properties类读取配置文件

给springmvc接口快速增加字段检索,外键从表检索,外键从表查询的searchdb注解

给springmvc接口快速增加字段检索,外键从表检索,外键从表查询的searchdb注解

当用户使用返回键从任何其他页面返回页面时如何刷新页面?

bash 使用散列键从 CSV 多列中读取

用几个键从字典中写入一个csv文件