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

feat(java): ✨ added android specific critical actions #975

Merged
merged 2 commits into from
Jan 22, 2025
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
2 changes: 1 addition & 1 deletion core-java/checkstyles/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!--
~ MIT License
~
~ Copyright (c) 2022 Wasiq Bhamla
~ Copyright (c) 2022 Boyka Framework
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions core-java/checkstyles/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!--
~ MIT License
~
~ Copyright (c) 2022 Wasiq Bhamla
~ Copyright (c) 2022 Boyka Framework
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -145,7 +145,7 @@
</module>
<!-- Validate whitespace around Generics (angle brackets) per typical conventions
http://checkstyle.sourceforge.net/config_whitespace.html#GenericWhitespace -->
<!-- <module name="GenericWhitespace"/>-->
<!-- <module name="GenericWhitespace"/>-->

<!-- ##### Blank line requirements ##### -->
<module name="EmptyLineSeparator">
Expand Down
2 changes: 1 addition & 1 deletion core-java/code-formatter/boyka-formatter.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!--
~ MIT License
~
~ Copyright (c) 2023, Wasiq Bhamla
~ Copyright (c) 2024, Boyka Framework
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion core-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!--
~ MIT License
~
~ Copyright (c) 2022 Wasiq Bhamla
~ Copyright (c) 2022 Boyka Framework
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 3 additions & 3 deletions core-java/setting/settings.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!--
~ MIT License
~
~ Copyright (c) 2022 Wasiq Bhamla
~ Copyright (c) 2022 Boyka Framework
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
Expand All @@ -15,8 +15,8 @@
-->

<settings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>
<profile>
<id>central</id>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024, Wasiq Bhamla
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024, Wasiq Bhamla
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024, Wasiq Bhamla
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024, Wasiq Bhamla
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024, Wasiq Bhamla
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -16,6 +16,8 @@

package io.github.boykaframework.actions.device;

import static com.google.common.truth.Truth.assertWithMessage;
import static io.github.boykaframework.actions.CommonActions.getDriverAttribute;
import static io.github.boykaframework.actions.CommonActions.performDriverAction;
import static io.github.boykaframework.enums.ListenerType.ANDROID_DEVICE_ACTION;
import static io.github.boykaframework.enums.Message.ACTION_NOT_SUPPORTED_ON_PLATFORM;
Expand All @@ -25,12 +27,19 @@
import static java.util.Optional.ofNullable;
import static org.apache.logging.log4j.LogManager.getLogger;

import java.io.File;
import java.io.IOException;

import com.google.common.truth.StringSubject;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.HasNotifications;
import io.appium.java_client.android.nativekey.AndroidKey;
import io.appium.java_client.android.nativekey.KeyEvent;
import io.appium.java_client.clipboard.HasClipboard;
import io.github.boykaframework.actions.interfaces.device.IAndroidDeviceActions;
import io.github.boykaframework.actions.interfaces.listeners.device.IAndroidDeviceActionsListener;
import org.apache.logging.log4j.Logger;
import org.openqa.selenium.WebDriverException;

/**
* Handles all Android device specific actions.
Expand All @@ -57,16 +66,93 @@ private AndroidDeviceActions () {
this.listener = getSession ().getListener (ANDROID_DEVICE_ACTION);
}

@Override
public String getClipboardText () {
LOGGER.traceEntry ();
isActionSupported ();
LOGGER.info ("Getting the Clipboard text from Android device...");
ofNullable (this.listener).ifPresent (IAndroidDeviceActionsListener::onGetClipboardText);
return getClipboard ();
}

@Override
public void openNotification () {
LOGGER.traceEntry ();
isActionSupported ();
LOGGER.info ("Opening Notification panel on the Android device...");
ofNullable (this.listener).ifPresent (IAndroidDeviceActionsListener::onOpenNotification);
performDriverAction (HasNotifications::openNotifications);
LOGGER.traceExit ();
}

@Override
public void pressKey (final AndroidKey key) {
LOGGER.traceEntry ();
final var platform = getSession ().getPlatformType ();
if (platform != ANDROID) {
throwError (ACTION_NOT_SUPPORTED_ON_PLATFORM, "Press key", platform);
}
isActionSupported ();
LOGGER.info ("Pressing key [{}] on Android device...", key);
ofNullable (this.listener).ifPresent (l -> l.onPressKey (key));
performDriverAction ((AndroidDriver d) -> d.pressKey (new KeyEvent ().withKey (key)));
LOGGER.traceExit ();
}

@Override
public byte[] pullFile (final String targetFile) {
LOGGER.traceEntry ();
isActionSupported ();
LOGGER.info ("Pulling file [{}] from Android device...", targetFile);
ofNullable (this.listener).ifPresent (l -> l.onPullFile (targetFile));
return getDriverAttribute ((final AndroidDriver d) -> {
try {
return d.pullFile (targetFile);
} catch (final WebDriverException e) {
return null;
}
}, null);
}

@Override
public boolean putFile (final File sourceFile, final String destinationPath) {
LOGGER.traceEntry ();
isActionSupported ();
LOGGER.info ("Putting file [{}] on Android device path [{}]...", sourceFile.getName (), destinationPath);
ofNullable (this.listener).ifPresent (l -> l.onPutFile (sourceFile, destinationPath));
return getDriverAttribute ((final AndroidDriver d) -> {
try {
d.pushFile (destinationPath, sourceFile);
return true;
} catch (final IOException e) {
return false;
}
}, false);
}

@Override
public void setClipboardText (final String text) {
LOGGER.traceEntry ();
isActionSupported ();
LOGGER.info ("Setting the Clipboard text [{}] on the Android device...", text);
ofNullable (this.listener).ifPresent (l -> l.onSetClipboardText (text));
performDriverAction ((AndroidDriver d) -> d.setClipboardText (text));
LOGGER.traceExit ();
}

@Override
public StringSubject verifyClipboardText () {
LOGGER.traceEntry ();
isActionSupported ();
LOGGER.info ("Verifying the Clipboard text from Android device...");
ofNullable (this.listener).ifPresent (IAndroidDeviceActionsListener::onVerifyClipboardText);
return assertWithMessage ("Clipboard Text").that (getClipboard ());
}

private String getClipboard () {
return getDriverAttribute (HasClipboard::getClipboardText, null);
}

private void isActionSupported () {
final var platform = getSession ().getPlatformType ();
if (platform != ANDROID) {
throwError (ACTION_NOT_SUPPORTED_ON_PLATFORM, "Press key", platform);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024, Wasiq Bhamla
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024, Wasiq Bhamla
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024, Wasiq Bhamla
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024, Wasiq Bhamla
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024, Wasiq Bhamla
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024, Wasiq Bhamla
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024, Wasiq Bhamla
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024, Wasiq Bhamla
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024, Wasiq Bhamla
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024, Wasiq Bhamla
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024, Wasiq Bhamla
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024, Wasiq Bhamla
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024, Wasiq Bhamla
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024, Wasiq Bhamla
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024, Wasiq Bhamla
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024, Wasiq Bhamla
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024, Wasiq Bhamla
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2024, Wasiq Bhamla
* Copyright (c) 2024, Boyka Framework
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
Loading
Loading