diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/config/DeviceSetting.java b/src/main/java/com/github/wasiqb/coteafs/appium/config/DeviceSetting.java index fc685d4..b0581fd 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/config/DeviceSetting.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/config/DeviceSetting.java @@ -15,7 +15,7 @@ */ package com.github.wasiqb.coteafs.appium.config; -import static org.apache.commons.text.StringSubstitutor.replaceSystemProperties; +import static com.github.wasiqb.coteafs.appium.utils.StringUtil.replaceSystemProperty; import com.github.wasiqb.coteafs.appium.config.enums.ApplicationType; import com.github.wasiqb.coteafs.appium.config.enums.AutomationName; @@ -81,9 +81,7 @@ public AndroidDeviceSetting getAndroid () { * @return the appLocation */ public String getAppLocation () { - return this.appLocation.startsWith ("${") - ? replaceSystemProperties (this.appLocation) - : this.appLocation; + return replaceSystemProperty (this.appLocation); } /** diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/config/ServerSetting.java b/src/main/java/com/github/wasiqb/coteafs/appium/config/ServerSetting.java index 1ea65d3..7bf2b5c 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/config/ServerSetting.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/config/ServerSetting.java @@ -15,7 +15,7 @@ */ package com.github.wasiqb.coteafs.appium.config; -import static org.apache.commons.text.StringSubstitutor.replaceSystemProperties; +import static com.github.wasiqb.coteafs.appium.utils.StringUtil.replaceSystemProperty; import java.util.HashMap; import java.util.Map; @@ -128,9 +128,7 @@ public String getNodePath () { * @return the password */ public String getPassword () { - return this.password.startsWith ("${") - ? replaceSystemProperties (this.password) - : this.password; + return replaceSystemProperty (this.password); } /** @@ -175,9 +173,7 @@ public long getStartUpTimeOutSeconds () { * @return the userName */ public String getUserName () { - return this.userName.startsWith ("${") - ? replaceSystemProperties (this.userName) - : this.userName; + return replaceSystemProperty (this.userName); } /** diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/utils/StringUtil.java b/src/main/java/com/github/wasiqb/coteafs/appium/utils/StringUtil.java new file mode 100644 index 0000000..88f3090 --- /dev/null +++ b/src/main/java/com/github/wasiqb/coteafs/appium/utils/StringUtil.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) 2017-2020, Wasiq Bhamla. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.github.wasiqb.coteafs.appium.utils; + +import static org.apache.commons.lang3.StringUtils.isEmpty; +import static org.apache.commons.text.StringSubstitutor.replaceSystemProperties; + +/** + * @author wasiqb + * @since Oct 2, 2018 + */ +public final class StringUtil { + /** + * @author wasiqb + * @since Oct 2, 2018 + * @param value + * @return extracted string. + */ + public static String replaceSystemProperty (final String value) { + if (isEmpty (value)) + return null; + return value.startsWith ("${") ? replaceSystemProperties (value) : value; + } + + private StringUtil () { + // Util class. + } +} \ No newline at end of file diff --git a/src/test/resources/appium-config.yaml b/src/test/resources/appium-config.yaml index b704206..8f16b2b 100644 --- a/src/test/resources/appium-config.yaml +++ b/src/test/resources/appium-config.yaml @@ -41,7 +41,6 @@ devices: app_type: HYBRID device_type: REAL automation_name: APPIUM - app_location: apps/android/VodQA.apk app_location: ${env.app} cloud_app: true session_timeout: 120000