diff --git a/src/main/java/com/crowdar/tella/constants/FilesConstants.java b/src/main/java/com/crowdar/tella/constants/FilesConstants.java index c206766..5928d7d 100644 --- a/src/main/java/com/crowdar/tella/constants/FilesConstants.java +++ b/src/main/java/com/crowdar/tella/constants/FilesConstants.java @@ -54,4 +54,8 @@ public class FilesConstants { public static final String ADD_FOLDER = "id:fab_move_button"; public static final String NEW_FOLDER = "xpath://android.widget.TextView[@resource-id=\"org.hzontal.tella:id/fileNameTextView\" and @text=\"TellaFolder\"]"; + + public static final String SELECT_FOLDER_ICON = "xpath://android.widget.TextView[@resource-id=\"org.hzontal.tella:id/textTitle\" and @text=\"%s\"]"; + public static final String ICON_FILE_AUDIO = "xpath://android.widget.FrameLayout[@resource-id=\"org.hzontal.tella:id/attachmentImgContainer\"]"; + public static final String NEXT_BTN = "xpath://android.widget.TextView[@resource-id=\"org.hzontal.tella:id/next_btn\"]"; } diff --git a/src/main/java/com/crowdar/tella/constants/HomeConstants.java b/src/main/java/com/crowdar/tella/constants/HomeConstants.java index c0ece7a..bbc1ea9 100644 --- a/src/main/java/com/crowdar/tella/constants/HomeConstants.java +++ b/src/main/java/com/crowdar/tella/constants/HomeConstants.java @@ -18,4 +18,6 @@ public class HomeConstants { public static final String PICK_GOOGLE_ACCOUNT = "xpath:(//android.widget.LinearLayout[@resource-id=\"com.google.android.gms:id/container\"])[1]"; public static final String ALOW_GOOGLE_IN_TELLA = "xpath://android.widget.Button[@resource-id=\"com.google.android.gms:id/agree_and_share_button\"]"; + public static final String SLIDE_DELETE = "id:org.hzontal.tella:id/panic_seek"; + public static final String LBL_CONNECTIOS = "id:org.hzontal.tella:id/serversText"; } diff --git a/src/main/java/com/crowdar/tella/constants/SettingsConstants.java b/src/main/java/com/crowdar/tella/constants/SettingsConstants.java index 5d0c523..038aad6 100644 --- a/src/main/java/com/crowdar/tella/constants/SettingsConstants.java +++ b/src/main/java/com/crowdar/tella/constants/SettingsConstants.java @@ -45,7 +45,10 @@ public class SettingsConstants { public static final String DELETE_SERVER_ICON = "id:delete_server_tooltip"; public static final String HELP_INFO_TEXTVIEW = "xpath://android.widget.TextView[@text=\"%s\"]"; public static final String REMAINING_UNLOCK_ATTEMPTS = "(//android.widget.Switch[@resource-id=\"org.hzontal.tella:id/mSwitch\"])[1]"; - - + public static final String CHECKBOX_DELETE_FILE = "xpath://android.widget.CheckBox[@resource-id=\"org.hzontal.tella:id/delete_vault\"]"; + public static final String CHECKBOX_DELETE_DRAFT_SUBMITTE_DFORMS = "xpath://android.widget.CheckBox[@resource-id=\"org.hzontal.tella:id/delete_vault\"]"; + public static final String CHECKBOX_DELETE_SERVER_SETTING = "xpath://android.widget.CheckBox[@resource-id=\"org.hzontal.tella:id/delete_server_settings\"]"; + public static final String GO_BACK_BUTTON = "xpath://android.widget.ImageButton[@content-desc=\"go back\"]"; + public static final String VIEW_COUNTER_MESSAGE = "xpath://android.widget.TextView[@text=\"%s\"]"; } diff --git a/src/main/java/com/crowdar/tella/services/FilesService.java b/src/main/java/com/crowdar/tella/services/FilesService.java index 78046b3..af4ca63 100644 --- a/src/main/java/com/crowdar/tella/services/FilesService.java +++ b/src/main/java/com/crowdar/tella/services/FilesService.java @@ -232,5 +232,32 @@ public static void chooseFolder() { GenericService.commonClick(FilesConstants.PICK_FOLDER); } + /** + * Open Open a folder by passing the name + * + * @param nameFolder name of the folder to access + */ + public static void clicFolder(String nameFolder) { + MobileActionManager.waitClickable(FilesConstants.SELECT_FOLDER_ICON, nameFolder).click(); + } + + /** + * Validate that the all files folder is not empty. + * This is confirmed by audio icon. + */ + public static void validateIsNotEmptyFolderAllFile() { + clicFolder("All files"); + Assert.assertTrue(MobileActionManager.waitVisibility(FilesConstants.ICON_FILE_AUDIO).isDisplayed()); + } + + /** + * Validate that the all files folder is empty. + * This is confirmed by the empty folder icon. + */ + public static void validateIsEmptyFolderAllFile() { + clicFolder("All files"); + Assert.assertTrue(MobileActionManager.waitVisibility(FilesConstants.EMPTY_VIEW_MSG_CONTAINER).isDisplayed()); + } + } diff --git a/src/main/java/com/crowdar/tella/services/GenericService.java b/src/main/java/com/crowdar/tella/services/GenericService.java index a8e4c18..36c3393 100644 --- a/src/main/java/com/crowdar/tella/services/GenericService.java +++ b/src/main/java/com/crowdar/tella/services/GenericService.java @@ -3,6 +3,7 @@ import com.crowdar.core.actions.MobileActionManager; import com.crowdar.driver.DriverManager; import com.crowdar.tella.constants.HomeConstants; +import com.crowdar.tella.constants.SettingsConstants; import io.appium.java_client.MobileBy; import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; @@ -197,6 +198,44 @@ public static void lockScreenWaitAndUnlock(int timeMinute) { } } + /** + * Verifies whether the Tella app is currently active in the foreground. + *
+ * This method retrieves the current package name of the app in the foreground + * and checks if it matches the Tella package: {@code org.hzontal.tella}. + *
+ * + * @return {@code true} if the Tella app is currently active in the foreground; + * {@code false} if the app is closed or running in the background. + */ + public static boolean verifyActiveAppTella() { + AndroidDriver> driver = (AndroidDriver>) GenericService.getDriver(); + String currentPackage = driver.getCurrentPackage(); + + if (!"org.hzontal.tella".equals(currentPackage)) { + System.out.println("The app is closed or in the background."); + return true; + } else { + System.out.println("The app is active in the foreground."); + return true; + + } + } + + /** + * we reopen the application + */ + public static void openAppTella() { + if (MobileActionManager.isAndroid()) { + AndroidDriver> driver = (AndroidDriver>) GenericService.getDriver(); + driver.activateApp("org.hzontal.tella"); + } + } + + public static void clicBackIcon() { + MobileActionManager.waitVisibility(SettingsConstants.GO_BACK_BUTTON).click(); + } + } diff --git a/src/main/java/com/crowdar/tella/services/HomeService.java b/src/main/java/com/crowdar/tella/services/HomeService.java index b6a7b27..6bde7c0 100644 --- a/src/main/java/com/crowdar/tella/services/HomeService.java +++ b/src/main/java/com/crowdar/tella/services/HomeService.java @@ -3,22 +3,95 @@ import com.crowdar.core.actions.MobileActionManager; import com.crowdar.tella.constants.HomeConstants; import com.crowdar.tella.constants.HomeConstantsIOS; + +import io.appium.java_client.android.AndroidDriver; + + +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.PointerInput; +import org.openqa.selenium.interactions.Sequence; + import org.testng.Assert; +import java.time.Duration; +import java.util.Arrays; + + public class HomeService { public static void isHomeLoaded() { if (MobileActionManager.isAndroid()) { - MobileActionManager.waitVisibility(HomeConstants.HOME_BUTTON); - MobileActionManager.waitVisibility(HomeConstants.CAMERA_BUTTON); - MobileActionManager.waitVisibility(HomeConstants.MIC_BUTTON); - Assert.assertTrue(MobileActionManager.isVisible(HomeConstants.HOME_BUTTON), HomeConstants.VIEW_NOT_DISPLAYED_MESSAGE); - } else { + MobileActionManager.waitVisibility(HomeConstants.HOME_BUTTON); + MobileActionManager.waitVisibility(HomeConstants.CAMERA_BUTTON); + MobileActionManager.waitVisibility(HomeConstants.MIC_BUTTON); + Assert.assertTrue(MobileActionManager.isVisible(HomeConstants.HOME_BUTTON), HomeConstants.VIEW_NOT_DISPLAYED_MESSAGE); + } else { MobileActionManager.waitVisibility(HomeConstantsIOS.HOME_BUTTON); MobileActionManager.waitVisibility(HomeConstantsIOS.CAMERA_BUTTON); MobileActionManager.waitVisibility(HomeConstantsIOS.MIC_BUTTON); Assert.assertTrue(MobileActionManager.isVisible(HomeConstantsIOS.HOME_BUTTON), HomeConstantsIOS.VIEW_NOT_DISPLAYED_MESSAGE); } + } + + public static void verifySwipeDeleteButtonIsVisibleOnHomeScreen() { + if (MobileActionManager.isAndroid()) { + Assert.assertTrue(MobileActionManager.waitVisibility(HomeConstants.SLIDE_DELETE).isDisplayed()); } + } + + /** + * Simula el movimiento del dedo para arrastrar un SeekBar hasta su posición final (100%). + * + * @throws org.openqa.selenium.NoSuchElementException si no se encuentra el SeekBar por ID. + */ + public static void moveFingerSeekBarToEnd() { + //Validamos que se encuentre y este visible + if (MobileActionManager.waitVisibility(HomeConstants.SLIDE_DELETE).isDisplayed()) { + AndroidDriver> driver = (AndroidDriver>) GenericService.getDriver(); + //Aqui recuperamos parte de la cadena, pero obtener el Id del elemento + WebElement seekBar = MobileActionManager.getElement(HomeConstants.SLIDE_DELETE); + //driver.findElement(By.id(HomeConstants.SLIDE_DELETE.split(":")[1])); + + int startX = seekBar.getLocation().getX(); + int width = seekBar.getSize().getWidth(); + int endX = startX + width - 10; + + // Simula el movimiento del dedo al desplazar el SeekBar + PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger"); + Sequence drag = new Sequence(finger, 1); + + int thumbX = 117; // Posición inicial del thumb (ajustado manualmente según el dispositivo) + int thumbY = 1850; // Altura del SeekBar en pantalla + + // Presionar el thumb y mover hacia la derecha + drag.addAction(finger.createPointerMove(Duration.ZERO, PointerInput.Origin.viewport(), thumbX, thumbY)); + drag.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg())); + drag.addAction(finger.createPointerMove(Duration.ofMillis(600), PointerInput.Origin.viewport(), endX, thumbY)); + drag.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg())); + driver.perform(Arrays.asList(drag)); + } + } + + public static void isConnection() { + isHomeLoaded(); + Assert.assertTrue(MobileActionManager.waitVisibility(HomeConstants.LBL_CONNECTIOS).isDisplayed()); + } + + public static void isNotConnection() { + isHomeLoaded(); + try{ + //Hacemos falla al proposito para indicar que el LBl de conexion ya no esta. + // Indicando que la conexion desaparecio + boolean flag = MobileActionManager.getElement(HomeConstants.LBL_CONNECTIOS).isDisplayed(); + Assert.assertFalse(flag); + } catch (Exception e) { + System.out.println("The user is no longer connected to the Tella web server."); + } + } + + public static void clicHomeButton() { + MobileActionManager.waitClickable(HomeConstants.HOME_BUTTON).click(); + } + } diff --git a/src/main/java/com/crowdar/tella/services/ServersService.java b/src/main/java/com/crowdar/tella/services/ServersService.java index dff7e47..0182c49 100644 --- a/src/main/java/com/crowdar/tella/services/ServersService.java +++ b/src/main/java/com/crowdar/tella/services/ServersService.java @@ -89,8 +89,6 @@ public static void okServerButton() { } - - public static void viewSettingServer(String server) { if (MobileActionManager.isPresent(ServersConstants.URL_INPUT)) { Assert.assertTrue(ActionManager.isPresent(ServersConstants.URL_INPUT)); @@ -161,7 +159,7 @@ public static void connectToTellaServer() { MobileActionManager.setInput(ServersConstants.TELLA_PASS_INPUT, PropertyManager.getProperty("tellapass")); MobileActionManager.click(ServersConstants.TEXT_SERVER_BUTTON, "Log in"); MobileActionManager.click(ServersConstants.SAVE_BUTTON); - MobileActionManager.click(ServersConstants.TEXT_SERVER_BUTTON, "OK"); + MobileActionManager.click(ServersConstants.TEXT_SERVER_BUTTON, "GO TO REPORTS"); MobileActionManager.click(ServersConstants.BACK_BUTTON); MobileActionManager.click(ServersConstants.BACK_BUTTON); } @@ -220,4 +218,29 @@ public static void googleDrive() { } + + public static void clicNextBtn() { + //Como el boton esta abajo de la pantalla, tenemos q escroliar hasta el final + // por ello utilizamos PointerInput para simular el movimiento del dedo + AndroidDriver> driver = (AndroidDriver>) GenericService.getDriver(); + + Dimension size = driver.manage().window().getSize(); + int width = size.width / 2; + + // Cambiar: empezar desde abajo y mover hacia arriba + int startY = (int) (size.height * 0.70); // más abajo + int endY = (int) (size.height * 0.30); // más arriba + + PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger"); + Sequence swipe = new Sequence(finger, 1); + swipe.addAction(finger.createPointerMove(Duration.ZERO, PointerInput.Origin.viewport(), width, startY)); + swipe.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg())); + swipe.addAction(finger.createPointerMove(Duration.ofMillis(300), PointerInput.Origin.viewport(), width, endY)); + swipe.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg())); + driver.perform(List.of(swipe)); + + MobileActionManager.waitPresence(FilesConstants.NEXT_BTN).click(); + + } + } \ No newline at end of file diff --git a/src/main/java/com/crowdar/tella/services/SettingsService.java b/src/main/java/com/crowdar/tella/services/SettingsService.java index 751a2cf..8634121 100644 --- a/src/main/java/com/crowdar/tella/services/SettingsService.java +++ b/src/main/java/com/crowdar/tella/services/SettingsService.java @@ -17,6 +17,7 @@ import static com.crowdar.driver.DriverManager.*; import static org.bouncycastle.oer.its.ieee1609dot2.basetypes.Duration.seconds; +import static org.mozilla.javascript.Context.exit; public class SettingsService { @@ -292,4 +293,40 @@ private static int selectMinutetime(String waitTime) { return 0; } } + + public static void selectedDeleteCheck(String quickDeleteCheck) { + String selectDeleteCheck = ""; + switch (quickDeleteCheck) { + case "Delete files": + selectDeleteCheck = SettingsConstants.CHECKBOX_DELETE_FILE; + break; + case "Delete draft and submitted forms": + selectDeleteCheck = SettingsConstants.CHECKBOX_DELETE_DRAFT_SUBMITTE_DFORMS; + break; + case "Delete server settings": + selectDeleteCheck = SettingsConstants.CHECKBOX_DELETE_SERVER_SETTING; + break; + default: + System.out.println("[WARNING] Opcion invalida"); + } + MobileActionManager.waitVisibility(selectDeleteCheck).click(); + + + } + + public static void goToHomeFromSecurityPage() { + //La pagina de seguridad esta a dos paginas de la home, por ello simulo dos tab + MobileActionManager.waitVisibility(SettingsConstants.GO_BACK_BUTTON).click(); + MobileActionManager.waitVisibility(SettingsConstants.GO_BACK_BUTTON).click(); + } + + public static void viewCounterMessage(String message) { + Assert.assertTrue(MobileActionManager.waitVisibility(SettingsConstants.VIEW_COUNTER_MESSAGE, message).isDisplayed()); + } + + public static void theAppIsClosed() throws InterruptedException { + //Esperamos por el cierre de la app y validamos que se haya cerrado + Thread.sleep(6000); + Assert.assertTrue(GenericService.verifyActiveAppTella()); + } } diff --git a/src/main/java/com/crowdar/tella/services/UnlockService.java b/src/main/java/com/crowdar/tella/services/UnlockService.java index 10945a5..d50df65 100644 --- a/src/main/java/com/crowdar/tella/services/UnlockService.java +++ b/src/main/java/com/crowdar/tella/services/UnlockService.java @@ -36,9 +36,9 @@ public static void isViewLoadedReopenAppWithPassword() { public static void isViewLoadedReopenAppWithPin() { if (MobileActionManager.isAndroid()) { - MobileActionManager.waitVisibility(LockUnlockConstants.REOPEN_APP_PIN_VERIFICATION); - MobileActionManager.click(LockUnlockConstants.REOPEN_APP_PIN_VERIFICATION); - } else { + MobileActionManager.waitVisibility(LockUnlockConstants.REOPEN_APP_PIN_VERIFICATION); + MobileActionManager.click(LockUnlockConstants.REOPEN_APP_PIN_VERIFICATION); + } else { GenericService.commonClick(LockUnlockConstantsIOS.REOPEN_APP_PIN_VERIFICATION); } } @@ -59,7 +59,7 @@ public static void enterPassword(String password) throws InterruptedException { MobileActionManager.setInput(LockUnlockConstants.PASSWORD_INPUT, password); EventFiringWebDriver driver = DriverManager.getDriverInstance(); driver.getKeyboard().sendKeys(Keys.ENTER); - }else{ + } else { Thread.sleep(1000); MobileActionManager.waitVisibility(LockUnlockConstantsIOS.PASSWORD_INPUT); MobileActionManager.waitClickable(LockUnlockConstantsIOS.PASSWORD_INPUT); @@ -132,11 +132,11 @@ public static void setPin(String pin) { } } - public static void enterPin(String pin) { + public static void enterPin(String pin) { setPin(pin); if (MobileActionManager.isAndroid()) { MobileActionManager.click(LockUnlockConstants.PIN_OK_BUTTON); - }else { + } else { GenericService.commonClick(LockUnlockConstantsIOS.PIN_OK_BUTTON); } } @@ -203,5 +203,7 @@ public static void reopenTheApp() throws InterruptedException { driver.activateApp("org.wearehorizontal.tella"); // Usa el package name de tu app para traerla de vuelta al frente -}}} + } + } +} diff --git a/src/main/java/com/crowdar/tella/steps/SettingsSteps.java b/src/main/java/com/crowdar/tella/steps/SettingsSteps.java index ba1bc0a..66ac9cd 100644 --- a/src/main/java/com/crowdar/tella/steps/SettingsSteps.java +++ b/src/main/java/com/crowdar/tella/steps/SettingsSteps.java @@ -4,9 +4,7 @@ import com.crowdar.core.actions.MobileActionManager; import com.crowdar.driver.DriverManager; import com.crowdar.tella.constants.SettingsConstants; -import com.crowdar.tella.services.HomeService; -import com.crowdar.tella.services.SettingsService; -import com.crowdar.tella.services.UnlockService; +import com.crowdar.tella.services.*; import io.cucumber.java.en.*; import org.openqa.selenium.WebDriver; import org.openqa.selenium.support.ui.WebDriverWait; @@ -233,4 +231,101 @@ public void theScreenLockShouldBeDisplayedInTheApp() { public void theUserLocksTheDeviceScreenWaitsForTheConfiguredTimeTimeoutAndUnlocksIt(String timeout) throws InterruptedException { SettingsService.pressBlockInAndroid(timeout); } + + @And("select check box (.*)") + public void selectCheckBox(String quickDeleteCheck) { + SettingsService.selectedDeleteCheck(quickDeleteCheck); + } + + @And("Go to the Tella homepage from Security Page") + public void goToTheTellaHomepageFromSecurityPage() { + SettingsService.goToHomeFromSecurityPage(); + HomeService.isHomeLoaded(); + } + + @And("verify slide {string} button is present") + public void verifySlideButtonIsPresent(String DELETE) { + HomeService.verifySwipeDeleteButtonIsVisibleOnHomeScreen(); + } + + @And("taps slide {string} button") + public void tapsSlideButton(String arg0) { + HomeService.moveFingerSeekBarToEnd(); + } + + @And("view counter message (.*)") + public void viewCounterMessage(String message) { + SettingsService.viewCounterMessage(message); + } + + @And("the app is closed") + public void theAppIsClosed() throws InterruptedException { + SettingsService.theAppIsClosed(); + + } + + @And("open Tella application again") + public void openTellaApplicationAgain() { + GenericService.openAppTella(); + } + + @And("set security code valid") + public void setSecurityCodeValid() throws InterruptedException { + UnlockService.enterPassword(PropertyManager.getProperty("password")); + } + + @Given("the user records an audio file") + public void theUserRecordsAnAudioFile() throws InterruptedException { + //Volvemos a la home para grabar un audio + SettingsService.goToHomeFromSecurityPage(); + HomeService.isHomeLoaded(); + //Inicia la grabacion + AudioService.clickRecOption(); + AudioService.clickMicrophoneIcon(); + AudioService.clickMicrophoneIcon(); + AudioService.validateAprovalMessage("The audio recording was saved to your Tella files"); + //Volvemos a la Home + HomeService.clicHomeButton(); + //Validamos el archivo de audio + FilesService.validateIsNotEmptyFolderAllFile(); + GenericService.clicBackIcon(); + + //Volvemos a Settings + SettingsService.clickSettingsIcon(); + SettingsService.clickCategory("Security"); + + } + + @Then("that files were deleted") + public void thatFilesWereDeleted() { + FilesService.validateIsEmptyFolderAllFile(); + } + + @Given("The user has already connected to the Tella web server") + public void theUserHasAlreadyConnectedToTheTellaWebServer() { + //Volvemos a la home para configuracion de conexion + SettingsService.goToHomeFromSecurityPage(); + HomeService.isHomeLoaded(); + + //Iniciamos la configuracion de conexion + SettingsService.clickSettingsIcon(); + SettingsService.clickCategory("Servers"); + ServersService.clickPlusButton(); + ServersService.selectButton("Tella Web"); + ServersService.clicNextBtn(); + ServersService.inputServerUrl("https://tella.world/p/server-project-crowdar"); + ServersService.pressButton("Next"); + ServersService.connectToTellaServer(); + + //Verificamos el forms de conexion + HomeService.isConnection(); + //Volvemos a Settings + SettingsService.clickSettingsIcon(); + SettingsService.clickCategory("Security"); + } + + @Then("The user is no longer connected to the Tella web server.") + public void theUserIsNoLongerConnectedToTheTellaWebServer() { + HomeService.isNotConnection(); + } } diff --git a/src/test/resources/features/Settings/Security.feature b/src/test/resources/features/Settings/Security.feature index ae26922..13c6d16 100644 --- a/src/test/resources/features/Settings/Security.feature +++ b/src/test/resources/features/Settings/Security.feature @@ -33,7 +33,7 @@ Feature: Security And taps "next" button Then "Your lock has been changed" message is shown - @Smoke @SmokeManual @LockTimeout @LockFlow @TestAngi + @Smoke @SmokeManual @LockTimeout @LockFlow #@TestAngi Scenario Outline: Security - Lock Timeout Given the user sets the app lock timeout to