Skip to content
Open
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/***************************************************************************************************
*
* Copyright (c) 2026 Universitat Politecnica de Valencia - www.upv.es
* Copyright (c) 2026 Open Universiteit - www.ou.nl
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************************************/

package org.testar.monkey.alayer.android;

import org.w3c.dom.Document;

public final class AndroidPageSourceResult {

private final Document document;
private final String feedback;

public AndroidPageSourceResult(Document document, String feedback) {
this.document = document;
this.feedback = feedback;
}

public Document getDocument() {
return document;
}

public String getFeedback() {
return feedback;
}

public boolean hasDocument() {
return document != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class AndroidStateFetcher implements Callable<AndroidState> {
private Rect biggestRect = Rect.from(0, 0, 0, 0);

private String androidActivityVar;
private String stateFeedback = "";

public AndroidStateFetcher(SUT system) {
this.system = system;
Expand Down Expand Up @@ -79,6 +80,9 @@ public AndroidState call() throws Exception {
AndroidState root = createWidgetTree(rootElement);
root.set(Tags.Role, Roles.Process);
root.set(Tags.NotResponding, false);
if (!stateFeedback.isEmpty()) {
root.set(Tags.StateFeedback, stateFeedback);
}

// After create the widget tree, set widgets Path
for (Widget w : root) {
Expand All @@ -99,8 +103,11 @@ private AndroidRootElement buildAndroidSkeleton(SUT system) {

rootElement.pid = system.get(Tags.PID, (long)-1);

AndroidPageSourceResult pageSourceResult = AndroidAppiumFramework.getAndroidPageSource();
stateFeedback = pageSourceResult.getFeedback();

Document xmlAndroid;
if((xmlAndroid = AndroidAppiumFramework.getAndroidPageSource()) != null) {
if((xmlAndroid = pageSourceResult.getDocument()) != null) {
Node stateNode = xmlAndroid.getDocumentElement();

if(stateNode.hasChildNodes()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/***************************************************************************************************
*
* Copyright (c) 2020 - 2025 Universitat Politecnica de Valencia - www.upv.es
* Copyright (c) 2020 - 2025 Open Universiteit - www.ou.nl
* Copyright (c) 2020 - 2026 Universitat Politecnica de Valencia - www.upv.es
* Copyright (c) 2020 - 2026 Open Universiteit - www.ou.nl
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -41,48 +41,54 @@ public class AndroidActionClick extends TaggableBase implements Action {

private static final long serialVersionUID = 6663144395605910140L;

private String text;
private String accessibilityID;
private Widget widget;
private String widgetClass;
private String xpath;
private final String text;
private final String accessibilityId;
private final Widget widget;
private final String widgetClass;
private final String xpath;

public AndroidActionClick(State state, Widget w) {
this.set(Tags.Role, ActionRoles.LeftClickAt);
this.mapOriginWidget(w);
this.text = w.get(AndroidTags.AndroidText, "");
this.accessibilityID = w.get(AndroidTags.AndroidAccessibilityId, "");
this.accessibilityId = w.get(AndroidTags.AndroidAccessibilityId, "");
this.widget = w;
this.widgetClass = w.get(AndroidTags.AndroidClassName);
this.xpath = w.get(AndroidTags.AndroidXpath);
this.widgetClass = w.get(AndroidTags.AndroidClassName, "");
this.xpath = w.get(AndroidTags.AndroidXpath, "");
this.set(Tags.Desc, toShortString());
}

@Override
public void run(SUT system, State state, double duration) throws ActionFailedException {
try {
WebElement element = AndroidAppiumFramework.resolveElementByIdOrXPath(this.accessibilityID, this.widget);
WebElement element = AndroidAppiumFramework.resolveElementByIdOrXPath(this.accessibilityId, this.widget);
element.click();
} catch(Exception e) {
System.out.println("Exception trying to click Element By Id : " + this.accessibilityID);
System.out.println("Exception trying to click Element By Id : " + this.accessibilityId);
System.out.println(e.getMessage());
throw new ActionFailedException(toShortString());
}
}

@Override
public String toShortString() {
return "Execute Android click on Widget of type: '" + this.widgetClass + "', with text: '" + text + "', with Id: '" + accessibilityID + "', with xPath: " + xpath;
return "Execute Android click on Widget of type: '" + this.widgetClass + "', with text: '" + this.text + "', with Id: '" + this.accessibilityId + "', with xPath: " + this.xpath;
}

@Override
public String toParametersString() {
return "";
String widgetConcreteId = widget.get(Tags.ConcreteID, "NoWidgetConcreteIdAvailable");
return "role=" + this.get(Tags.Role, ActionRoles.LeftClickAt)
+ ",widget=" + widgetConcreteId
+ ",widgetClass=" + this.widgetClass
+ ",text=" + this.text
+ ",accessibilityId=" + this.accessibilityId
+ ",xpath=" + this.xpath;
}

@Override
public String toString(Role... discardParameters) {
return "";
return toParametersString();
}

public Widget getWidget(){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/***************************************************************************************************
*
* Copyright (c) 2020 - 2025 Open Universiteit - www.ou.nl
* Copyright (c) 2020 - 2025 Universitat Politecnica de Valencia - www.upv.es
* Copyright (c) 2020 - 2026 Open Universiteit - www.ou.nl
* Copyright (c) 2020 - 2026 Universitat Politecnica de Valencia - www.upv.es
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -31,6 +31,7 @@
package org.testar.monkey.alayer.android.actions;

import org.testar.monkey.alayer.*;
import org.testar.monkey.alayer.actions.ActionRoles;
import org.testar.monkey.alayer.exceptions.ActionFailedException;
import org.testar.monkey.alayer.android.AndroidAppiumFramework;
import org.testar.monkey.alayer.android.enums.AndroidRoles;
Expand All @@ -51,9 +52,9 @@ public AndroidActionLongClick(State state, Widget w) {
this.mapOriginWidget(w);
this.accessibilityId = w.get(AndroidTags.AndroidAccessibilityId, "");
this.widget = w;
this.widgetClass = w.get(AndroidTags.AndroidClassName);
this.xpath = w.get(AndroidTags.AndroidXpath);
this.text = w.get(AndroidTags.AndroidText);
this.widgetClass = w.get(AndroidTags.AndroidClassName, "");
this.xpath = w.get(AndroidTags.AndroidXpath, "");
this.text = w.get(AndroidTags.AndroidText, "");
this.set(Tags.Desc, toShortString());

}
Expand All @@ -74,14 +75,20 @@ public String toShortString() {
return "Execute Android Longclick on Widget of type: '" + this.widgetClass + "', with text: '" + this.text + "', with Id: '" + this.accessibilityId + "', with xPath: " + this.xpath;
}

@Override
public String toParametersString() {
return "";
}
@Override
public String toParametersString() {
String widgetConcreteId = widget.get(Tags.ConcreteID, "NoWidgetConcreteIdAvailable");
return "role=" + this.get(Tags.Role, ActionRoles.LeftClickAt)
+ ",widget=" + widgetConcreteId
+ ",widgetClass=" + this.widgetClass
+ ",text=" + this.text
+ ",accessibilityId=" + this.accessibilityId
+ ",xpath=" + this.xpath;
}

@Override
public String toString(Role... discardParameters) {
return "";
return toParametersString();
}

public Widget getWidget(){
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/***************************************************************************************************
*
* Copyright (c) 2020 - 2025 Open Universiteit - www.ou.nl
* Copyright (c) 2020 - 2025 Universitat Politecnica de Valencia - www.upv.es
* Copyright (c) 2020 - 2026 Open Universiteit - www.ou.nl
* Copyright (c) 2020 - 2026 Universitat Politecnica de Valencia - www.upv.es
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -40,22 +40,28 @@ public class AndroidActionScroll extends TaggableBase implements Action {

private static final long serialVersionUID = 6205133391190145934L;

private final int scrollDistance = 500;
private static final int SCROLL_DISTANCE = 500;
private final String accessibilityId;
private final Widget widget;
private final String widgetClass;
private final String text;
private final String xpath;

public AndroidActionScroll(State state, Widget w) {
this.set(Tags.Role, AndroidRoles.AndroidWidget);
this.mapOriginWidget(w);
this.accessibilityId = w.get(AndroidTags.AndroidAccessibilityId, "");
this.widget = w;
this.widgetClass = w.get(AndroidTags.AndroidClassName, "");
this.text = w.get(AndroidTags.AndroidText, "");
this.xpath = w.get(AndroidTags.AndroidXpath, "");
this.set(Tags.Desc, toShortString());
}

@Override
public void run(SUT system, State state, double duration) throws ActionFailedException {
try {
AndroidAppiumFramework.scrollElementById(this.accessibilityId, this.widget, this.scrollDistance);
AndroidAppiumFramework.scrollElementById(this.accessibilityId, this.widget, SCROLL_DISTANCE);
} catch(Exception e) {
System.out.println("Exception trying to scroll Element By Id : " + this.accessibilityId);
System.out.println(e.getMessage());
Expand All @@ -70,15 +76,22 @@ public String toShortString() {

@Override
public String toParametersString() {
return "";
String widgetConcreteId = this.widget.get(Tags.ConcreteID, "NoWidgetConcreteIdAvailable");
return "role=" + this.get(Tags.Role, AndroidRoles.AndroidWidget)
+ ",widget=" + widgetConcreteId
+ ",widgetClass=" + this.widgetClass
+ ",text=" + this.text
+ ",accessibilityId=" + this.accessibilityId
+ ",xpath=" + this.xpath
+ ",scrollDistance=" + SCROLL_DISTANCE;
}

@Override
public String toString(Role... discardParameters) {
return "";
return this.toParametersString();
}

public Widget getWidget(){
return widget;
return this.widget;
}
}
Loading
Loading