Skip to content
This repository has been archived by the owner on Nov 15, 2020. It is now read-only.

Commit

Permalink
Merge pull request #35 from sbtqa/move-plotva
Browse files Browse the repository at this point in the history
Move plotva
  • Loading branch information
kosteman authored Mar 10, 2017
2 parents 80dde0a + 6e975c1 commit 6eb4603
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/main/java/ru/sbtqa/tag/pagefactory/Page.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import ru.sbtqa.tag.pagefactory.annotations.PageEntry;
import ru.sbtqa.tag.pagefactory.annotations.RedirectsTo;
import ru.sbtqa.tag.pagefactory.annotations.ValidationRule;
import ru.sbtqa.tag.pagefactory.drivers.TagMobileDriver;
import ru.sbtqa.tag.pagefactory.exceptions.ElementDescriptionException;
import ru.sbtqa.tag.pagefactory.exceptions.ElementNotFoundException;
import ru.sbtqa.tag.pagefactory.exceptions.FactoryRuntimeException;
Expand All @@ -41,6 +42,8 @@
import ru.sbtqa.tag.pagefactory.exceptions.WaitException;
import ru.sbtqa.tag.pagefactory.extensions.DriverExtension;
import ru.sbtqa.tag.pagefactory.extensions.WebExtension;
import ru.sbtqa.tag.pagefactory.support.Environment;
import ru.sbtqa.tag.pagefactory.support.AdbConsole;
import ru.sbtqa.tag.qautils.errors.AutotestError;
import ru.sbtqa.tag.qautils.i18n.I18N;
import ru.sbtqa.tag.qautils.i18n.I18NRuntimeException;
Expand Down Expand Up @@ -71,8 +74,20 @@ public abstract class Page {
public void fillField(String elementTitle, String text) throws PageException {
WebElement webElement = getElementByTitle(elementTitle);
webElement.click();
webElement.clear();
webElement.sendKeys(text);

if (PageFactory.getEnvironment() == Environment.WEB) {
webElement.clear();
}

if (PageFactory.getEnvironment() == Environment.MOBILE && TagMobileDriver.getAppiumClickAdb()) {
// set ADBKeyBoard as default
AdbConsole.execute("ime set com.android.adbkeyboard/.AdbIME");
// send broadcast intent via adb
AdbConsole.execute(String.format("am broadcast -a ADB_INPUT_TEXT --es msg '%s'", text));
} else {
webElement.sendKeys(text);
}

Core.addToReport(elementTitle, text);
}

Expand Down Expand Up @@ -102,7 +117,14 @@ public void fillField(WebElement webElement, String text) {
* @param webElement a WebElement object to click
*/
public void clickWebElement(WebElement webElement) {
webElement.click();
if (PageFactory.getEnvironment() == Environment.MOBILE && TagMobileDriver.getAppiumClickAdb()) {
// get center point of element to tap on it
int x = webElement.getLocation().getX() + webElement.getSize().getWidth() / 2;
int y = webElement.getLocation().getY() + webElement.getSize().getHeight() / 2;
AdbConsole.execute(String.format("input tap %s %s", x, y));
} else {
webElement.click();
}
Core.addToReport(webElement, " is clicked");
}

Expand Down Expand Up @@ -812,7 +834,7 @@ public WebElement getElementByTitle(String title) throws PageException {
public <T extends TypifiedElement> T getTypifiedElementByTitle(String title) throws PageException {
for (Field field : FieldUtilsExt.getDeclaredFieldsWithInheritance(this.getClass())) {
if (Core.isRequiredElement(field, title) && Core.isChildOf(TypifiedElement.class, field)) {
return (T) Core.getElementByField(this, field);
return Core.getElementByField(this, field);
}
}
throw new ElementNotFoundException(String.format("Element '%s' is not present on current page '%s''", title, this.getTitle()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class TagMobileDriver {
private static final String APPIUM_APP_PACKAGE = Props.get("appium.app.package");
private static final String APPIUM_APP_ACTIVITY = Props.get("appium.app.activity");
private static final String VIDEO_ENABLED = Props.get("video.enabled", "false");
private static final boolean APPIUM_FILL_ADB = "true".equalsIgnoreCase(Props.get("appium.fill.adb"));
private static final boolean APPIUM_CLICK_ADB = "true".equalsIgnoreCase(Props.get("appium.click.adb"));
private static String deviceUdId;

public static AppiumDriver<AndroidElement> getDriver() {
if (Environment.MOBILE != PageFactory.getEnvironment()) {
Expand Down Expand Up @@ -64,11 +67,33 @@ private static void createDriver() {
LOG.debug("Aspect disabled");
mobileDriver = new AndroidDriver<>(url, capabilities);
LOG.info("Mobile driver created {}", mobileDriver);
deviceUdId = (String) mobileDriver.getSessionDetails().get("deviceUDID");
}

public static void dispose() {
if (mobileDriver != null) {
mobileDriver.quit();
}
}

/**
* @return the APPIUM_FILL_ADB
*/
public static boolean getAppiumFillAdb() {
return APPIUM_FILL_ADB;
}

/**
* @return the APPIUM_CLICK_ADB
*/
public static boolean getAppiumClickAdb() {
return APPIUM_CLICK_ADB;
}

/**
* @return the deviceUdId
*/
public static String getDeviceUDID() {
return deviceUdId;
}
}
45 changes: 45 additions & 0 deletions src/main/java/ru/sbtqa/tag/pagefactory/support/AdbConsole.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package ru.sbtqa.tag.pagefactory.support;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.sbtqa.tag.pagefactory.drivers.TagMobileDriver;

public class AdbConsole {

private static final Logger LOG = LoggerFactory.getLogger(AdbConsole.class);

private AdbConsole() {
throw new IllegalAccessError("Utility class");
}

public static boolean execute(String command) {
return execute(TagMobileDriver.getDeviceUDID(), command);
}

public static boolean execute(String deviceUDID, String command) {
ProcessBuilder processBuilder = new ProcessBuilder(new String[]{"adb", "-s", deviceUDID, "shell", command});
LOG.info("Command '{}' is processing...", command);
try {
Process process = processBuilder.start();

BufferedReader reader
= new BufferedReader(new InputStreamReader(process.getInputStream()));
StringBuilder builder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
builder.append(System.getProperty("line.separator"));
}
LOG.debug(builder.toString());

return process.waitFor() == 0;
} catch (IOException | InterruptedException ex) {
LOG.error("Failed to process command '{}'", command, ex);
}

return false;
}
}
Binary file added src/main/resources/apk/ADBKeyBoard.apk
Binary file not shown.
6 changes: 6 additions & 0 deletions src/main/resources/config/application.properties-sample
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ appium.device.platform = 6.0
appium.app.package = com.android.settings
appium.app.activity = .Settings

#optional. Avoid appium and fill fields throw adb
#(make sure that ADBKeyBoard is installed on android emulator for unicode support).
#False by default
appium.fill.adb = false
#optional. Avoid appium and click on elements throw adb by location. False by default
appium.click.adb = false

#IN CASE OF WEB
#parameters for web driver create
Expand Down

0 comments on commit 6eb4603

Please sign in to comment.