diff --git a/.circleci/config.yml b/.circleci/config.yml index cba99a6..9dd87c1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -65,7 +65,7 @@ jobs: - repo-reports-{{ .Branch }}-{{ .Revision }} - run: name: Update Sonar Analysis - command: mvn package sonar:sonar -Dsonar.host.url=$SONAR_HOST -Dsonar.organization=$SONAR_ORG -Dsonar.login=$SONAR_KEY + command: mvn package sonar:sonar -Dsonar.host.url=$SONAR_HOST -Dsonar.organization=$SONAR_ORG -Dsonar.login=$SONAR_KEY -DskipTests=true filters: &all_branches branches: @@ -88,4 +88,8 @@ workflows: - build: filters: *all_branches requires: - - resolve_dependencies \ No newline at end of file + - resolve_dependencies + - code_analysis: + filters: *all_branches + requires: + - build \ No newline at end of file diff --git a/pom.xml b/pom.xml index a25bad0..d0c01ce 100644 --- a/pom.xml +++ b/pom.xml @@ -1,16 +1,17 @@ - 4.0.0 appium 2.2.0 ${project.groupId}:${project.artifactId} - Automation Framework wrapped over Appium. + Robust Automation Framework wrapped over Appium. https://github.com/WasiqB/coteafs-appium com.github.wasiqb.coteafs parent - 2.0.1 + 2.0.1 @@ -25,8 +26,8 @@ - travis - https://travis-ci.org/WasiqB/coteafs-appium + Circle CI + https://circleci.com/gh/WasiqB/coteafs-appium @@ -35,6 +36,7 @@ 1.6.0 1.5.0 1.6.0 + 1.4 @@ -49,6 +51,11 @@ + + org.apache.commons + commons-text + ${commons.text.version} + com.github.wasiqb.coteafs error 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 dc8e94a..fc685d4 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,6 +15,14 @@ */ package com.github.wasiqb.coteafs.appium.config; +import static org.apache.commons.text.StringSubstitutor.replaceSystemProperties; + +import com.github.wasiqb.coteafs.appium.config.enums.ApplicationType; +import com.github.wasiqb.coteafs.appium.config.enums.AutomationName; +import com.github.wasiqb.coteafs.appium.config.enums.Browser; +import com.github.wasiqb.coteafs.appium.config.enums.DeviceType; +import com.github.wasiqb.coteafs.appium.config.enums.PlatformType; + /** * @author wasiq.bhamla * @since 12-Apr-2017 8:34:28 PM @@ -26,6 +34,7 @@ public class DeviceSetting { private AutomationName automationName; private Browser browser; private boolean clearSystemFiles; + private boolean cloudApp; private String deviceName; private DeviceType deviceType; private String deviceVersion; @@ -54,6 +63,7 @@ public DeviceSetting () { this.externalApp = false; this.clearSystemFiles = false; this.sessionTimeout = 120; + this.cloudApp = false; } /** @@ -71,7 +81,9 @@ public AndroidDeviceSetting getAndroid () { * @return the appLocation */ public String getAppLocation () { - return this.appLocation; + return this.appLocation.startsWith ("${") + ? replaceSystemProperties (this.appLocation) + : this.appLocation; } /** @@ -191,6 +203,15 @@ public boolean isClearSystemFiles () { return this.clearSystemFiles; } + /** + * @author wasiqb + * @since Sep 29, 2018 + * @return the cloudApp + */ + public boolean isCloudApp () { + return this.cloudApp; + } + /** * @author wasiq.bhamla * @since Nov 19, 2017 9:54:14 PM @@ -287,6 +308,16 @@ public void setClearSystemFiles (final boolean clearSystemFiles) { this.clearSystemFiles = clearSystemFiles; } + /** + * @author wasiqb + * @since Sep 29, 2018 + * @param cloudApp + * the cloudApp to set + */ + public void setCloudApp (final boolean cloudApp) { + this.cloudApp = cloudApp; + } + /** * @author wasiq.bhamla * @since 12-Apr-2017 8:42:49 PM diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/config/ServerArgumentSetting.java b/src/main/java/com/github/wasiqb/coteafs/appium/config/ServerArgumentSetting.java index db4af31..adbe9f1 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/config/ServerArgumentSetting.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/config/ServerArgumentSetting.java @@ -15,6 +15,8 @@ */ package com.github.wasiqb.coteafs.appium.config; +import com.github.wasiqb.coteafs.appium.config.enums.LogLevel; + /** * @author wasiq.bhamla * @since Oct 27, 2017 1:26:27 PM 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 b7a2682..1ea65d3 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,9 +15,13 @@ */ package com.github.wasiqb.coteafs.appium.config; +import static org.apache.commons.text.StringSubstitutor.replaceSystemProperties; + import java.util.HashMap; import java.util.Map; +import com.github.wasiqb.coteafs.appium.config.enums.Protocol; + /** * @author wasiq.bhamla * @since 12-Apr-2017 8:43:22 PM @@ -31,16 +35,20 @@ public class ServerSetting { private String appiumJsPath; private ServerArgumentSetting arguments; + private boolean cloud; private Map environmentVariables; private boolean external; private boolean fullReset; - private String ip; + private String host; private String logFilePath; private String nodePath; private boolean noReset; + private String password; private int port; + private Protocol protocol; private int sessionTimeout; private long startUpTimeOutSeconds; + private String userName; /** * @author wasiq.bhamla @@ -48,13 +56,16 @@ public class ServerSetting { */ public ServerSetting () { countInstance++; + this.cloud = false; this.external = false; this.noReset = false; this.fullReset = false; this.sessionTimeout = 120; this.startUpTimeOutSeconds = 60; this.environmentVariables = new HashMap <> (); - this.logFilePath = String.format ("%s/logs/server-%d.log", System.getProperty ("user.dir"), countInstance); + this.protocol = Protocol.HTTP; + this.logFilePath = String.format ("%s/logs/server-%d.log", System.getProperty ("user.dir"), + countInstance); } /** @@ -87,10 +98,10 @@ public Map getEnvironmentVariables () { /** * @author wasiq.bhamla * @since 12-Apr-2017 8:51:26 PM - * @return the ip + * @return the host */ - public String getIp () { - return this.ip; + public String getHost () { + return this.host; } /** @@ -111,6 +122,17 @@ public String getNodePath () { return this.nodePath; } + /** + * @author wasiqb + * @since Sep 29, 2018 + * @return the password + */ + public String getPassword () { + return this.password.startsWith ("${") + ? replaceSystemProperties (this.password) + : this.password; + } + /** * @author wasiq.bhamla * @since 12-Apr-2017 8:51:26 PM @@ -120,6 +142,15 @@ public int getPort () { return this.port; } + /** + * @author wasiqb + * @since Sep 29, 2018 + * @return the protocol + */ + public Protocol getProtocol () { + return this.protocol; + } + /** * @author wasiq.bhamla * @since 08-May-2017 7:49:31 PM @@ -138,6 +169,26 @@ public long getStartUpTimeOutSeconds () { return this.startUpTimeOutSeconds; } + /** + * @author wasiqb + * @since Sep 29, 2018 + * @return the userName + */ + public String getUserName () { + return this.userName.startsWith ("${") + ? replaceSystemProperties (this.userName) + : this.userName; + } + + /** + * @author wasiqb + * @since Sep 29, 2018 + * @return the cloud + */ + public boolean isCloud () { + return this.cloud; + } + /** * @author wasiq.bhamla * @since 21-Apr-2017 5:06:22 PM @@ -185,6 +236,16 @@ public void setArguments (final ServerArgumentSetting arguments) { this.arguments = arguments; } + /** + * @author wasiqb + * @since Sep 29, 2018 + * @param cloud + * the cloud to set + */ + public void setCloud (final boolean cloud) { + this.cloud = cloud; + } + /** * @author wasiq.bhamla * @since Oct 27, 2017 1:28:09 PM @@ -218,11 +279,11 @@ public void setFullReset (final boolean fullReset) { /** * @author wasiq.bhamla * @since 12-Apr-2017 8:51:26 PM - * @param ip - * the ip to set + * @param host + * the host to set */ - public void setIp (final String ip) { - this.ip = ip; + public void setHost (final String host) { + this.host = host; } /** @@ -255,6 +316,16 @@ public void setNoReset (final boolean noReset) { this.noReset = noReset; } + /** + * @author wasiqb + * @since Sep 29, 2018 + * @param password + * the password to set + */ + public void setPassword (final String password) { + this.password = password; + } + /** * @author wasiq.bhamla * @since 12-Apr-2017 8:51:26 PM @@ -265,6 +336,16 @@ public void setPort (final int port) { this.port = port; } + /** + * @author wasiqb + * @since Sep 29, 2018 + * @param protocol + * the protocol to set + */ + public void setProtocol (final Protocol protocol) { + this.protocol = protocol; + } + /** * @author wasiq.bhamla * @since 08-May-2017 7:49:31 PM @@ -284,4 +365,14 @@ public void setSessionTimeout (final int sessionTimeout) { public void setStartUpTimeOutSeconds (final long startUpTimeOutSeconds) { this.startUpTimeOutSeconds = startUpTimeOutSeconds; } + + /** + * @author wasiqb + * @since Sep 29, 2018 + * @param userName + * the userName to set + */ + public void setUserName (final String userName) { + this.userName = userName; + } } \ No newline at end of file diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/config/ApplicationType.java b/src/main/java/com/github/wasiqb/coteafs/appium/config/enums/ApplicationType.java similarity index 93% rename from src/main/java/com/github/wasiqb/coteafs/appium/config/ApplicationType.java rename to src/main/java/com/github/wasiqb/coteafs/appium/config/enums/ApplicationType.java index d751e2b..fdda332 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/config/ApplicationType.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/config/enums/ApplicationType.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.github.wasiqb.coteafs.appium.config; +package com.github.wasiqb.coteafs.appium.config.enums; /** * @author wasiq.bhamla diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/config/AutomationName.java b/src/main/java/com/github/wasiqb/coteafs/appium/config/enums/AutomationName.java similarity index 94% rename from src/main/java/com/github/wasiqb/coteafs/appium/config/AutomationName.java rename to src/main/java/com/github/wasiqb/coteafs/appium/config/enums/AutomationName.java index 3621a90..db99fd8 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/config/AutomationName.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/config/enums/AutomationName.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.github.wasiqb.coteafs.appium.config; +package com.github.wasiqb.coteafs.appium.config.enums; /** * @author wasiq.bhamla diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/config/Browser.java b/src/main/java/com/github/wasiqb/coteafs/appium/config/enums/Browser.java similarity index 95% rename from src/main/java/com/github/wasiqb/coteafs/appium/config/Browser.java rename to src/main/java/com/github/wasiqb/coteafs/appium/config/enums/Browser.java index 7be6337..e872bb9 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/config/Browser.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/config/enums/Browser.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.github.wasiqb.coteafs.appium.config; +package com.github.wasiqb.coteafs.appium.config.enums; import io.appium.java_client.remote.MobileBrowserType; diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/config/DeviceType.java b/src/main/java/com/github/wasiqb/coteafs/appium/config/enums/DeviceType.java similarity index 93% rename from src/main/java/com/github/wasiqb/coteafs/appium/config/DeviceType.java rename to src/main/java/com/github/wasiqb/coteafs/appium/config/enums/DeviceType.java index 0976dcf..b60c38d 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/config/DeviceType.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/config/enums/DeviceType.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.github.wasiqb.coteafs.appium.config; +package com.github.wasiqb.coteafs.appium.config.enums; /** * @author wasiq.bhamla diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/config/LogLevel.java b/src/main/java/com/github/wasiqb/coteafs/appium/config/enums/LogLevel.java similarity index 97% rename from src/main/java/com/github/wasiqb/coteafs/appium/config/LogLevel.java rename to src/main/java/com/github/wasiqb/coteafs/appium/config/enums/LogLevel.java index 6a84d8a..930c0d4 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/config/LogLevel.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/config/enums/LogLevel.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.github.wasiqb.coteafs.appium.config; +package com.github.wasiqb.coteafs.appium.config.enums; /** * @author wasiq.bhamla diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/config/PlatformType.java b/src/main/java/com/github/wasiqb/coteafs/appium/config/enums/PlatformType.java similarity index 95% rename from src/main/java/com/github/wasiqb/coteafs/appium/config/PlatformType.java rename to src/main/java/com/github/wasiqb/coteafs/appium/config/enums/PlatformType.java index 8431abb..cb4e473 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/config/PlatformType.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/config/enums/PlatformType.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.github.wasiqb.coteafs.appium.config; +package com.github.wasiqb.coteafs.appium.config.enums; import io.appium.java_client.remote.MobilePlatform; diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/config/enums/Protocol.java b/src/main/java/com/github/wasiqb/coteafs/appium/config/enums/Protocol.java new file mode 100644 index 0000000..3679ce7 --- /dev/null +++ b/src/main/java/com/github/wasiqb/coteafs/appium/config/enums/Protocol.java @@ -0,0 +1,46 @@ +/** + * 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.config.enums; + +/** + * @author wasiqb + * @since Sep 29, 2018 + */ +public enum Protocol { + /** + * HTTP protocol. + */ + HTTP ("http"), + /** + * HTTPS protocol. + */ + HTTPS ("https"); + + private final String name; + + private Protocol (final String name) { + this.name = name; + } + + /** + * @author wasiqb + * @since Sep 29, 2018 + * @return the protocol name + */ + public String getName () { + return this.name; + } +} \ No newline at end of file diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/device/Device.java b/src/main/java/com/github/wasiqb/coteafs/appium/device/Device.java index 6d031f1..7ac055b 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/device/Device.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/device/Device.java @@ -79,11 +79,11 @@ import com.github.wasiqb.coteafs.appium.checker.ServerChecker; import com.github.wasiqb.coteafs.appium.config.AndroidDeviceSetting; import com.github.wasiqb.coteafs.appium.config.AppiumSetting; -import com.github.wasiqb.coteafs.appium.config.ApplicationType; import com.github.wasiqb.coteafs.appium.config.DeviceSetting; -import com.github.wasiqb.coteafs.appium.config.DeviceType; import com.github.wasiqb.coteafs.appium.config.IOSDeviceSetting; -import com.github.wasiqb.coteafs.appium.config.PlatformType; +import com.github.wasiqb.coteafs.appium.config.enums.ApplicationType; +import com.github.wasiqb.coteafs.appium.config.enums.DeviceType; +import com.github.wasiqb.coteafs.appium.config.enums.PlatformType; import com.github.wasiqb.coteafs.appium.error.AppiumServerStoppedError; import com.github.wasiqb.coteafs.appium.error.DeviceAppNotFoundError; import com.github.wasiqb.coteafs.appium.error.DeviceDesiredCapabilitiesNotSetError; @@ -201,8 +201,8 @@ private void buildCapabilities () { if (this.setting.getAppType () == ApplicationType.WEB) { setCapability (BROWSER_NAME, this.setting.getBrowser (), this.capabilities, true); } else { - final String appPath = this.setting.getAppLocation (); - if (appPath != null) { + String appPath = this.setting.getAppLocation (); + if (appPath != null && !this.setting.isCloudApp ()) { String path = "%s/src/test/resources/%s"; path = String.format (path, getProperty ("user.dir"), appPath); @@ -216,8 +216,9 @@ private void buildCapabilities () { log.error (String.format (msg, path)); fail (DeviceAppNotFoundError.class, String.format (msg, path)); } - setCapability (APP, path, this.capabilities, true); + appPath = path; } + setCapability (APP, appPath, this.capabilities, true); } log.trace ("Building Device capabilities completed..."); } diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceActivity.java b/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceActivity.java index 2357eee..ee53d36 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceActivity.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceActivity.java @@ -33,8 +33,8 @@ import org.openqa.selenium.support.ui.WebDriverWait; import com.github.wasiqb.coteafs.appium.checker.ServerChecker; -import com.github.wasiqb.coteafs.appium.config.PlatformType; import com.github.wasiqb.coteafs.appium.config.PlaybackSetting; +import com.github.wasiqb.coteafs.appium.config.enums.PlatformType; import com.github.wasiqb.coteafs.appium.error.AppiumSelectorNotImplementedError; import com.github.wasiqb.coteafs.appium.error.AppiumServerStoppedError; import com.github.wasiqb.coteafs.appium.error.DeviceElementFindTimedOutError; diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceElementActions.java b/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceElementActions.java index 64e91f0..55d8d7f 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceElementActions.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/device/DeviceElementActions.java @@ -109,9 +109,7 @@ public void clear () { * @since Jul 15, 2017 6:12:00 PM */ public void click () { - perform ("Clicking on", e -> { - e.click (); - }); + perform ("Clicking on", MobileElement::click); } /** diff --git a/src/main/java/com/github/wasiqb/coteafs/appium/service/AppiumServer.java b/src/main/java/com/github/wasiqb/coteafs/appium/service/AppiumServer.java index b3956b2..121eb65 100644 --- a/src/main/java/com/github/wasiqb/coteafs/appium/service/AppiumServer.java +++ b/src/main/java/com/github/wasiqb/coteafs/appium/service/AppiumServer.java @@ -15,6 +15,7 @@ */ package com.github.wasiqb.coteafs.appium.service; +import static com.github.wasiqb.coteafs.appium.checker.ServerChecker.checkServerConfigParams; import static com.github.wasiqb.coteafs.appium.constants.ConfigKeys.COTEAFS_CONFIG_DEFAULT_FILE; import static com.github.wasiqb.coteafs.appium.constants.ConfigKeys.COTEAFS_CONFIG_KEY; import static com.github.wasiqb.coteafs.appium.utils.CapabilityUtils.setCapability; @@ -50,7 +51,6 @@ import org.apache.logging.log4j.Logger; import org.openqa.selenium.remote.DesiredCapabilities; -import com.github.wasiqb.coteafs.appium.checker.ServerChecker; import com.github.wasiqb.coteafs.appium.config.AndroidArgumentSetting; import com.github.wasiqb.coteafs.appium.config.AppiumSetting; import com.github.wasiqb.coteafs.appium.config.IOSArgumentSetting; @@ -74,11 +74,7 @@ * @since 12-Apr-2017 5:17:22 PM */ public final class AppiumServer { - private static final Logger log; - - static { - log = LogManager.getLogger (AppiumServer.class); - } + private static final Logger log = LogManager.getLogger (AppiumServer.class); private AppiumServiceBuilder builder; private DesiredCapabilities capabilities; @@ -92,11 +88,11 @@ public final class AppiumServer { */ public AppiumServer (final String name) { this.setting = ConfigLoader.settings () - .withKey (COTEAFS_CONFIG_KEY) - .withDefault (COTEAFS_CONFIG_DEFAULT_FILE) - .load (AppiumSetting.class) - .getServer (name); - if (!this.setting.isExternal ()) { + .withKey (COTEAFS_CONFIG_KEY) + .withDefault (COTEAFS_CONFIG_DEFAULT_FILE) + .load (AppiumSetting.class) + .getServer (name); + if (!this.setting.isExternal () && !this.setting.isCloud ()) { initService (); buildCapabilities (); buildService (); @@ -110,14 +106,12 @@ public AppiumServer (final String name) { */ public URL getServiceUrl () { log.trace ("Fetching Appium Service URL..."); - if (!this.setting.isExternal ()) { + if (!this.setting.isExternal () && !this.setting.isCloud ()) return this.service.getUrl (); - } - final String url = String.format ("http://%s:%d/wd/hub", this.setting.getIp (), this.setting.getPort ()); + final String url = String.format ("%s/wd/hub", getUrl ()); try { return new URL (url); - } - catch (final MalformedURLException e) { + } catch (final MalformedURLException e) { log.error ("Error occurred while getting service url..."); log.catching (e); } @@ -130,15 +124,17 @@ public URL getServiceUrl () { * @return isRunning */ public boolean isRunning () { + if (this.setting.isCloud ()) + return true; if (!this.setting.isExternal ()) { log.trace ("Checking if Appium Service is running..."); return this.service.isRunning (); } - final SocketAddress addr = new InetSocketAddress (this.setting.getIp (), this.setting.getPort ()); + final SocketAddress addr = new InetSocketAddress (this.setting.getHost (), + this.setting.getPort ()); try (Socket socket = new Socket ()) { socket.connect (addr, 2000); - } - catch (final IOException e) { + } catch (final IOException e) { fail (AppiumServerNotRunningError.class, "Error connecting to Server...", e); } return true; @@ -150,20 +146,19 @@ public boolean isRunning () { */ public void start () { log.trace ("Starting Appium Service..."); - if (!this.setting.isExternal ()) { + if (!this.setting.isExternal () && !this.setting.isCloud ()) { this.service = AppiumDriverLocalService.buildService (this.builder); try { this.service.start (); - } - catch (final AppiumServerHasNotBeenStartedLocallyException e) { - fail (AppiumServerNotStartingError.class, "Error occured while starting Appium server", e); - } - catch (final Exception e) { - fail (AppiumServerAlreadyRunningError.class, "Appium server is running already.", e); + } catch (final AppiumServerHasNotBeenStartedLocallyException e) { + fail (AppiumServerNotStartingError.class, + "Error occured while starting Appium server", e); + } catch (final Exception e) { + fail (AppiumServerAlreadyRunningError.class, "Appium server is running already.", + e); } log.trace ("Appium Service Started..."); - } - else { + } else { if (isRunning ()) { log.trace ("Appium Service is already running..."); } @@ -176,17 +171,16 @@ public void start () { */ public void stop () { log.trace ("Trying to stop Appium Service..."); - if (!this.setting.isExternal ()) { + if (!this.setting.isExternal () && !this.setting.isCloud ()) { try { this.service.stop (); - } - catch (final Exception e) { - fail (AppiumServerNotStoppingError.class, "Error occured while stopping the server.", e); + } catch (final Exception e) { + fail (AppiumServerNotStoppingError.class, + "Error occured while stopping the server.", e); } this.service = null; log.trace ("Appium Service Stopped..."); - } - else { + } else { log.trace ("Appium Service can only be stopped from the tool you started with..."); } } @@ -197,19 +191,20 @@ public void stop () { */ private void buildCapabilities () { log.trace ("Building Appium Capabilities started..."); - setCapability (MobileCapabilityType.NO_RESET, Boolean.toString (this.setting.isNoReset ()), this.capabilities); - setCapability (MobileCapabilityType.FULL_RESET, Boolean.toString (this.setting.isFullReset ()), - this.capabilities); - setCapability (MobileCapabilityType.NEW_COMMAND_TIMEOUT, Integer.toString (this.setting.getSessionTimeout ()), + setCapability (MobileCapabilityType.NO_RESET, Boolean.toString (this.setting.isNoReset ()), this.capabilities); + setCapability (MobileCapabilityType.FULL_RESET, + Boolean.toString (this.setting.isFullReset ()), this.capabilities); + setCapability (MobileCapabilityType.NEW_COMMAND_TIMEOUT, + Integer.toString (this.setting.getSessionTimeout ()), this.capabilities); log.trace ("Building Appium Capabilities completed..."); } private void buildService () { log.trace ("Building Appium Service started..."); - ServerChecker.checkServerConfigParams ("IP Address", this.setting.getIp ()); - this.builder = this.builder.withIPAddress (this.setting.getIp ()) - .withStartUpTimeOut (this.setting.getStartUpTimeOutSeconds (), TimeUnit.SECONDS); + checkServerConfigParams ("IP Host Address", this.setting.getHost ()); + this.builder = this.builder.withIPAddress (this.setting.getHost ()) + .withStartUpTimeOut (this.setting.getStartUpTimeOutSeconds (), TimeUnit.SECONDS); setPort (); setLogFile (); setAppiumJS (); @@ -220,6 +215,25 @@ private void buildService () { log.trace ("Building Appium Service done..."); } + private String getUrl () { + final StringBuilder sb = new StringBuilder (this.setting.getProtocol () + .getName ()).append ("://"); + if (this.setting.isCloud ()) { + checkServerConfigParams ("User Name", this.setting.getUserName ()); + checkServerConfigParams ("Password", this.setting.getPassword ()); + sb.append (this.setting.getUserName ()) + .append (":") + .append (this.setting.getPassword ()) + .append ("@") + .append (this.setting.getHost ()); + } else { + sb.append (this.setting.getHost ()) + .append (":") + .append (this.setting.getPort ()); + } + return sb.toString (); + } + private void initService () { log.trace ("Initializing Appium Service started..."); this.builder = new AppiumServiceBuilder (); @@ -284,7 +298,7 @@ private void setArguments () { setArgument (SUPPRESS_ADB_KILL_SERVER, android.isSuppressAdbKillServer ()); } setArgument (LOG_LEVEL, args.getLogLevel () - .toString ()); + .toString ()); setArgument (SESSION_OVERRIDE, args.isSessionOverride ()); setArgument (LOG_TIMESTAMP, args.isLogTimeStamp ()); setArgument (LOCAL_TIMEZONE, args.isLocalTimeZone ()); @@ -321,8 +335,7 @@ private void setLogFile () { if (logFile.exists ()) { Files.delete (logFile.toPath ()); } - } - catch (final IOException e) { + } catch (final IOException e) { fail (AppiumServerLogFileError.class, "Error while deleting log file!", e); } this.builder = this.builder.withLogFile (logFile); @@ -343,8 +356,7 @@ private void setNodeExe () { private void setPort () { if (this.setting.getPort () > 0) { this.builder = this.builder.usingPort (this.setting.getPort ()); - } - else { + } else { this.builder = this.builder.usingAnyFreePort (); } } diff --git a/src/test/java/com/github/wasiqb/coteafs/appium/android/DefaultTest.java b/src/test/java/com/github/wasiqb/coteafs/appium/android/DefaultTest.java index 7f6f9e1..3054c66 100644 --- a/src/test/java/com/github/wasiqb/coteafs/appium/android/DefaultTest.java +++ b/src/test/java/com/github/wasiqb/coteafs/appium/android/DefaultTest.java @@ -39,7 +39,7 @@ public class DefaultTest { */ @BeforeMethod public void setupMethod () { - this.androidDevice = new AndroidDevice (this.androidServer, "test"); + this.androidDevice = new AndroidDevice (this.androidServer, "test_browserstack"); this.androidDevice.start (); login (); @@ -53,7 +53,7 @@ public void setupMethod () { */ @BeforeClass (alwaysRun = true) public void setupTestSuite () { - this.androidServer = new AppiumServer ("android"); + this.androidServer = new AppiumServer ("browserstack"); this.androidServer.start (); } @@ -82,7 +82,7 @@ public void tearDownTestSuite () { private void login () { final LoginActivityAction login = new LoginActivityAction (this.androidDevice); login.addInputValue ("UserName", "admin") - .addInputValue ("Password", "admin") - .perform (); + .addInputValue ("Password", "admin") + .perform (); } } \ No newline at end of file diff --git a/src/test/resources/appium-config.yaml b/src/test/resources/appium-config.yaml index 3ca4e0d..b704206 100644 --- a/src/test/resources/appium-config.yaml +++ b/src/test/resources/appium-config.yaml @@ -1,10 +1,9 @@ servers: android: - ip: 127.0.0.1 + host: 0.0.0.0 port: 4723 appium_js_path: C:\Users\wasiqb\AppData\Roaming\npm\node_modules\appium\build\lib\main.js node_path: C:\Program Files\nodejs\node.exe - external: true arguments: log_level: DEBUG log_time_stamp: true @@ -12,16 +11,39 @@ servers: session_override: true android: suppress_adb_kill_server: true + browserstack: + protocol: HTTPS + host: hub-cloud.browserstack.com + cloud: true + external: true + user_name: ${env.user} + password: ${env.pass} devices: - test: + test_local: + platform_type: ANDROID + device_name: Samsung Galaxy S8 + device_version: 7.0 + app_type: HYBRID + device_type: REAL + automation_name: APPIUM + app_location: apps/android/VodQA.apk + session_timeout: 120000 + playback: + delay_before_swipe: 2 + delay_after_swipe: 1 + delay_before_tap: 2 + delay_after_tap: 1 + test_browserstack: platform_type: ANDROID - device_name: MI Redmi Note 4 + device_name: Samsung Galaxy S8 device_version: 7.0 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 playback: delay_before_swipe: 2