Skip to content

Commit

Permalink
Merge branch 'feature/selenium4' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
vertigo17 authored Apr 3, 2024
2 parents dd32113 + fce135c commit 03a311f
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 163 deletions.
6 changes: 4 additions & 2 deletions source/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@
<!-- <groovy-dateutil.version>3.0.11</groovy-dateutil.version>-->
<groovy-sandbox.version>1.19</groovy-sandbox.version>
<!-- Appium/Selenium scope Version -->
<appium.version>7.2.0</appium.version>
<selenium.version>3.141.59</selenium.version>
<!-- <appium.version>7.2.0</appium.version>-->
<appium.version>8.5.1</appium.version>
<!-- <selenium.version>3.141.59</selenium.version>-->
<selenium.version>4.13.0</selenium.version>
<jna.version>4.1.0</jna.version>
<!-- quartz -->
<quartz.version>2.3.2</quartz.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public void quit() {
driver.quit();
}
if (appiumDriver != null) {
appiumDriver.closeApp();
appiumDriver.close();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ public TestCaseExecution executeTestCase(TestCaseExecution execution) throws Cer
if (execution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI) && !execution.getManualExecution().equals("Y")) {
try {
Capabilities caps = this.robotServerService.getUsedCapabilities(execution.getSession());
execution.setVersion(caps.getVersion());
execution.setPlatform(caps.getPlatform().toString());
execution.setVersion(caps.getBrowserVersion());
execution.setPlatform(caps.getPlatformName().toString());
} catch (Exception ex) {
LOG.error("{}Exception on Selenium getting Used Capabilities.", logPrefix, ex);
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.cerberus.core.engine.execution.video;

import com.google.common.collect.Lists;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import org.apache.commons.io.FileUtils;
import org.cerberus.core.crud.entity.Application;
Expand Down Expand Up @@ -93,7 +92,7 @@ public void beginRecordVideo() {
@Override
public void endRecordVideo() {

AppiumDriver driver = null;
AndroidDriver driver = null;
try {
String applicationType = testCaseExecution.getAppTypeEngine();

Expand All @@ -107,8 +106,8 @@ public void endRecordVideo() {

String test = testCaseExecution.getTest();
String testCase = testCaseExecution.getTestCase();
driver = session.getAppiumDriver();

driver = (AndroidDriver) session.getAppiumDriver();
List<String> videosPath = new LinkedList<>();

for (int i = 0; i < cpt; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.primitives.Ints;
import com.jayway.jsonpath.PathNotFoundException;
import java.time.Duration;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.cerberus.core.crud.entity.AppService;
Expand Down Expand Up @@ -1592,7 +1593,7 @@ private MessageEvent verifyUrl(TestCaseExecution tCExecution, String value1) thr
try {
LOG.debug("Before wait: {}", System.currentTimeMillis());
WebDriverWait wait = new WebDriverWait(tCExecution.getSession().getDriver(),
TimeUnit.MILLISECONDS.toSeconds(tCExecution.getSession().getCerberus_selenium_wait_element()));
Duration.ofMillis(tCExecution.getSession().getCerberus_selenium_wait_element()));

//Wait until the url is the expected one
wait.until(new Function<WebDriver, Boolean>() {
Expand Down Expand Up @@ -1638,7 +1639,7 @@ private MessageEvent verifyTitle(TestCaseExecution tCExecution, String title, St
try {
LOG.debug("Before wait {}", System.currentTimeMillis());
WebDriverWait wait = new WebDriverWait(tCExecution.getSession().getDriver(),
TimeUnit.MILLISECONDS.toSeconds(tCExecution.getSession().getCerberus_selenium_wait_element()));
Duration.ofMillis(tCExecution.getSession().getCerberus_selenium_wait_element()));

//Wait until the title is the expected one
wait.until(new Function<WebDriver, Boolean>() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
/**
* Cerberus Copyright (C) 2013 - 2017 cerberustesting
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* <p>
* This file is part of Cerberus.
*
* <p>
* Cerberus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* <p>
* Cerberus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* <p>
* You should have received a copy of the GNU General Public License
* along with Cerberus. If not, see <http://www.gnu.org/licenses/>.
*/
package org.cerberus.core.service.appium.impl;

import io.appium.java_client.PerformsTouchActions;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.nativekey.AndroidKey;
Expand Down Expand Up @@ -100,7 +101,7 @@ public MessageEvent keyPress(Session session, String keyName) {
@Override
public MessageEvent hideKeyboard(Session session) {
try {
session.getAppiumDriver().hideKeyboard();
// session.getAppiumDriver().hideKeyboard(); #FIXME SELENIUM
return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_HIDEKEYBOARD);
} catch (Exception e) {
// Instead of http://stackoverflow.com/questions/35030794/soft-keyboard-not-present-cannot-hide-keyboard-appium-android?answertab=votes#tab-top
Expand All @@ -125,7 +126,7 @@ public MessageEvent swipe(Session session, SwipeAction action) {

// Do the swipe thanks to the Appium driver
TouchAction dragNDrop
= new TouchAction(session.getAppiumDriver()).press(PointOption.point(direction.getX1(), direction.getY1())).waitAction(WaitOptions.waitOptions(Duration.ofMillis(duration == null ? DEFAULT_CERBERUS_APPIUM_SWIPE_DURATION : Integer.parseInt(duration.getValue()))))
= new TouchAction((PerformsTouchActions) session.getAppiumDriver()).press(PointOption.point(direction.getX1(), direction.getY1())).waitAction(WaitOptions.waitOptions(Duration.ofMillis(duration == null ? DEFAULT_CERBERUS_APPIUM_SWIPE_DURATION : Integer.parseInt(duration.getValue()))))//#FIXME SELENIUM #TEST (was cast to PerformsTouchActions)
.moveTo(PointOption.point(direction.getX2(), direction.getY2())).release();
dragNDrop.perform();

Expand Down Expand Up @@ -223,7 +224,7 @@ public MessageEvent openApp(Session session, String appPackage, String appActivi
public MessageEvent closeApp(Session session) {
try {

session.getAppiumDriver().closeApp();
((AndroidDriver) session.getAppiumDriver()).closeApp(); //#FIXME SELENIUM #TEST (was cast to AndroidDriver)

return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CLOSEAPP_GENERIC);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import io.appium.java_client.NoSuchContextException;
import io.appium.java_client.*;
import io.appium.java_client.remote.SupportsContextSwitching; //#FIXME To remove cause already import above but seems like i need it
import io.appium.java_client.touch.WaitOptions;
import io.appium.java_client.touch.offset.ElementOption;
import io.appium.java_client.touch.offset.PointOption;
Expand Down Expand Up @@ -82,18 +83,18 @@ public MessageEvent switchToContext(Session session, Identifier identifier) {
AppiumDriver driver = session.getAppiumDriver();
String newContext = "";

@SuppressWarnings("unchecked")
Set<String> contextNames = driver.getContextHandles();

for (String contextName : contextNames) {
LOG.error("Context : " + contextName);
if (contextName.contains("WEBVIEW")) {
driver.context(contextName);
newContext = contextName;
break;
}
}
//driver.context("WEBVIEW_1");
// @SuppressWarnings("unchecked") #FIXME SELENIUM what's the purpose of the for if u set the driver after anyway
// Set<String> contextNames = driver.getContextHandles();
//
// for (String contextName : contextNames) {
// LOG.error("Context : " + contextName);
// if (contextName.contains("WEBVIEW")) {
// driver.context(contextName);
// newContext = contextName;
// break;
// }
// }
// driver.context("WEBVIEW_1");
message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_SWITCHTOWINDOW);
message.setDescription(message.getDescription().replace("%WINDOW%", newContext));
return message;
Expand All @@ -103,21 +104,21 @@ public MessageEvent switchToContext(Session session, Identifier identifier) {
public MessageEvent switchToContext(Session session, String context) {
MessageEvent message;
AppiumDriver driver = session.getAppiumDriver();
Set<String> contexts = driver.getContextHandles();
Set<String> contexts = ((SupportsContextSwitching) driver).getContextHandles(); //#FIXME SELENIUM #TEST (was cast to SupportsContextSwitching)

try {
if (context.isEmpty()) {
context = "NATIVE_APP";
}
driver.context(context);
((SupportsContextSwitching) driver).context(context); //#FIXME SELENIUM #TEST (was cast to SupportsContextSwitching)
message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_SWITCHTOCONTEXT);
message.setDescription(message.getDescription().replace("%CONTEXT%", context));
} catch (NoSuchContextException exception) {
LOG.error("Impossible to change the context: ", exception);
message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SWITCHTOCONTEXT_NO_SUCH_ELEMENT);
message.setDescription(message.getDescription()
.replace("%CONTEXT%", context)
.replace("%CONTEXTS%", contexts.toString())
.replace("%CONTEXTS%", contexts.toString()) //#FIXME SELENIUM
.replace("%ERROR%", exception.getMessage()));
}
return message;
Expand Down Expand Up @@ -150,17 +151,17 @@ public MessageEvent type(Session session, Identifier identifier, String valueToT
try {
if (!StringUtil.isEmptyOrNullValue(valueToType)) {
WebElement elmt = this.getElement(session, identifier, false, false);
if (elmt instanceof MobileElement) {
((MobileElement) this.getElement(session, identifier, false, false)).setValue(valueToType);
if (elmt instanceof WebElement) { //#FIXME SELENIUM #TEST (changed type to WebElement)
(this.getElement(session, identifier, false, false)).sendKeys(valueToType);
} else { // FIXME See if we can delete it ??
TouchAction action = new TouchAction(session.getAppiumDriver());
action.press(ElementOption.element(this.getElement(session, identifier, false, false))).release().perform();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
LOG.error("Exception during Appium Type action.", e);
}
session.getAppiumDriver().getKeyboard().sendKeys(valueToType);
// TouchAction action = new TouchAction((PerformsTouchActions) session.getAppiumDriver());
// action.press(ElementOption.element(this.getElement(session, identifier, false, false))).release().perform();
// try {
// Thread.sleep(3000);
// } catch (InterruptedException e) {
// LOG.error("Exception during Appium Type action.", e);
// }
// session.getAppiumDriver().getKeyboard().sendKeys(valueToType);
}
}
message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_TYPE);
Expand All @@ -185,12 +186,12 @@ public MessageEvent type(Session session, Identifier identifier, String valueToT
@Override
public MessageEvent click(final Session session, final Identifier identifier) {
try {
final TouchAction action = new TouchAction(session.getAppiumDriver());
final TouchAction action = new TouchAction((PerformsTouchActions) session.getAppiumDriver()); //#FIXME SELENIUM #TEST (was cast to PerformsTouchActions)
if (identifier.isSameIdentifier(Identifier.Identifiers.COORDINATE)) {
final Coordinates coordinates = getCoordinates(identifier);
action.tap(PointOption.point(coordinates.getX(), coordinates.getY())).perform();
action.tap(PointOption.point(coordinates.getX(), coordinates.getY())).perform();//#FIXME SELENIUM #TEST (was cast to PerformsTouchActions)
} else {
action.tap(ElementOption.element(getElement(session, identifier, false, false))).perform();
action.tap(ElementOption.element(getElement(session, identifier, false, false))).perform();//#FIXME SELENIUM #TEST (was cast to PerformsTouchActions)
}
return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CLICK).resolveDescription("ELEMENT", identifier.toString());
} catch (NoSuchElementException e) {
Expand Down Expand Up @@ -285,7 +286,7 @@ private WebElement getElement(Session session, Identifier identifier, boolean vi

LOG.debug("Waiting for Element : " + identifier.getIdentifier() + "=" + identifier.getLocator());
try {
WebDriverWait wait = new WebDriverWait(driver, TimeUnit.MILLISECONDS.toSeconds(session.getCerberus_appium_wait_element()));
WebDriverWait wait = new WebDriverWait(driver, Duration.ofMillis(session.getCerberus_appium_wait_element()));
if (visible) {
if (clickable) {
wait.until(ExpectedConditions.elementToBeClickable(locator));
Expand Down Expand Up @@ -449,7 +450,7 @@ private MessageEvent scrollDown(AppiumDriver driver, By element, int numberOfScr

private void scroll(AppiumDriver driver, int fromX, int fromY, int toX, int toY) {

TouchAction touchAction = new TouchAction(driver);
TouchAction touchAction = new TouchAction((PerformsTouchActions) driver); //#FIXME SELENIUM #TEST (was cast to PerformsTouchActions)
touchAction.longPress(PointOption.point(fromX, fromY)).moveTo(PointOption.point(toX, toY)).release().perform();

}
Expand All @@ -459,16 +460,17 @@ private void scroll(AppiumDriver driver, int fromX, int fromY, int toX, int toY)
public String getElementPosition(Session session, Identifier identifier) {
AppiumDriver driver = session.getAppiumDriver();

MobileElement element = (MobileElement) driver.findElement(this.getBy(identifier));
Point location = element.getLocation();

return location.getX() + ";" + location.getY();
// MobileElement element = (MobileElement) driver.findElement(this.getBy(identifier)); //#FIXME SELENIUM
// Point location = element.getLocation();
//
// return location.getX() + ";" + location.getY();
return null;
}

@Override
public MessageEvent longPress(final Session session, final Identifier identifier, final Integer timeDuration) {
try {
final TouchAction action = new TouchAction(session.getAppiumDriver());
final TouchAction action = new TouchAction((PerformsTouchActions) session.getAppiumDriver());//#FIXME SELENIUM #TEST (was cast to PerformsTouchActions)
if (identifier.isSameIdentifier(Identifier.Identifiers.COORDINATE)) {
final Coordinates coordinates = getCoordinates(identifier);
action.press(PointOption.point(coordinates.getX(), coordinates.getY())).waitAction(WaitOptions.waitOptions(Duration.ofMillis(timeDuration))).release().perform();
Expand All @@ -491,7 +493,7 @@ public MessageEvent longPress(final Session session, final Identifier identifier
@Override
public MessageEvent clearField(final Session session, final Identifier identifier) {
try {
final TouchAction action = new TouchAction(session.getAppiumDriver());
final TouchAction action = new TouchAction((PerformsTouchActions) session.getAppiumDriver());//#FIXME SELENIUM #TEST (was cast to PerformsTouchActions)
if (identifier.isSameIdentifier(Identifier.Identifiers.COORDINATE)) {
final Coordinates coordinates = getCoordinates(identifier);
click(session, identifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
*/
package org.cerberus.core.service.appium.impl;

import io.appium.java_client.PerformsTouchActions;
import io.appium.java_client.TouchAction;
import io.appium.java_client.touch.WaitOptions;
import io.appium.java_client.touch.offset.PointOption;
import io.appium.java_client.ios.IOSDriver;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.cerberus.core.crud.service.impl.ParameterService;
Expand Down Expand Up @@ -93,7 +95,7 @@ public MessageEvent keyPress(Session session, String keyName) {

// Then do the key press
try {
session.getAppiumDriver().getKeyboard().pressKey(keyToPress.getCode());
// session.getAppiumDriver().getKeyboard().pressKey(keyToPress.getCode()); #FIXME SELENIUM
return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_KEYPRESS_NO_ELEMENT_NO_MODIFIER).resolveDescription("KEY", keyName);
} catch (Exception e) {
LOG.warn("Unable to key press due to " + e.getMessage());
Expand Down Expand Up @@ -155,7 +157,7 @@ public MessageEvent swipe(Session session, SwipeAction action) {

// Do the swipe thanks to the Appium driver
TouchAction dragNDrop
= new TouchAction(session.getAppiumDriver()).press(PointOption.point(direction.getX1(), direction.getY1())).waitAction(WaitOptions.waitOptions(Duration.ofMillis(myduration)))
= new TouchAction((PerformsTouchActions) session.getAppiumDriver()).press(PointOption.point(direction.getX1(), direction.getY1())).waitAction(WaitOptions.waitOptions(Duration.ofMillis(myduration))) //#FIXME SELENIUM #TEST (was cast to PerformsTouchActions)
.moveTo(PointOption.point(direction.getX2(), direction.getY2())).release();
dragNDrop.perform();

Expand Down Expand Up @@ -235,9 +237,9 @@ public MessageEvent openApp(Session session, String appPackage, String appActivi
try {

if (StringUtil.isEmpty(appPackage)) {
session.getAppiumDriver().launchApp();
((IOSDriver) session.getAppiumDriver()).launchApp(); //#FIXME SELENIUM #TEST (was cast to IOSDriver)
} else {
session.getAppiumDriver().activateApp(appPackage);
((IOSDriver) session.getAppiumDriver()).activateApp(appPackage);//#FIXME SELENIUM #TEST (was cast to IOSDriver)
}

return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_OPENAPP).resolveDescription("APP", appPackage);
Expand All @@ -253,7 +255,7 @@ public MessageEvent openApp(Session session, String appPackage, String appActivi
public MessageEvent closeApp(Session session) {
try {

session.getAppiumDriver().closeApp();
((IOSDriver) session.getAppiumDriver()).closeApp();//#FIXME SELENIUM #TEST (was cast to IOSDriver)

return new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CLOSEAPP_GENERIC);

Expand Down
Loading

0 comments on commit 03a311f

Please sign in to comment.