Skip to content

Commit

Permalink
Bug fix and dependency upgrade (#90)
Browse files Browse the repository at this point in the history
* Added funding option (#89)

* Updated dependencies for Appium, Selenium and other supporting libraries. (#88)

* Updated outdated dependencies.
  • Loading branch information
WasiqB authored Aug 26, 2019
1 parent 723cde2 commit b2ecca5
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 55 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
patreon: wasiqb
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
/.project
/bin/
/screenshots/
/videos/
/videos/
/.idea/
*.iml
.DS_Store
18 changes: 9 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>appium</artifactId>
Expand All @@ -11,7 +11,7 @@
<parent>
<groupId>com.github.wasiqb.coteafs</groupId>
<artifactId>parent</artifactId>
<version>2.1.0</version>
<version>2.2.0</version>
</parent>

<scm>
Expand All @@ -31,12 +31,12 @@
</ciManagement>

<properties>
<appium-version>6.1.0</appium-version>
<selenium-version>3.141.5</selenium-version>
<coteafs.config.version>1.7.0</coteafs.config.version>
<coteafs.error.version>1.6.0</coteafs.error.version>
<coteafs.logger.version>1.7.0</coteafs.logger.version>
<commons.text.version>1.6</commons.text.version>
<appium-version>7.2.0</appium-version>
<selenium-version>3.141.59</selenium-version>
<coteafs.config.version>1.8.0</coteafs.config.version>
<coteafs.error.version>1.7.0</coteafs.error.version>
<coteafs.logger.version>1.8.0</coteafs.logger.version>
<commons.text.version>1.7</commons.text.version>
<coteafs.listeners.version>1.2.0</coteafs.listeners.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
* @since 12-Apr-2017 9:38:38 PM
*/
public abstract class Device <D extends AppiumDriver <MobileElement>, T extends TouchAction <T>> {
private static final Logger LOG = LogManager.getLogger (Device.class);
private static final Logger LOG = LogManager.getLogger (Device.class);

protected DesiredCapabilities capabilities;
protected D driver;
Expand Down Expand Up @@ -268,7 +268,7 @@ private D init (final URL url, final Capabilities capability) {
final Constructor <D> ctor = cls.getDeclaredConstructor (argTypes);
return ctor.newInstance (url, capability);
}
catch (NoSuchMethodException | SecurityException | InstantiationException
catch (final NoSuchMethodException | SecurityException | InstantiationException
| IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
fail (DeviceDriverInitializationFailedError.class,
"Error occured while initializing device driver.", e);
Expand Down Expand Up @@ -424,12 +424,13 @@ private <X extends BaseStartScreenRecordingOptions <X>> void startRecord (
}
}

private void stopRecord (final CanRecordScreen screen) {
private <X extends BaseStopScreenRecordingOptions <X>> void stopRecord (
final CanRecordScreen screen) {
final RecordSetting record = this.setting.getPlayback ()
.getRecord ();
if (record.isEnabled () && !this.setting.isCloudApp ()) {
LOG.info ("Stopping video recording...");
final String content = screen.stopRecordingScreen (stopRecordSetting ());
final String content = screen. <X>stopRecordingScreen (stopRecordSetting ());
saveRecording (content, record);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static com.github.wasiqb.coteafs.appium.constants.ErrorMessage.SERVER_STOPPED;
import static com.github.wasiqb.coteafs.appium.utils.ErrorUtils.fail;
import static java.lang.String.format;
import static java.time.Duration.ofSeconds;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -57,8 +58,8 @@ public class DeviceActions <D extends AppiumDriver <MobileElement>, E extends De
/**
* @author wasiq.bhamla
* @since Jul 22, 2017 11:03:48 PM
* @param srcFiler
* @param path
* @param source
* @param destination
*/
private static void copyFile (final File source, final String destination) {
try {
Expand Down Expand Up @@ -87,7 +88,8 @@ public DeviceActions (final E device, final T actions) {
this.actions = actions;
this.driver = this.device.getDriver ();
this.setting = device.setting.getPlayback ();
this.wait = new WebDriverWait (this.driver, this.setting.getWaitForElementUntil ());
this.wait = new WebDriverWait (this.driver,
ofSeconds (this.setting.getWaitForElementUntil ()).getSeconds ());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static com.github.wasiqb.coteafs.appium.constants.ErrorMessage.SERVER_STOPPED;
import static com.github.wasiqb.coteafs.appium.utils.ErrorUtils.fail;
import static java.time.Duration.ofSeconds;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfAllElementsLocatedBy;

import java.util.HashMap;
Expand Down Expand Up @@ -57,7 +58,7 @@
*/
public abstract class DeviceActivity <D extends AppiumDriver <MobileElement>,
E extends Device <D, T>, T extends TouchAction <T>> {
private static final Logger log = LogManager.getLogger (DeviceActivity.class);
private static final Logger log = LogManager.getLogger (DeviceActivity.class);

protected final AutomationType automation;
protected final E device;
Expand All @@ -83,7 +84,7 @@ public DeviceActivity (final E device, final T touch) {
this.platform = this.deviceSetting.getPlatformType ();
this.playSetting = this.deviceSetting.getPlayback ();
this.wait = new WebDriverWait (device.getDriver (),
this.playSetting.getWaitForElementUntil ());
ofSeconds (this.playSetting.getWaitForElementUntil ()).getSeconds ());
}

/**
Expand Down Expand Up @@ -205,8 +206,7 @@ private MobileElement findElements (final DeviceElement element) {
}

private DeviceElement getDeviceElement (final String name) {
if (this.deviceElements.containsKey (name))
return this.deviceElements.get (name);
if (this.deviceElements.containsKey (name)) return this.deviceElements.get (name);
final String msg = "DeviceElement with name [%s] not found.";
fail (DeviceElementNameNotFoundError.class, String.format (msg, name));
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
* @since 12-Apr-2017 5:17:22 PM
*/
public final class AppiumServer {
private static final Logger log = LogManager.getLogger (AppiumServer.class);
private static final Logger log = LogManager.getLogger (AppiumServer.class);

private AppiumServiceBuilder builder;
private DesiredCapabilities capabilities;
Expand All @@ -88,10 +88,10 @@ 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);
.withKey (COTEAFS_CONFIG_KEY)
.withDefault (COTEAFS_CONFIG_DEFAULT_FILE)
.load (AppiumSetting.class)
.getServer (name);
if (!this.setting.isExternal () && !this.setting.isCloud ()) {
initService ();
buildCapabilities ();
Expand All @@ -106,12 +106,12 @@ public AppiumServer (final String name) {
*/
public URL getServiceUrl () {
log.trace ("Fetching Appium Service URL...");
if (!this.setting.isExternal () && !this.setting.isCloud ())
return this.service.getUrl ();
if (!this.setting.isExternal () && !this.setting.isCloud ()) return this.service.getUrl ();
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);
}
Expand All @@ -124,17 +124,17 @@ public URL getServiceUrl () {
* @return isRunning
*/
public boolean isRunning () {
if (this.setting.isCloud ())
return true;
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.getHost (),
this.setting.getPort ());
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;
Expand All @@ -147,18 +147,29 @@ public boolean isRunning () {
public void start () {
log.trace ("Starting Appium Service...");
if (!this.setting.isExternal () && !this.setting.isCloud ()) {
boolean failure = false;
this.service = AppiumDriverLocalService.buildService (this.builder);
try {
this.service.start ();
} catch (final AppiumServerHasNotBeenStartedLocallyException e) {
}
catch (final AppiumServerHasNotBeenStartedLocallyException e) {
failure = true;
fail (AppiumServerNotStartingError.class,
"Error occured while starting Appium server", e);
} catch (final Exception e) {
"Error occured while starting Appium server", e);
}
catch (final Exception e) {
failure = true;
fail (AppiumServerAlreadyRunningError.class, "Appium server is running already.",
e);
e);
}
finally {
if (failure) {
stop ();
}
}
log.trace ("Appium Service Started...");
} else {
}
else {
if (isRunning ()) {
log.trace ("Appium Service is already running...");
}
Expand All @@ -174,13 +185,15 @@ public void stop () {
if (!this.setting.isExternal () && !this.setting.isCloud ()) {
try {
this.service.stop ();
} catch (final Exception e) {
}
catch (final Exception e) {
fail (AppiumServerNotStoppingError.class,
"Error occured while stopping the server.", e);
"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...");
}
}
Expand All @@ -192,19 +205,19 @@ public void stop () {
private void buildCapabilities () {
log.trace ("Building Appium Capabilities started...");
setCapability (MobileCapabilityType.NO_RESET, Boolean.toString (this.setting.isNoReset ()),
this.capabilities);
this.capabilities);
setCapability (MobileCapabilityType.FULL_RESET,
Boolean.toString (this.setting.isFullReset ()), this.capabilities);
Boolean.toString (this.setting.isFullReset ()), this.capabilities);
setCapability (MobileCapabilityType.NEW_COMMAND_TIMEOUT,
Integer.toString (this.setting.getSessionTimeout ()), this.capabilities);
Integer.toString (this.setting.getSessionTimeout ()), this.capabilities);
log.trace ("Building Appium Capabilities completed...");
}

private void buildService () {
log.trace ("Building Appium Service started...");
checkServerConfigParams ("IP Host Address", this.setting.getHost ());
this.builder = this.builder.withIPAddress (this.setting.getHost ())
.withStartUpTimeOut (this.setting.getStartUpTimeOutSeconds (), TimeUnit.SECONDS);
.withStartUpTimeOut (this.setting.getStartUpTimeOutSeconds (), TimeUnit.SECONDS);
setPort ();
setLogFile ();
setAppiumJS ();
Expand All @@ -217,21 +230,22 @@ private void buildService () {

private String getUrl () {
final StringBuilder sb = new StringBuilder (this.setting.getProtocol ()
.getName ()).append ("://");
.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 {
.append (":")
.append (this.setting.getPassword ())
.append ("@")
.append (this.setting.getHost ());
}
else {
sb.append (this.setting.getHost ());
}
if (this.setting.getPort () > 0) {
sb.append (":")
.append (this.setting.getPort ());
.append (this.setting.getPort ());
}
return sb.toString ();
}
Expand Down Expand Up @@ -300,7 +314,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 ());
Expand Down Expand Up @@ -337,7 +351,8 @@ 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);
Expand All @@ -358,7 +373,8 @@ 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 ();
}
}
Expand Down

0 comments on commit b2ecca5

Please sign in to comment.