Skip to content

Commit 00be1f9

Browse files
authored
Merge pull request #90 from sCShaimaaElbazedy/MobileClickFix
Enhancing mobile click functionality
2 parents c91ddce + f236822 commit 00be1f9

File tree

10 files changed

+531
-243
lines changed

10 files changed

+531
-243
lines changed

pom.xml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.github.umutayb</groupId>
88
<artifactId>Pickleib</artifactId>
9-
<version>1.9.7</version>
9+
<version>1.9.8</version>
1010
<packaging>jar</packaging>
1111

1212
<name>Pickleib</name>
@@ -42,7 +42,7 @@
4242
<buildDirectory>${project.basedir}/out/artifacts/POM-Framework_jar</buildDirectory>
4343
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4444
<maven.compiler.version>3.8.0</maven.compiler.version>
45-
<java.utilities.version>1.6.0</java.utilities.version>
45+
<java.utilities.version>1.6.1</java.utilities.version>
4646
<gpt.utilities.version>0.1.3</gpt.utilities.version>
4747
<docker-java.version>3.3.0</docker-java.version>
4848
<selenium.version>4.12.1</selenium.version>
@@ -181,6 +181,14 @@
181181
<version>1.15.4</version>
182182
</dependency>
183183

184+
<!-- Jsoup -->
185+
<dependency>
186+
<groupId>org.json</groupId>
187+
<artifactId>json</artifactId>
188+
<version>20231013</version>
189+
</dependency>
190+
191+
184192
<!-- JUnit -->
185193
<dependency>
186194
<groupId>junit</groupId>

src/main/java/pickleib/mobile/interactions/MobileInteractions.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.openqa.selenium.*;
44
import org.openqa.selenium.remote.RemoteWebDriver;
55
import org.openqa.selenium.support.ui.WebDriverWait;
6-
import pickleib.driver.DriverFactory;
76
import pickleib.enums.Direction;
87
import pickleib.enums.ElementState;
98
import pickleib.mobile.driver.PickleibAppiumDriver;
@@ -29,8 +28,7 @@ public MobileInteractions(RemoteWebDriver driver, WebDriverWait wait){
2928
this.wait = wait;
3029
interact = new ElementInteractions(
3130
driver,
32-
wait,
33-
DriverFactory.DriverType.Mobile
31+
wait
3432
);
3533
}
3634

@@ -40,8 +38,7 @@ public MobileInteractions(){
4038
this.wait = PickleibAppiumDriver.wait;
4139
interact = new ElementInteractions(
4240
driver,
43-
wait,
44-
DriverFactory.DriverType.Mobile
41+
wait
4542
);
4643
}
4744

@@ -190,8 +187,13 @@ public void scrollOrSwipeInDirection(Direction direction) {
190187
swiper(direction);
191188
}
192189

193-
public void clickButtonByText(String buttonText, Boolean scroll) {
194-
interact.clickButtonByText(buttonText, scroll);
190+
public void clickButtonByText(String buttonText, boolean scroll) {
191+
if (scroll) interact.clickButtonByText(buttonText, this::centerElement);
192+
else interact.clickButtonByText(buttonText);
193+
}
194+
195+
public void clickButtonByText(String buttonText) {
196+
interact.clickButtonByText(buttonText);
195197
}
196198

197199
public void updateContext(String key, String value) {

src/main/java/pickleib/mobile/utilities/MobileUtilities.java

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.openqa.selenium.support.PageFactory;
1212
import pickleib.enums.Direction;
1313
import pickleib.enums.ElementState;
14+
import pickleib.exceptions.PickleibException;
1415
import pickleib.mobile.driver.PickleibAppiumDriver;
1516
import pickleib.utilities.Utilities;
1617
import java.time.Duration;
@@ -54,9 +55,56 @@ protected MobileUtilities(RemoteWebDriver driver){
5455
);
5556
}
5657

57-
@Override
58-
public WebElement centerElement(WebElement element){
58+
/**
59+
* Clicks the specified {@code element} with retry mechanism and optional scrolling.
60+
*
61+
* <p>
62+
* This method attempts to click the given {@code element} with a retry mechanism.
63+
* It uses an implicit wait of 500 milliseconds during the retry attempts.
64+
* The method supports an optional {@code scroller} for scrolling before clicking the element.
65+
* If the {@code scroller} is provided, it scrolls towards the specified location before clicking.
66+
* </p>
67+
*
68+
* <p>
69+
* The method logs warning messages during the iteration process, indicating WebDriver exceptions.
70+
* After the maximum time specified by {@code elementTimeout}, if the element is still not clickable,
71+
* a {@code PickleibException} is thrown, including the last caught WebDriver exception.
72+
* </p>
73+
*
74+
* @param element The target {@code WebElement} to be clicked with retry mechanism.
75+
* @throws PickleibException If the element is not clickable after the retry attempts, a {@code PickleibException} is thrown
76+
* with the last caught WebDriver exception.
77+
*/
78+
public void clickElement(WebElement element, boolean scroll){
79+
if (scroll) clickElement(element, this::centerElement);
80+
else clickElement(element);
81+
}
82+
83+
/**
84+
* Clears and fills a given input
85+
*
86+
* @param inputElement target input element
87+
* @param inputText input text
88+
* @param verify verifies the input text value equals to an expected text if true
89+
*/
90+
protected void clearFillInput(WebElement inputElement, String inputText, boolean verify){
91+
fillInputElement(inputElement, inputText, null, verify);
92+
}
93+
94+
/**
95+
* Clears and fills a given input
96+
*
97+
* @param inputElement target input element
98+
* @param inputText input text
99+
* @param verify verifies the input text value equals to an expected text if true
100+
*/
101+
protected void clearFillInput(WebElement inputElement, String inputText, boolean scroll, boolean verify){
102+
if (scroll) fillInputElement(inputElement, inputText, this::centerElement, verify);
103+
else fillInputElement(inputElement, inputText, null, verify);
104+
}
59105

106+
//TODO: Implement iterative scroll that will swipe or center depending on if the element can be found in view.
107+
protected WebElement centerElement(WebElement element){
60108
Point center = new Point(
61109
driver.manage().window().getSize().getWidth()/2,
62110
driver.manage().window().getSize().getHeight()/2

src/main/java/pickleib/utilities/Interactions.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,21 @@ void verifyPresenceOfListedElements(
345345
* Click on a button that contains {button text} text
346346
*
347347
* @param buttonText target button text
348-
* @param scroll scrolls if true
349348
*/
350-
void clickButtonByText(String buttonText, Boolean scroll);
349+
void clickButtonByText(String buttonText);
350+
351+
/**
352+
* Clicks on a button with the specified text.
353+
*
354+
* <p>
355+
* This method clicks on a button that contains the provided {@code buttonText} text.
356+
* Optionally, it scrolls towards the button if {@code scroll} is set to true.
357+
* </p>
358+
*
359+
* @param buttonText The text content of the target button.
360+
* @param scroll If true, scrolls towards the button before clicking; otherwise, clicks directly.
361+
*/
362+
void clickButtonByText(String buttonText, boolean scroll);
351363

352364
/**
353365
*

src/main/java/pickleib/utilities/PropertyLoader.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package pickleib.utilities;
22

33
import context.ContextStore;
4-
import properties.PropertyUtility;
4+
import properties.PropertyUtilities;
55
import java.util.Properties;
66

77
public class PropertyLoader {
@@ -11,8 +11,8 @@ public class PropertyLoader {
1111

1212
public static void load(){
1313
if (!loaded){
14-
Properties properties = PropertyUtility.getProperties();
15-
Properties pickleibProperties = PropertyUtility.loadPropertyFile("pickleib.properties");
14+
Properties properties = PropertyUtilities.getProperties();
15+
Properties pickleibProperties = PropertyUtilities.loadPropertyFile("pickleib.properties");
1616
ContextStore.loadProperties("pickleib.properties");
1717

1818
if (!properties.isEmpty()){
@@ -21,7 +21,7 @@ public static void load(){
2121
}
2222
else properties = pickleibProperties;
2323

24-
PropertyUtility.properties.putAll(properties);
24+
PropertyUtilities.properties.putAll(properties);
2525
}
2626
loaded = true;
2727
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package pickleib.utilities;
2+
3+
import org.openqa.selenium.WebElement;
4+
5+
@FunctionalInterface
6+
public interface ScrollFunction {
7+
WebElement scroll(WebElement element);
8+
}

0 commit comments

Comments
 (0)