Skip to content

Commit

Permalink
feat: enable checkstyle in taps_to_cases module (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
TedaLIEz authored Mar 2, 2023
1 parent 3d94ff2 commit 184ea80
Show file tree
Hide file tree
Showing 16 changed files with 95 additions and 47 deletions.
3 changes: 3 additions & 0 deletions taps_to_cases/runner/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
group 'org.example'
version '1.0-SNAPSHOT'
apply from: "${project.rootDir}/quality/checkstyle.gradle"

repositories {
mavenCentral()
}

classes.finalizedBy checkstyleMain

dependencies {
implementation "com.google.guava:guava:30.1.1-jre"
// implementation 'com.squareup.okhttp3:okhttp:4.9.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package com.microsoft.hydralab.t2c.runner;

import com.microsoft.hydralab.t2c.runner.elements.BaseElementInfo;
Expand Down Expand Up @@ -38,7 +39,6 @@ public Integer getId() {
return id;
}


public String getDescription() {
return description;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package com.microsoft.hydralab.t2c.runner;

public class DriverInfo {
Expand All @@ -8,7 +9,7 @@ public class DriverInfo {
private final String launcherApp;
private final String initURL;

public DriverInfo(String id, String platform, String launcherApp, String initURL){
public DriverInfo(String id, String platform, String launcherApp, String initURL) {
this.id = id;
this.platform = platform;
this.launcherApp = launcherApp;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package com.microsoft.hydralab.t2c.runner;

import com.alibaba.fastjson.JSON;
Expand All @@ -21,13 +22,19 @@
import java.util.HashMap;
import java.util.Map;

public class T2CAppiumUtils {
public final class T2CAppiumUtils {
static HashMap<String, String> keyToInfoMap = new HashMap<>();
private static boolean isSelfTesting = false;

private T2CAppiumUtils() {

}

public static WebElement findElement(BaseDriverController driver, BaseElementInfo element, Logger logger) {
WebElement elementFound = null;
if (element == null) return null;
if (element == null) {
return null;
}
ElementFinder<BaseElementInfo> finder = ElementFinderFactory.createElementFinder(driver);
elementFound = finder.findElement(element);
if (elementFound != null) {
Expand All @@ -53,16 +60,18 @@ public static void doAction(@NotNull BaseDriverController driver, @NotNull Actio
}
}

@SuppressWarnings("methodlength")

public static void chooseActionType(BaseDriverController driver, ActionInfo actionInfo, Logger logger) {
String ActionType = actionInfo.getActionType();
String actionType = actionInfo.getActionType();
BaseElementInfo element = actionInfo.getTestElement();
WebElement webElement = findElement(driver, element, logger);
Map<String, Object> arguments = actionInfo.getArguments();
// Safe wait if no element required before this action to ensure the UI is ready
if (webElement == null && !isSelfTesting) {
safeSleep(3000);
}
switch (ActionType) {
switch (actionType) {
case "click":
driver.click(webElement);
break;
Expand Down Expand Up @@ -94,14 +103,16 @@ public static void chooseActionType(BaseDriverController driver, ActionInfo acti
case "activateApp":
String appPackageName = (String) arguments.get("appPackageName");
if (appPackageName == null) {
throw new IllegalArgumentException("App package name should not be null. Please add argument 'appPackageName' in the json. action index: " + actionInfo.getId());
throw new IllegalArgumentException(
"App package name should not be null. Please add argument 'appPackageName' in the json. action index: " + actionInfo.getId());
}
driver.activateApp(appPackageName);
break;
case "terminateApp":
String removeAppPackageName = (String) arguments.get("appPackageName");
if (removeAppPackageName == null) {
throw new IllegalArgumentException("App package name should not be null. Please add argument 'appPackageName' in the json. action index: " + actionInfo.getId());
throw new IllegalArgumentException(
"App package name should not be null. Please add argument 'appPackageName' in the json. action index: " + actionInfo.getId());
}
driver.terminateApp(removeAppPackageName);
break;
Expand Down Expand Up @@ -144,7 +155,8 @@ public static void chooseActionType(BaseDriverController driver, ActionInfo acti
String attribute = (String) arguments.get("attribute");
String expectedValue = (String) arguments.get("expectedValue");
if (attribute == null || expectedValue == null) {
throw new IllegalArgumentException("Assert info is not defined. Please add argument 'attribute' and 'expectedValue' in the json. action index: " + actionInfo.getId());
throw new IllegalArgumentException(
"Assert info is not defined. Please add argument 'attribute' and 'expectedValue' in the json. action index: " + actionInfo.getId());
}
driver.assertElementAttribute(webElement, attribute, expectedValue);
break;
Expand Down Expand Up @@ -184,7 +196,8 @@ public static void chooseActionType(BaseDriverController driver, ActionInfo acti
WebElement toElement = findElement(driver, toElementInfo, logger);
driver.dragAndDrop(webElement, toElement);
} else {
throw new IllegalArgumentException("Destination is not defined. Please add argument 'xVector' & 'yVector' or 'toElement' in the json. action index: " + actionInfo.getId());
throw new IllegalArgumentException(
"Destination is not defined. Please add argument 'xVector' & 'yVector' or 'toElement' in the json. action index: " + actionInfo.getId());
}
break;
case "switchToUrl":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package com.microsoft.hydralab.t2c.runner;

import com.alibaba.fastjson.JSON;
Expand All @@ -13,7 +14,9 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class T2CJsonParser {
private final Map<String, String> driveIdToTypeMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package com.microsoft.hydralab.t2c.runner;

import java.util.ArrayList;
Expand All @@ -8,7 +9,7 @@ public class TestInfo {
ArrayList<DriverInfo> drivers;
ArrayList<ActionInfo> cases;

public TestInfo(ArrayList<DriverInfo> drivers, ArrayList<ActionInfo> cases){
public TestInfo(ArrayList<DriverInfo> drivers, ArrayList<ActionInfo> cases) {
this.cases = cases;
this.drivers = drivers;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package com.microsoft.hydralab.t2c.runner.controller;

import com.google.common.collect.ImmutableMap;
import com.microsoft.hydralab.t2c.runner.T2CAppiumUtils;
import io.appium.java_client.AppiumBy;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.nativekey.AndroidKey;
import io.appium.java_client.android.nativekey.KeyEvent;
Expand All @@ -16,7 +16,6 @@
import org.openqa.selenium.interactions.PointerInput;
import org.openqa.selenium.interactions.Sequence;
import org.openqa.selenium.remote.RemoteWebElement;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.slf4j.Logger;

import java.time.Duration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package com.microsoft.hydralab.t2c.runner.controller;

import com.microsoft.hydralab.t2c.runner.elements.AndroidElementInfo;
Expand Down Expand Up @@ -33,6 +34,7 @@ public void click(WebElement element) {

/**
* Send content via keyboard, this will send the string directly to the current focus element
*
* @param content string you want to input with
*/
public void sendKeys(String content) {
Expand Down Expand Up @@ -189,6 +191,7 @@ public WebElement findElementByText(String text) {
/**
* In windows, id refers to {@link WindowsElementInfo#getName()}
* In android, id refers to {@link AndroidElementInfo#getResourceId()}
*
* @param id
* @return
*/
Expand All @@ -204,7 +207,6 @@ public WebElement findElementById(String id) {
return elementFound;
}


public abstract String getPageSource();

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public String getPageSource() {
return "Windows page: \n" + windowsDriver.getPageSource() + "\n Edge source: " + edgeDriver.getPageSource();
}


@Override
public void paste(WebElement webElement) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package com.microsoft.hydralab.t2c.runner.controller;

import io.appium.java_client.windows.WindowsDriver;
Expand Down Expand Up @@ -63,7 +64,6 @@ public String getPageSource() {
return windowsDriver.getPageSource();
}


@Override
public void paste(WebElement webElement) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package com.microsoft.hydralab.t2c.runner.elements;

import com.alibaba.fastjson.annotation.JSONField;
Expand Down Expand Up @@ -46,8 +47,9 @@ public class AndroidElementInfo extends BaseElementInfo {
@JSONField(name = "resource-id")
private String resourceId;

@SuppressWarnings("ParameterNumber")
public AndroidElementInfo(String index, String packageName, String className, String text, String contentDesc, String checkable,
String checked, String clickable, String enabled, String focusable, String focused, String long_clickable,
String checked, String clickable, String enabled, String focusable, String focused, String longClickable,
String password, String scrollable, String selected, String bounds, String displayed, String xpath,
String resourceId) {
super(xpath);
Expand All @@ -62,20 +64,20 @@ public AndroidElementInfo(String index, String packageName, String className, St
this.enabled = enabled;
this.focusable = focusable;
this.focused = focused;
this.longClickable = long_clickable;
this.longClickable = longClickable;
this.password = password;
this.scrollable = scrollable;
this.selected = selected;
this.bounds = bounds;
this.displayed = displayed;
this.xpath = xpath;
this.resourceId = resourceId;
if(bounds != null){
if (bounds != null) {
parseCoordinates(bounds);
}
}

private void parseCoordinates(String bounds){
private void parseCoordinates(String bounds) {
String[] boundsArray = bounds.split("\\[|\\]|,");
String[] validArr = Arrays.stream(boundsArray).filter(StringUtils::isNotEmpty).toArray(String[]::new);
int x1 = Integer.parseInt(validArr[0]);
Expand All @@ -84,10 +86,10 @@ private void parseCoordinates(String bounds){
int y2 = Integer.parseInt(validArr[3]);
top = y1;
left = x1;
width = x2-x1;
height = y2-y1;
centerX = x1 + width/2;
centerY = y1 + height/2;
width = x2 - x1;
height = y2 - y1;
centerX = x1 + width / 2;
centerY = y1 + height / 2;
}

public String getIndex() {
Expand All @@ -106,11 +108,10 @@ public String getContentDesc() {
return contentDesc;
}

public String getText(){
public String getText() {
return text;
}


public String getXpath() {
return xpath;
}
Expand Down Expand Up @@ -143,7 +144,6 @@ public String getResourceId() {
return resourceId;
}


public boolean isCheckable() {
return Boolean.parseBoolean(checkable);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package com.microsoft.hydralab.t2c.runner.elements;

import org.apache.commons.lang3.builder.ToStringBuilder;
Expand All @@ -11,12 +12,10 @@ public BaseElementInfo(String xpath) {
this.xpath = xpath;
}


public String getElementInfo(){
public String getElementInfo() {
return ToStringBuilder.reflectionToString(this);
}


public String getXpath() {
return xpath;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.microsoft.hydralab.t2c.runner.elements;

public class EdgeElementInfo extends WindowsElementInfo {
@SuppressWarnings("ParameterNumber")
public EdgeElementInfo(String acceleratorKey, String accessKey, String automationId, String className,
String frameworkId, String hasKeyboardFocus, String helpText, String isContentElement,
String isControlElement, String isEnabled, String isKeyboardFocusable, String isOffscreen,
Expand Down
Loading

0 comments on commit 184ea80

Please sign in to comment.