Skip to content

Commit

Permalink
Add sendkeys method in T2C runner and support input keys directly (#157)
Browse files Browse the repository at this point in the history
* feat: add sendkeys method and support input keys directly

* feat: remove unrelated changes

* feat: change method call to Actions

* feat: update demo json

Co-authored-by: Le Zhou <[email protected]>
  • Loading branch information
TedaLIEz and zhou9584 authored Nov 22, 2022
1 parent 0083064 commit 5495b3c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public static void chooseActionType(BaseDriverController driver, ActionInfo acti
BaseElementInfo element = actionInfo.getTestElement();
WebElement webElement = findElement(driver, element);
Map<String, Object> arguments = actionInfo.getArguments();

switch (ActionType) {
case "click":
driver.click(webElement);
Expand All @@ -78,7 +77,11 @@ public static void chooseActionType(BaseDriverController driver, ActionInfo acti
if (content == null) {
throw new IllegalArgumentException("Trying to input a null String. actionId: " + actionInfo.getId());
}
driver.input(webElement, content);
if (webElement == null) {
driver.sendKeys(content);
} else {
driver.input(webElement, content);
}
break;
case "clear":
driver.clear(webElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.slf4j.Logger;
Expand All @@ -27,6 +28,14 @@ public void click(WebElement element) {
element.click();
}

/**
* 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) {
new Actions(webDriver).sendKeys(content).perform();
}

public void tap(int x, int y) {
}

Expand Down Expand Up @@ -156,4 +165,5 @@ public WebElement findElementByName(String name) {
}
return elementFound;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ public void tap(int x, int y) {
tap.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));
windowsDriver.perform(Arrays.asList(tap));
}

}
14 changes: 13 additions & 1 deletion taps_to_cases/T2C_Runner/src/test/resources/DemoJson.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@
}
},
"isOption": false
}
},
{
"index": 1,
"elementInfo": { },
"driverId": "13211FDD400183",
"action": {
"actionType": "input",
"arguments": {
"content": "helloworld"
}
},
"isOption": false
}
]
}

0 comments on commit 5495b3c

Please sign in to comment.