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

Move plotva #35

Merged
merged 9 commits into from
Mar 10, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
25 changes: 22 additions & 3 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.MobileConsole;
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,18 @@ 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch/case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rejected.

webElement.clear();
}

if (PageFactory.getEnvironment() == Environment.MOBILE && TagMobileDriver.getAppiumClickAdb()) {
MobileConsole.execute("ime set com.android.adbkeyboard/.AdbIME");
MobileConsole.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 +115,13 @@ 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()) {
int x = webElement.getLocation().getX() + webElement.getSize().getWidth() / 2;
int y = webElement.getLocation().getY() + webElement.getSize().getHeight() / 2;
MobileConsole.execute(String.format("input tap %s %s", x, y));
} else {
webElement.click();
}
Core.addToReport(webElement, " is clicked");
}

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".equals(Props.get("appium.fill.adb").toLowerCase());
private static final boolean APPIUM_CLICK_ADB = "true".equals(Props.get("appium.click.adb").toLowerCase());
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;
}
}
42 changes: 42 additions & 0 deletions src/main/java/ru/sbtqa/tag/pagefactory/support/MobileConsole.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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 MobileConsole {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AdbConsole. Because when we will add Iphone it will confuse everything. Also you can describe the interface which will abstract you from mobile platform.


private static final Logger LOG = LoggerFactory.getLogger(MobileConsole.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);
Process process;
try {
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);
}

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