diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/provider/selenium/webdriver/WebDriverWrapper.java b/bb-core/src/main/java/com/cognifide/qa/bb/provider/selenium/webdriver/WebDriverWrapper.java index 01d17a45..7a19ad47 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/provider/selenium/webdriver/WebDriverWrapper.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/provider/selenium/webdriver/WebDriverWrapper.java @@ -19,10 +19,15 @@ */ package com.cognifide.qa.bb.provider.selenium.webdriver; +import java.io.File; +import java.io.IOException; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.UUID; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.Connection; import org.openqa.selenium.Capabilities; import org.openqa.selenium.ContextAware; import org.openqa.selenium.DeviceRotation; @@ -40,6 +45,7 @@ import org.openqa.selenium.internal.FindsByName; import org.openqa.selenium.internal.FindsByTagName; import org.openqa.selenium.internal.FindsByXPath; +import org.openqa.selenium.internal.HasIdentity; import org.openqa.selenium.remote.Response; import org.openqa.selenium.support.events.EventFiringWebDriver; @@ -53,37 +59,33 @@ import io.appium.java_client.InteractsWithApps; import io.appium.java_client.InteractsWithFiles; import io.appium.java_client.MobileDriver; -import io.appium.java_client.MobileElement; import io.appium.java_client.MultiTouchAction; -import io.appium.java_client.NetworkConnectionSetting; import io.appium.java_client.PerformsTouchActions; -import io.appium.java_client.ScrollsTo; import io.appium.java_client.TouchAction; import io.appium.java_client.TouchShortcuts; import io.appium.java_client.android.AndroidDeviceActionShortcuts; import io.appium.java_client.android.HasNetworkConnection; import io.appium.java_client.android.PushesFiles; import io.appium.java_client.android.StartsActivity; -import io.appium.java_client.ios.GetsNamedTextField; import io.appium.java_client.ios.IOSDeviceActionShortcuts; /** - * This class is a "simple" extension of Selenium's EventFiringWebDriver that additionally implements several - * useful interfaces. + * This class is a "simple" extension of Selenium's EventFiringWebDriver that additionally + * implements several useful interfaces. */ public class WebDriverWrapper extends EventFiringWebDriver implements FindsById, FindsByClassName, - FindsByLinkText, FindsByName, FindsByCssSelector, FindsByTagName, FindsByXPath, HasCapabilities, - MobileDriver, Rotatable, FindsByAccessibilityId, LocationContext, TouchShortcuts, - InteractsWithApps, ScrollsTo, AndroidDeviceActionShortcuts, HasAppStrings, HasNetworkConnection, - PushesFiles, StartsActivity, FindsByAndroidUIAutomator, IOSDeviceActionShortcuts, - GetsNamedTextField, FindsByIosUIAutomation { + FindsByLinkText, FindsByName, FindsByCssSelector, FindsByTagName, FindsByXPath, + HasCapabilities, MobileDriver, Rotatable, LocationContext, ContextAware, + TouchShortcuts, InteractsWithApps, AndroidDeviceActionShortcuts, HasAppStrings, + HasNetworkConnection, PushesFiles, StartsActivity, FindsByAndroidUIAutomator, + IOSDeviceActionShortcuts, FindsByIosUIAutomation, HasIdentity, PerformsTouchActions { private final FrameSwitcher frameSwitcher; /** * Constructs WebDriverWrapper. * - * @param driver instance of WebDriver. + * @param driver instance of WebDriver. * @param frameSwitcher instance of FrameSwitcher. */ public WebDriverWrapper(WebDriver driver, FrameSwitcher frameSwitcher) { @@ -239,16 +241,6 @@ public void performMultiTouchAction(MultiTouchAction multiAction) { ((PerformsTouchActions) super.getWrappedDriver()).performMultiTouchAction(multiAction); } - @Override - public MobileElement scrollTo(String text) { - return ((ScrollsTo) super.getWrappedDriver()).scrollTo(text); - } - - @Override - public MobileElement scrollToExact(String text) { - return ((ScrollsTo) super.getWrappedDriver()).scrollToExact(text); - } - @Override public void launchApp() { ((InteractsWithApps) super.getWrappedDriver()).launchApp(); @@ -335,8 +327,8 @@ public void hideKeyboard() { } @Override - public void sendKeyEvent(int key) { - ((DeviceActionShortcuts) super.getWrappedDriver()).sendKeyEvent(key); + public String getDeviceTime() { + return ((DeviceActionShortcuts) super.getWrappedDriver()).getDeviceTime(); } @Override @@ -375,13 +367,13 @@ public DeviceRotation rotation() { } @Override - public void rotate(ScreenOrientation arg0) { - ((Rotatable) super.getWrappedDriver()).rotate(arg0); + public void rotate(ScreenOrientation screenOrientation) { + ((Rotatable) super.getWrappedDriver()).rotate(screenOrientation); } @Override - public WebDriver context(String arg0) { - return ((ContextAware) super.getWrappedDriver()).context(arg0); + public WebDriver context(String name) { + return ((ContextAware) super.getWrappedDriver()).context(name); } @Override @@ -395,7 +387,7 @@ public Set getContextHandles() { } @Override - public Response execute(String driverCommand, Map parameters) { + public Response execute(String driverCommand, Map parameters) { return ((MobileDriver) super.getWrappedDriver()).execute(driverCommand, parameters); } @@ -409,11 +401,6 @@ public List findElementsByIosUIAutomation(String using) { return ((FindsByIosUIAutomation) super.getWrappedDriver()).findElementsByIosUIAutomation(using); } - @Override - public WebElement getNamedTextField(String name) { - return ((GetsNamedTextField) super.getWrappedDriver()).getNamedTextField(name); - } - @Override public void hideKeyboard(String keyName) { ((IOSDeviceActionShortcuts) super.getWrappedDriver()).hideKeyboard(keyName); @@ -441,6 +428,13 @@ public List findElementsByAndroidUIAutomator(String using) { .findElementsByAndroidUIAutomator(using); } + @Override + public void startActivity(String appPackage, String appActivity, String appWaitPackage, + String appWaitActivity, boolean stopApp) throws IllegalArgumentException { + ((StartsActivity) super.getWrappedDriver()).startActivity(appPackage, appActivity, + appWaitPackage, appWaitActivity, stopApp); + } + @Override public void startActivity(String appPackage, String appActivity, String appWaitPackage, String appWaitActivity) { @@ -453,38 +447,88 @@ public void startActivity(String appPackage, String appActivity) { ((StartsActivity) super.getWrappedDriver()).startActivity(appPackage, appActivity); } + @Override + public void startActivity(String appPackage, String appActivity, String appWaitPackage, + String appWaitActivity, String intentAction, String intentCategory, String intentFlags, + String intentOptionalArgs) throws IllegalArgumentException { + ((StartsActivity) super.getWrappedDriver()).startActivity(appPackage, appActivity, + appWaitPackage, appWaitActivity, intentAction, intentCategory, intentFlags, + intentOptionalArgs); + + } + + @Override + public void startActivity(String appPackage, String appActivity, String appWaitPackage, + String appWaitActivity, String intentAction, String intentCategory, String intentFlags, + String intentOptionalArgs, boolean stopApp) throws IllegalArgumentException { + ((StartsActivity) super.getWrappedDriver()).startActivity(appPackage, appActivity, + appWaitPackage, appWaitActivity, intentAction, intentCategory, intentFlags, + intentOptionalArgs, stopApp); + } + @Override public void pushFile(String remotePath, byte[] base64Data) { ((PushesFiles) super.getWrappedDriver()).pushFile(remotePath, base64Data); } @Override - public NetworkConnectionSetting getNetworkConnection() { - return ((HasNetworkConnection) super.getWrappedDriver()).getNetworkConnection(); + public void pushFile(String remotePath, File file) throws IOException { + ((PushesFiles) super.getWrappedDriver()).pushFile(remotePath, file); } @Override - public void setNetworkConnection(NetworkConnectionSetting connection) { - ((HasNetworkConnection) super.getWrappedDriver()).setNetworkConnection(connection); + public TargetLocator switchTo() { + return new BobcatTargetLocator(super.getWrappedDriver().switchTo(), frameSwitcher); } @Override - public String getAppStrings() { - return ((HasAppStrings) super.getWrappedDriver()).getAppStrings(); + public Map getAppStringMap() { + return ((HasAppStrings) super.getWrappedDriver()).getAppStringMap(); } @Override - public String getAppStrings(String language) { - return ((HasAppStrings) super.getWrappedDriver()).getAppStrings(language); + public Map getAppStringMap(String language) { + return ((HasAppStrings) super.getWrappedDriver()).getAppStringMap(language); } @Override - public void sendKeyEvent(int key, Integer metastate) { - ((AndroidDeviceActionShortcuts) super.getWrappedDriver()).sendKeyEvent(key, metastate); + public Map getAppStringMap(String language, String stringFile) { + return ((HasAppStrings) super.getWrappedDriver()).getAppStringMap(language, stringFile); } @Override - public TargetLocator switchTo() { - return new BobcatTargetLocator(super.getWrappedDriver().switchTo(), frameSwitcher); + public void pressKeyCode(int key) { + ((AndroidDriver) super.getWrappedDriver()).longPressKeyCode(key); + } + + @Override + public void pressKeyCode(int key, Integer metastate) { + ((AndroidDriver) super.getWrappedDriver()).pressKeyCode(key, metastate); + } + + @Override + public void longPressKeyCode(int key) { + ((AndroidDriver) super.getWrappedDriver()).longPressKeyCode(key); + } + + @Override + public void longPressKeyCode(int key, Integer metastate) { + ((AndroidDriver) super.getWrappedDriver()).longPressKeyCode(key, metastate); + } + + @Override + public void setConnection(Connection connection) { + ((HasNetworkConnection) super.getWrappedDriver()).setConnection(connection); } + + @Override + public Connection getConnection() { + return ((HasNetworkConnection) super.getWrappedDriver()).getConnection(); + } + + @Override + public String getId() { + return UUID.randomUUID().toString(); + } + } diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/webelement/BobcatWebElement.java b/bb-core/src/main/java/com/cognifide/qa/bb/webelement/BobcatWebElement.java index d41a3201..6fa2cc62 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/webelement/BobcatWebElement.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/webelement/BobcatWebElement.java @@ -25,6 +25,7 @@ import com.google.inject.assistedinject.Assisted; import java.util.List; +import java.util.UUID; import org.apache.commons.lang3.StringUtils; import org.openqa.selenium.By; @@ -36,13 +37,14 @@ import org.openqa.selenium.WebDriverException; import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.internal.Coordinates; +import org.openqa.selenium.internal.HasIdentity; import org.openqa.selenium.internal.Locatable; import org.openqa.selenium.internal.WrapsElement; /** * Improves WebElement implementation with custom {@link #sendKeys(CharSequence...)} method */ -public class BobcatWebElement implements WebElement, Locatable, WrapsElement { +public class BobcatWebElement implements WebElement, Locatable, WrapsElement, HasIdentity { private static final int SEND_KEYS_RETRIES = 10; @@ -202,4 +204,9 @@ private boolean isKeys(CharSequence charSequence) { private String getValue() { return element.getAttribute("value"); } + + @Override + public String getId() { + return UUID.randomUUID().toString(); + } } diff --git a/bb-reports/src/main/java/com/cognifide/qa/bb/logging/TestInfo.java b/bb-reports/src/main/java/com/cognifide/qa/bb/logging/TestInfo.java index cefa9953..8d20c7da 100644 --- a/bb-reports/src/main/java/com/cognifide/qa/bb/logging/TestInfo.java +++ b/bb-reports/src/main/java/com/cognifide/qa/bb/logging/TestInfo.java @@ -30,6 +30,9 @@ import java.util.TreeSet; import java.util.concurrent.TimeUnit; +import com.cognifide.qa.bb.provider.selenium.webdriver.close.ClosingAwareWebDriverWrapper; +import io.appium.java_client.AppiumDriver; +import io.appium.java_client.MobileDriver; import org.openqa.selenium.Capabilities; import org.openqa.selenium.HasCapabilities; import org.openqa.selenium.WebDriver; @@ -66,6 +69,8 @@ public class TestInfo { private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(TestInfo.class); + private static final String NATIVE_APP_CONTEXT = "NATIVE_APP"; + private final Date start; private final Deque subreports; @@ -254,7 +259,18 @@ public void screenshot() { */ public void screenshot(String message) { try { - addLogEntry(new ScreenshotEntry(webDriver, fileCreator, message)); + if (webDriver instanceof ClosingAwareWebDriverWrapper + && ((ClosingAwareWebDriverWrapper) this.webDriver).getWrappedDriver() instanceof AppiumDriver) { + AppiumDriver appiumDriver = + (AppiumDriver) ((ClosingAwareWebDriverWrapper) this.webDriver).getWrappedDriver(); + String originalContext = appiumDriver.getContext(); + appiumDriver.context(NATIVE_APP_CONTEXT); + ScreenshotEntry screenshotEntry = new ScreenshotEntry(this.webDriver, fileCreator, message); + appiumDriver.context(originalContext); + addLogEntry(screenshotEntry); + } else { + addLogEntry(new ScreenshotEntry(webDriver, fileCreator, message)); + } } catch (IOException e) { LOG.error("Can't take screenshot", e); } diff --git a/pom.xml b/pom.xml index 46b6200d..3f35f06d 100644 --- a/pom.xml +++ b/pom.xml @@ -125,7 +125,7 @@ limitations under the License. io.appium java-client - 2.1.0 + 4.1.2 net.lightbody.bmp