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

Commit

Permalink
Merge branch 'master' of https://github.com/Cognifide/bobcat
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikolaj Manski committed Mar 10, 2017
2 parents d033bb4 + bb276c2 commit 6e0eb5b
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -395,7 +387,7 @@ public Set<String> getContextHandles() {
}

@Override
public Response execute(String driverCommand, Map<String, ?> parameters) {
public Response execute(String driverCommand, Map parameters) {
return ((MobileDriver) super.getWrappedDriver()).execute(driverCommand, parameters);
}

Expand All @@ -409,11 +401,6 @@ public List<WebElement> 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);
Expand Down Expand Up @@ -441,6 +428,13 @@ public List<WebElement> 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) {
Expand All @@ -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<String, String> getAppStringMap() {
return ((HasAppStrings) super.getWrappedDriver()).getAppStringMap();
}

@Override
public String getAppStrings(String language) {
return ((HasAppStrings) super.getWrappedDriver()).getAppStrings(language);
public Map<String, String> 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<String, String> 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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -202,4 +204,9 @@ private boolean isKeys(CharSequence charSequence) {
private String getValue() {
return element.getAttribute("value");
}

@Override
public String getId() {
return UUID.randomUUID().toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> subreports;
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ limitations under the License.
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>2.1.0</version>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>net.lightbody.bmp</groupId>
Expand Down

0 comments on commit 6e0eb5b

Please sign in to comment.