Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 60 #69

Merged
merged 3 commits into from
Oct 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
*/
package com.github.wasiqb.coteafs.appium.android;

import static com.github.wasiqb.coteafs.appium.utils.BatteryHealth.check;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.github.wasiqb.coteafs.appium.config.enums.AutomationType;
import com.github.wasiqb.coteafs.appium.device.DeviceActivity;

import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidBatteryInfo;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidTouchAction;

Expand All @@ -30,11 +34,7 @@
*/
public abstract class AndroidActivity
extends DeviceActivity <AndroidDriver <MobileElement>, AndroidDevice, AndroidTouchAction> {
private static final Logger log;

static {
log = LogManager.getLogger (AndroidActivity.class);
}
private static final Logger log = LogManager.getLogger (AndroidActivity.class);

/**
* @author wasiq.bhamla
Expand All @@ -51,6 +51,7 @@ public AndroidActivity (final AndroidDevice device) {
*/
@Override
public AndroidDeviceActions onDevice () {
checkBattery ();
log.trace ("Preparing to perform actions on Android device...");
return new AndroidDeviceActions (this.device);
}
Expand All @@ -61,8 +62,19 @@ public AndroidDeviceActions onDevice () {
*/
@Override
public AndroidDeviceElementActions onElement (final String name) {
checkBattery ();
final String msg = "Preparing to perform actions on Android device element [%s]...";
log.trace (String.format (msg, name));
return new AndroidDeviceElementActions (this.device, name, getElement (name));
}

private void checkBattery () {
if (this.device.getSetting ()
.getAutomationName () == AutomationType.UIAUTOMATOR2) {
final AndroidBatteryInfo battery = this.device.getDriver ()
.getBatteryInfo ();
check (battery.getState ()
.name (), battery.getLevel ());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
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;
import com.github.wasiqb.coteafs.appium.config.enums.AutomationType;
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;
Expand All @@ -31,7 +31,7 @@ public class DeviceSetting {
private AndroidDeviceSetting android;
private String appLocation;
private ApplicationType appType;
private AutomationName automationName;
private AutomationType automationName;
private Browser browser;
private boolean clearSystemFiles;
private boolean cloudApp;
Expand All @@ -54,7 +54,7 @@ public class DeviceSetting {
* @since 24-Apr-2017 9:21:26 PM
*/
public DeviceSetting () {
this.automationName = AutomationName.APPIUM;
this.automationName = AutomationType.APPIUM;
this.platformType = PlatformType.ANDROID;
this.appType = ApplicationType.NATIVE;
this.deviceType = DeviceType.REAL;
Expand Down Expand Up @@ -98,7 +98,7 @@ public ApplicationType getAppType () {
* @since 24-Apr-2017 9:15:54 PM
* @return the automationName
*/
public AutomationName getAutomationName () {
public AutomationType getAutomationName () {
return this.automationName;
}

Expand Down Expand Up @@ -282,7 +282,7 @@ public void setAppType (final ApplicationType appType) {
* @param automationName
* the automationName to set
*/
public void setAutomationName (final AutomationName automationName) {
public void setAutomationName (final AutomationType automationName) {
this.automationName = automationName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,29 @@
*/
package com.github.wasiqb.coteafs.appium.config.enums;

import io.appium.java_client.remote.AutomationName;

/**
* @author wasiq.bhamla
* @since 24-Apr-2017 9:11:30 PM
*/
public enum AutomationName {
public enum AutomationType {
/**
* Appium.
*/
APPIUM ("Appium"),
APPIUM (AutomationName.APPIUM),
/**
* Android UIAutomator2.
*/
UIAUTOMATOR2 (AutomationName.ANDROID_UIAUTOMATOR2),
/**
* XCUITest.
*/
XCUI ("XCUITest");
XCUI (AutomationName.IOS_XCUI_TEST);

private final String name;

private AutomationName (final String name) {
private AutomationType (final String name) {
this.name = name;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* 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.error;

/**
* @author wasiqb
* @since Oct 2, 2018
*/
public class NotEnoughBatteryChargeError extends CoteafsAppiumError {
private static final long serialVersionUID = -4401868812886874760L;

/**
* @author wasiqb
* @since Oct 2, 2018
* @param message
*/
public NotEnoughBatteryChargeError (final String message) {
super (message);
}

/**
* @author wasiqb
* @since Oct 2, 2018
* @param message
* @param cause
*/
public NotEnoughBatteryChargeError (final String message, final Throwable cause) {
super (message, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
*/
package com.github.wasiqb.coteafs.appium.ios;

import static com.github.wasiqb.coteafs.appium.utils.BatteryHealth.check;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.github.wasiqb.coteafs.appium.device.DeviceActivity;

import io.appium.java_client.MobileElement;
import io.appium.java_client.ios.IOSBatteryInfo;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.ios.IOSTouchAction;

Expand All @@ -30,11 +33,7 @@
*/
public abstract class IOSActivity
extends DeviceActivity <IOSDriver <MobileElement>, IOSDevice, IOSTouchAction> {
private static final Logger log;

static {
log = LogManager.getLogger (IOSActivity.class);
}
private static final Logger log = LogManager.getLogger (IOSActivity.class);

/**
* @author wasiq.bhamla
Expand All @@ -51,6 +50,7 @@ public IOSActivity (final IOSDevice device) {
*/
@Override
public IOSDeviceActions onDevice () {
checkBattery ();
log.trace ("Preparing to perform actions on iOS device...");
return new IOSDeviceActions (this.device);
}
Expand All @@ -61,8 +61,16 @@ public IOSDeviceActions onDevice () {
*/
@Override
public IOSDeviceElementActions onElement (final String name) {
checkBattery ();
final String msg = "Preparing to perform actions on iOS device element [%s]...";
log.trace (String.format (msg, name));
return new IOSDeviceElementActions (this.device, name, getElement (name));
}

private void checkBattery () {
final IOSBatteryInfo battery = this.device.getDriver ()
.getBatteryInfo ();
check (battery.getState ()
.name (), battery.getLevel ());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* 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 com.github.wasiqb.coteafs.appium.utils.ErrorUtils.fail;
import static java.text.MessageFormat.format;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.github.wasiqb.coteafs.appium.error.NotEnoughBatteryChargeError;

/**
* @author wasiqb
* @since Oct 2, 2018
*/
public final class BatteryHealth {
private static final Logger log = LogManager.getLogger (BatteryHealth.class);

/**
* @author wasiqb
* @since Oct 2, 2018
* @param state
* @param level
*/
public static void check (final String state, final double level) {
log.trace (format ("Current Battery status is [{0}] with charge level as [{1}%]...", state,
level * 100));
if (!state.equals ("CHARGING") && !state.equals ("FULL") && level < 0.2) {
fail (NotEnoughBatteryChargeError.class,
"Battery does not have enough charging, to continue, put your device on USB...");
}
}

private BatteryHealth () {
// TODO Auto-generated constructor stub
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@
* @since Nov 17, 2017 2:42:29 PM
*/
public final class ErrorUtils {
private static final Logger log;

static {
log = LogManager.getLogger (ErrorUtils.class);
}
private static final Logger log = LogManager.getLogger (ErrorUtils.class);

/**
* @author wasiq.bhamla
Expand All @@ -51,11 +47,11 @@ public static <E extends CoteafsError> void fail (final Class <E> error, final S
* @param message
* @param ex
*/
public static <E extends CoteafsError> void fail (final Class <E> error, final String message, final Throwable ex) {
public static <E extends CoteafsError> void fail (final Class <E> error, final String message,
final Throwable ex) {
try {
ErrorUtil.fail (error, message, ex);
}
catch (final CoteafsError err) {
} catch (final CoteafsError err) {
logError (err, message);
throw err;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
*/
package com.github.wasiqb.coteafs.appium.android;

import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;

import com.github.wasiqb.coteafs.appium.android.vodqa.actions.LoginActivityAction;
import com.github.wasiqb.coteafs.appium.android.vodqa.activities.MainActivity;
Expand All @@ -35,48 +34,32 @@ public class DefaultTest {

/**
* @author wasiq.bhamla
* @since Feb 2, 2018 3:37:06 PM
* @param server
* @param device
* @since 13-Apr-2017 10:10:45 PM
*/
@BeforeMethod
public void setupMethod () {
this.androidDevice = new AndroidDevice (this.androidServer, "test_browserstack");
@Parameters ({ "server", "device" })
@BeforeTest
public void setupTest (final String server, final String device) {
this.androidServer = new AppiumServer (server);
this.androidServer.start ();

this.androidDevice = new AndroidDevice (this.androidServer, device);
this.androidDevice.start ();

login ();

this.main = new MainActivity (this.androidDevice);
}

/**
* @author wasiq.bhamla
* @since 13-Apr-2017 10:10:45 PM
*/
@BeforeClass (alwaysRun = true)
public void setupTestSuite () {
this.androidServer = new AppiumServer ("browserstack");
this.androidServer.start ();
}

/**
* @author wasiq.bhamla
* @since Feb 2, 2018 3:38:26 PM
*/
@AfterMethod
public void tearDownMethod () {
if (this.androidDevice != null) {
this.androidDevice.stop ();
}
}

/**
* @author wasiq.bhamla
* @since 17-Apr-2017 3:47:41 PM
*/
@AfterClass (alwaysRun = true)
public void tearDownTestSuite () {
if (this.androidServer != null) {
this.androidServer.stop ();
}
@AfterTest
public void tearDownTest () {
this.androidDevice.stop ();
this.androidServer.stop ();
}

private void login () {
Expand Down
Loading