Skip to content

Architecture refactor 1v.9.9 #99

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

Merged
merged 48 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
e61c6db
:)
Umutayb Feb 2, 2024
4577fdd
Web interactions refactor
Umutayb Feb 2, 2024
1cb3de0
Changed access modifiers, added methods
Umutayb Feb 6, 2024
c3a1c7c
MobileInteractions
InnaDrapii Feb 7, 2024
7c25a46
MobileInteractions
InnaDrapii Feb 7, 2024
96481cd
MobileInteractions
InnaDrapii Feb 7, 2024
b750059
MobileInteractions
InnaDrapii Feb 7, 2024
d9a5d00
MobileInteractions
InnaDrapii Feb 9, 2024
d5a5c56
MobileInteractions
InnaDrapii Feb 9, 2024
e5d7aea
MobileInteractions
InnaDrapii Feb 9, 2024
3050dd4
WebInteractions
InnaDrapii Feb 9, 2024
7e9a96d
WebInteractions
InnaDrapii Feb 12, 2024
978c00d
WebInteractions
InnaDrapii Feb 12, 2024
696666b
WebInteractions
InnaDrapii Feb 12, 2024
df6d943
WebInteractions
InnaDrapii Feb 13, 2024
0ba5727
WebInteractions
InnaDrapii Feb 13, 2024
5935b0e
Merge branch 'main' into pr/93
Umutayb Feb 13, 2024
e7d6437
Update ServiceFactory.java
Umutayb Feb 13, 2024
144d7af
Wait improvements
Umutayb Feb 14, 2024
79d5614
Driver and wait updates
Umutayb Feb 14, 2024
960030c
WebInteractions
InnaDrapii Feb 14, 2024
6420dd5
WebInteractions
InnaDrapii Feb 14, 2024
2042151
WebInteractions
InnaDrapii Feb 14, 2024
f69e84b
WebInteractions
InnaDrapii Feb 14, 2024
412397c
WebInteractions
InnaDrapii Feb 15, 2024
d725d44
WebInteractions
InnaDrapii Feb 15, 2024
0b9a21c
Update PolymorphicUtilities.java
Umutayb Feb 15, 2024
3556b85
Introduced new scroller for listed elements.
Umutayb Feb 15, 2024
31c1bee
WebInteractions
InnaDrapii Feb 15, 2024
c587239
WebInteractions
InnaDrapii Feb 15, 2024
1feb35a
WebInteractions
InnaDrapii Feb 16, 2024
93c70f2
WebInteractions
InnaDrapii Feb 16, 2024
d96392b
WebInteractions
InnaDrapii Feb 16, 2024
959496a
New scroll in list and scroll until found approaches.
Umutayb Feb 17, 2024
d331f17
Merge branch 'mobile-interactions-1v.9.9' of https://github.com/InnaD…
Umutayb Feb 17, 2024
bb969d9
Update WebUtilities.java
Umutayb Feb 17, 2024
606a375
Update ElementAcquisition.java
Umutayb Feb 20, 2024
c4b62d7
Update ElementAcquisition.java
Umutayb Feb 20, 2024
628c5ff
WebInteractions
InnaDrapii Feb 20, 2024
9b52a69
WebInteractions
InnaDrapii Feb 21, 2024
699b99a
WebInteractions
InnaDrapii Feb 21, 2024
d1fa199
Update WebInteractions.java
Umutayb Feb 21, 2024
e895e3f
Merge branch 'mobile-interactions-1v.9.9' of https://github.com/InnaD…
Umutayb Feb 21, 2024
66f7135
WebInteractions
InnaDrapii Feb 21, 2024
307a037
Merge branch 'mobile-interactions-1v.9.9' of https://github.com/InnaD…
InnaDrapii Feb 21, 2024
b6cd747
Small refactor and repackaging
Umutayb Feb 21, 2024
1921dde
Merge pull request #93 from InnaDrapii/mobile-interactions-1v.9.9
Umutayb Feb 21, 2024
3d5c848
version update!
Umutayb Feb 21, 2024
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
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>8.3.0</version>
<scope>compile</scope>
<version>${appium.version}</version>
</dependency>

<!-- Gson -->
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/pickleib/driver/DriverFactory.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package pickleib.driver;

import org.jetbrains.annotations.Nullable;
import org.openqa.selenium.Platform;

public interface DriverFactory {
enum DriverType {
Web,
Mobile;
Mobile,
iOS,
Android;

public static DriverType fromString(String text) {
if (text != null)
Expand All @@ -18,5 +21,21 @@ public static DriverType fromString(String text) {
public static DriverType getType(@Nullable String text) {
return fromString(text);
}

public static DriverType getParentType(Platform platform) {
return switch (platform) {
case WINDOWS, LINUX, UNIX, VENTURA, MONTEREY, BIG_SUR, CATALINA, MOJAVE, HIGH_SIERRA, SIERRA, EL_CAPITAN, YOSEMITE, MAVERICKS, MOUNTAIN_LION, SNOW_LEOPARD, MAC, WIN11, WIN10, WIN8_1, WIN8, WIN7, VISTA, XP -> Web;
case ANDROID -> Android;
case IOS -> iOS;
case ANY -> null;
};
}

public static DriverType getGeneralType(DriverType driverType){
return switch (driverType){
case Web -> Web;
case Mobile, iOS, Android -> Mobile;
};
}
}
}
30 changes: 30 additions & 0 deletions src/main/java/pickleib/driver/DriverLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package pickleib.driver;

import collections.Pair;
import io.appium.java_client.AppiumDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import pickleib.mobile.driver.PickleibAppiumDriver;
import pickleib.web.driver.PickleibWebDriver;

public class DriverLoader {

public RemoteWebDriver loadWebDriver(){
PickleibWebDriver.initialize();
return PickleibWebDriver.get();
}

public AppiumDriver loadMobileDriver(){
PickleibAppiumDriver.initialize();
return PickleibAppiumDriver.get();
}

public void load(DriverFactory.DriverType... driverTypes){
for (DriverFactory.DriverType type:driverTypes) {
switch (type){
case Mobile -> PickleibAppiumDriver.initialize();
case Web -> PickleibWebDriver.initialize();
default -> throw new EnumConstantNotPresentException(DriverFactory.DriverType.class, type.name());
}
}
}
}
69 changes: 69 additions & 0 deletions src/main/java/pickleib/mobile/PickleibScreenObject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package pickleib.mobile;

import context.ContextStore;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.DefaultFieldDecorator;
import pickleib.mobile.driver.PickleibAppiumDriver;
import pickleib.mobile.utilities.MobileUtilities;
import pickleib.web.driver.PickleibWebDriver;

import java.time.Duration;

public abstract class PickleibScreenObject extends MobileUtilities {
/**
* PickleibScreenObject for frameworks that use the Pickleib driver
*
*/
protected PickleibScreenObject(){
super(PickleibAppiumDriver.get());
PageFactory.initElements(
new AppiumFieldDecorator(
PickleibAppiumDriver.get(),
Duration.ofSeconds(
Long.parseLong(ContextStore.get("element-timeout", "15000"))/1000
)
),
this
);
}

/**
* PickleibScreenObject for frameworks that do not use the Pickleib driver
*
*/
protected PickleibScreenObject(RemoteWebDriver driver){
super(driver);
PageFactory.initElements(
new AppiumFieldDecorator(
driver,
Duration.ofSeconds(
Long.parseLong(ContextStore.get("element-timeout", "15000"))/1000
)
),
this
);
}

/**
* PickleibScreenObject for frameworks with custom field decorator that use the Pickleib driver
*
*/
protected <CustomFieldDecorator extends DefaultFieldDecorator> PickleibScreenObject(CustomFieldDecorator fieldDecorator){
super(PickleibWebDriver.get());
PageFactory.initElements(fieldDecorator, this);
}

/**
* PickleibScreenObject for frameworks with custom field decorator that do not use the Pickleib driver
*
*/
protected <CustomFieldDecorator extends DefaultFieldDecorator> PickleibScreenObject(
CustomFieldDecorator fieldDecorator,
RemoteWebDriver driver
){
super(driver);
PageFactory.initElements(fieldDecorator, this);
}
}
20 changes: 7 additions & 13 deletions src/main/java/pickleib/mobile/driver/AppiumDriverFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,20 @@
import org.json.simple.JSONObject;
import org.openqa.selenium.remote.DesiredCapabilities;
import pickleib.driver.DriverFactory;
import utils.FileUtilities;
import utils.Printer;
import java.net.URL;
import java.time.Duration;

import static pickleib.mobile.driver.ServiceFactory.service;
import static pickleib.utilities.element.ElementAcquisition.strUtils;
import static utils.StringUtilities.Color.*;
import static utils.StringUtilities.*;

public class AppiumDriverFactory implements DriverFactory {

static Printer log = new Printer(AppiumDriverFactory.class);
static FileUtilities.Json jsonUtils = new FileUtilities.Json();

public static AppiumDriver getDriver(String deviceName, JSONObject capabilities){
DesiredCapabilities desiredCapabilities = getConfig(capabilities);
desiredCapabilities.setCapability("app", strUtils.contextCheck("UPLOAD-" + capabilities.get("app")));
desiredCapabilities.setCapability("app", contextCheck("UPLOAD-" + capabilities.get("app")));
try {
URL url;
if (service == null) {
Expand All @@ -30,18 +27,15 @@ public static AppiumDriver getDriver(String deviceName, JSONObject capabilities)
url = new URL("http://" + address + ":" + port + "/wd/hub");
}
else url = service.getUrl();

AppiumDriver driver = new AppiumDriver(url, desiredCapabilities);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(15));
log.important(deviceName + strUtils.markup(GRAY, " was selected"));
return driver;
log.important(deviceName + markup(GRAY, " was selected"));
return new AppiumDriver(url, desiredCapabilities);
}
catch (Exception gamma) {
if(gamma.toString().contains("Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure")){
log.info("Please make sure " + strUtils.markup(PURPLE, "Appium ") + "is on & verify the port that its running on at 'resources/test.properties'.");
throw new RuntimeException(strUtils.markup(YELLOW, gamma.getMessage()));
log.info("Please make sure " + markup(PURPLE, "Appium ") + "is on & verify the port that its running on at 'resources/test.properties'.");
throw new RuntimeException(markup(YELLOW, gamma.getMessage()));
}
else throw new RuntimeException(strUtils.markup(YELLOW, "Something went wrong while selecting a driver") + "\n" + strUtils.markup(RED, gamma.getMessage()));
else throw new RuntimeException(markup(YELLOW, "Something went wrong while selecting a driver") + "\n" + markup(RED, gamma.getMessage()));
}
}

Expand Down
34 changes: 27 additions & 7 deletions src/main/java/pickleib/mobile/driver/PickleibAppiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,32 @@

import context.ContextStore;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.AppiumFluentWait;
import org.json.simple.JSONObject;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.WebDriverWait;
import pickleib.utilities.PropertyLoader;
import pickleib.utilities.screenshot.ScreenCaptureUtility;
import properties.PropertiesReader;
import utils.*;
import java.io.IOException;
import java.net.ServerSocket;

@SuppressWarnings("unused")
public class PickleibAppiumDriver {
public abstract class PickleibAppiumDriver {

public static ScreenCaptureUtility capture = new ScreenCaptureUtility();

static {PropertyLoader.load();}

public static AppiumDriver driver;
public static WebDriverWait wait;
private static AppiumDriver driver;
private static AppiumFluentWait<RemoteWebDriver> wait;

public static AppiumDriver get(){
return driver;
}
private static final PropertiesReader reader = new PropertiesReader("properties-from-pom.properties");
private static final StringUtilities strUtils = new StringUtilities();
private static final Printer log = new Printer(PickleibAppiumDriver.class);

public static void startService(){
Expand All @@ -45,16 +53,28 @@ public static void initialize() {

String directory = ContextStore.get("config", "src/test/resources/configurations");

JSONObject json = AppiumDriverFactory.jsonUtils.parseJSONFile(directory+"/"+device+".json");
driver = AppiumDriverFactory.getDriver(strUtils.firstLetterCapped(device), json);
JSONObject json = FileUtilities.Json.parseJSONFile(directory+"/"+device+".json");
driver = AppiumDriverFactory.getDriver(StringUtilities.firstLetterCapped(device), json);
}

public static void terminate(){
log.info("Finalizing driver...");
try {driver.quit();}
catch (Exception exception){exception.printStackTrace();}
finally {
if (ServiceFactory.service != null) ServiceFactory.service.stop(); //TODO: Verify socket & log success
}
}

public static void captureAndTerminate(boolean success, String screenshotTag){
log.info("Finalizing driver...");
try {
capture.captureScreen(screenshotTag, "png", driver);
driver.quit();
}
catch (Exception exception){exception.printStackTrace();}
finally {
if (ServiceFactory.service != null) ServiceFactory.service.stop(); //TODO: Verify socket & log success
}
catch (Exception ignored){}
}
}
3 changes: 3 additions & 0 deletions src/main/java/pickleib/mobile/driver/ServiceFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import io.appium.java_client.service.local.AppiumServiceBuilder;
import utils.Printer;

import java.time.Duration;

import static utils.StringUtilities.Color.*;

public class ServiceFactory {
Expand All @@ -21,6 +23,7 @@ public static void startService(String address, Integer port){
service = new AppiumServiceBuilder()
.withIPAddress(address)
.usingPort(port)
.withTimeout(Duration.ofSeconds(Integer.parseInt(ContextStore.get("appium-server-launch-timeout", "45"))))
.build();
if(!Boolean.parseBoolean(ContextStore.get("detailed-logging", "false")))
ServiceFactory.service.clearOutPutStreams();
Expand Down
Loading