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

时间:2017-12-18 18:06:35

标签: java json selenium properties appium

我一直在寻找并且无法找到答案。我使用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

有人能指出我正确的方向吗?

1 个答案:

答案 0 :(得分:0)

弄清楚了。这是生成的代码。

    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));
        }
    }