From d75aa2697071595d4c31ea83fc9f265c9a1a1b78 Mon Sep 17 00:00:00 2001 From: Sergey Tikhomirov Date: Fri, 6 Jan 2017 19:04:08 +0300 Subject: [PATCH 1/9] #552 fix: - HasSessionDetails declares two additional methods now: String getPlatformName() and String getAutomationName() - these methods are re-implemented by AppiumDriver. - AppiumFieldDecorator refactoring --- .../io/appium/java_client/AppiumDriver.java | 45 ++++++++++++++++++- .../appium/java_client/HasSessionDetails.java | 11 +++++ .../JsonToAndroidElementConverter.java | 2 +- .../JsonToMobileElementConverter.java | 15 +++---- .../internal/JsonToIOSElementConverter.java | 2 +- .../pagefactory/AppiumFieldDecorator.java | 11 +++-- .../JsonToYouiEngineElementConverter.java | 2 +- 7 files changed, 69 insertions(+), 19 deletions(-) diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index b9bf03d03..c9bee2e0c 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -17,6 +17,9 @@ package io.appium.java_client; import static com.google.common.base.Preconditions.checkNotNull; +import static io.appium.java_client.remote.MobileCapabilityType.AUTOMATION_NAME; +import static io.appium.java_client.remote.MobileCapabilityType.PLATFORM_NAME; +import static java.util.Optional.ofNullable; import com.google.common.collect.ImmutableMap; @@ -71,6 +74,9 @@ public class AppiumDriver private URL remoteAddress; private RemoteLocationContext locationContext; private ExecuteMethod executeMethod; + private final String platformName; + private final String automationName; + /** * @param executor is an instance of {@link org.openqa.selenium.remote.HttpCommandExecutor} @@ -85,7 +91,34 @@ public AppiumDriver(HttpCommandExecutor executor, Capabilities capabilities) { locationContext = new RemoteLocationContext(executeMethod); super.setErrorHandler(errorHandler); this.remoteAddress = executor.getAddressOfRemoteServer(); - this.setElementConverter(new JsonToMobileElementConverter(this, getSessionDetails())); + final AppiumDriver driver = this; + + HasSessionDetails hasSessionDetails = new HasSessionDetails() { + @Override + public Response execute(String driverCommand, Map parameters) { + return driver.execute(driverCommand, parameters); + } + + @Override + public Response execute(String driverCommand) { + return driver.execute(driverCommand); + } + }; + + Object capabilityPlatform1 = getCapabilities().getCapability(PLATFORM_NAME); + Object capabilityAutomation1 = getCapabilities().getCapability(AUTOMATION_NAME); + + Object capabilityPlatform2 = capabilities.getCapability(PLATFORM_NAME); + Object capabilityAutomation2 = capabilities.getCapability(AUTOMATION_NAME); + + platformName = ofNullable(ofNullable(hasSessionDetails.getPlatformName()) + .orElse(capabilityPlatform1 != null ? String.valueOf(capabilityPlatform1) : null)) + .orElse(capabilityPlatform2 != null ? String.valueOf(capabilityPlatform2) : null); + automationName = ofNullable(ofNullable(hasSessionDetails.getAutomationName()) + .orElse(capabilityAutomation1 != null ? String.valueOf(capabilityAutomation1) : null)) + .orElse(capabilityAutomation2 != null ? String.valueOf(capabilityAutomation2) : null); + + this.setElementConverter(new JsonToMobileElementConverter(this, platformName, automationName)); } public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities) { @@ -137,7 +170,7 @@ public AppiumDriver(Capabilities desiredCapabilities) { protected static Capabilities substituteMobilePlatform(Capabilities originalCapabilities, String newPlatform) { DesiredCapabilities dc = new DesiredCapabilities(originalCapabilities); - dc.setCapability(MobileCapabilityType.PLATFORM_NAME, newPlatform); + dc.setCapability(PLATFORM_NAME, newPlatform); return dc; } @@ -384,4 +417,12 @@ public void zoom(int x, int y) { public URL getRemoteAddress() { return remoteAddress; } + + @Override public String getPlatformName() { + return platformName; + } + + @Override public String getAutomationName() { + return automationName; + } } diff --git a/src/main/java/io/appium/java_client/HasSessionDetails.java b/src/main/java/io/appium/java_client/HasSessionDetails.java index b17fe4530..000597fef 100644 --- a/src/main/java/io/appium/java_client/HasSessionDetails.java +++ b/src/main/java/io/appium/java_client/HasSessionDetails.java @@ -17,6 +17,7 @@ package io.appium.java_client; import static io.appium.java_client.MobileCommand.GET_SESSION; +import static java.util.Optional.of; import com.google.common.collect.ImmutableMap; @@ -39,4 +40,14 @@ default Map getSessionDetails() { default Object getSessionDetail(String detail) { return getSessionDetails().get(detail); } + + default String getPlatformName() { + Object platformName = getSessionDetail("platformName"); + return of(platformName != null ? String.valueOf(platformName) : null).orElse(null); + } + + default String getAutomationName() { + Object automationName = getSessionDetail("automationName"); + return of(automationName != null ? String.valueOf(automationName) : null).orElse(null); + } } diff --git a/src/main/java/io/appium/java_client/android/internal/JsonToAndroidElementConverter.java b/src/main/java/io/appium/java_client/android/internal/JsonToAndroidElementConverter.java index 7196065dd..78d7c98c0 100644 --- a/src/main/java/io/appium/java_client/android/internal/JsonToAndroidElementConverter.java +++ b/src/main/java/io/appium/java_client/android/internal/JsonToAndroidElementConverter.java @@ -29,7 +29,7 @@ public class JsonToAndroidElementConverter extends JsonToMobileElementConverter { public JsonToAndroidElementConverter(RemoteWebDriver driver) { - super(driver, null); + super(driver, null, null); } @Override protected MobileElement newMobileElement() { diff --git a/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java b/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java index 50d27b02c..ecfedba89 100644 --- a/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java +++ b/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java @@ -37,25 +37,20 @@ */ public class JsonToMobileElementConverter extends JsonToWebElementConverter { - private static final String AUTOMATION_NAME_PARAMETER = "automationName"; - private static final String PLATFORM_NAME_PARAMETER = "platformName"; - - protected final RemoteWebDriver driver; private final String automation; private final String platform; /** * @param driver an instance of {@link org.openqa.selenium.remote.RemoteWebDriver} subclass - * @param sessionParameters the map of current session parameters + * @param platform current session platform name + * @param automation current session automation name */ - public JsonToMobileElementConverter(RemoteWebDriver driver, Map sessionParameters) { + public JsonToMobileElementConverter(RemoteWebDriver driver, String platform, String automation) { super(driver); this.driver = driver; - automation = String.valueOf(sessionParameters - .get(AUTOMATION_NAME_PARAMETER)).toLowerCase(); - platform = String.valueOf(sessionParameters - .get(PLATFORM_NAME_PARAMETER)).toLowerCase(); + this.automation = String.valueOf(automation).toLowerCase(); + this.platform = String.valueOf(platform).toLowerCase(); } /** diff --git a/src/main/java/io/appium/java_client/ios/internal/JsonToIOSElementConverter.java b/src/main/java/io/appium/java_client/ios/internal/JsonToIOSElementConverter.java index d88b01779..f0d10f49b 100644 --- a/src/main/java/io/appium/java_client/ios/internal/JsonToIOSElementConverter.java +++ b/src/main/java/io/appium/java_client/ios/internal/JsonToIOSElementConverter.java @@ -29,7 +29,7 @@ public class JsonToIOSElementConverter extends JsonToMobileElementConverter { public JsonToIOSElementConverter(RemoteWebDriver driver) { - super(driver, null); + super(driver, null, null); } @Override protected MobileElement newMobileElement() { diff --git a/src/main/java/io/appium/java_client/pagefactory/AppiumFieldDecorator.java b/src/main/java/io/appium/java_client/pagefactory/AppiumFieldDecorator.java index ad07603e3..7ac6d1f0b 100644 --- a/src/main/java/io/appium/java_client/pagefactory/AppiumFieldDecorator.java +++ b/src/main/java/io/appium/java_client/pagefactory/AppiumFieldDecorator.java @@ -47,6 +47,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; /** * Default decorator for use with PageFactory. Will decorate 1) all of the @@ -72,7 +73,7 @@ public class AppiumFieldDecorator implements FieldDecorator { private final String automation; private final TimeOutDuration timeOutDuration; - private static String extractSessionData(WebDriver driver, String parameter) { + private static String extractSessionData(WebDriver driver, Supplier dataSupplier) { if (driver == null) { return null; } @@ -81,7 +82,7 @@ private static String extractSessionData(WebDriver driver, String parameter) { return null; } - return String.valueOf(HasSessionDetails.class.cast(driver).getSessionDetail(parameter)); + return String.valueOf(dataSupplier.get()); } public AppiumFieldDecorator(SearchContext context, long implicitlyWaitTimeOut, @@ -99,8 +100,10 @@ public AppiumFieldDecorator(SearchContext context, long implicitlyWaitTimeOut, */ public AppiumFieldDecorator(SearchContext context, TimeOutDuration timeOutDuration) { this.originalDriver = unpackWebDriverFromSearchContext(context); - platform = extractSessionData(originalDriver, "platformName"); - automation = extractSessionData(originalDriver, "automationName"); + platform = extractSessionData(originalDriver, () -> + HasSessionDetails.class.cast(originalDriver).getPlatformName()); + automation = extractSessionData(originalDriver, () -> + HasSessionDetails.class.cast(originalDriver).getAutomationName()); this.timeOutDuration = timeOutDuration; defaultElementFieldDecoracor = new DefaultFieldDecorator( diff --git a/src/main/java/io/appium/java_client/youiengine/internal/JsonToYouiEngineElementConverter.java b/src/main/java/io/appium/java_client/youiengine/internal/JsonToYouiEngineElementConverter.java index c1071c57c..01fc6a72c 100644 --- a/src/main/java/io/appium/java_client/youiengine/internal/JsonToYouiEngineElementConverter.java +++ b/src/main/java/io/appium/java_client/youiengine/internal/JsonToYouiEngineElementConverter.java @@ -29,7 +29,7 @@ @Deprecated public class JsonToYouiEngineElementConverter extends JsonToMobileElementConverter { public JsonToYouiEngineElementConverter(RemoteWebDriver driver) { - super(driver, null); + super(driver, null, null); } @Override From 57a17608fa1cdc3be7988a7d6c17d8f073c7e3b1 Mon Sep 17 00:00:00 2001 From: Sergey Tikhomirov Date: Thu, 12 Jan 2017 23:19:35 +0300 Subject: [PATCH 2/9] #552 fix: the work is going on. - HasSessionDetails declares the additional method isBrowser() - improving of element generating engine --- .../io/appium/java_client/AppiumDriver.java | 2 +- .../appium/java_client/HasSessionDetails.java | 12 ++- .../JsonToAndroidElementConverter.java | 2 +- .../JsonToMobileElementConverter.java | 23 +++-- .../internal/JsonToIOSElementConverter.java | 2 +- .../JsonToYouiEngineElementConverter.java | 2 +- .../android/AndroidElementGeneratingTest.java | 95 +++++++++++++++++++ .../localserver/StartingAppLocallyTest.java | 37 -------- 8 files changed, 122 insertions(+), 53 deletions(-) create mode 100644 src/test/java/io/appium/java_client/appium/element/generation/android/AndroidElementGeneratingTest.java diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index c9bee2e0c..8bf55ab9c 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -118,7 +118,7 @@ public Response execute(String driverCommand) { .orElse(capabilityAutomation1 != null ? String.valueOf(capabilityAutomation1) : null)) .orElse(capabilityAutomation2 != null ? String.valueOf(capabilityAutomation2) : null); - this.setElementConverter(new JsonToMobileElementConverter(this, platformName, automationName)); + this.setElementConverter(new JsonToMobileElementConverter(this, this)); } public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities) { diff --git a/src/main/java/io/appium/java_client/HasSessionDetails.java b/src/main/java/io/appium/java_client/HasSessionDetails.java index 000597fef..4cb292937 100644 --- a/src/main/java/io/appium/java_client/HasSessionDetails.java +++ b/src/main/java/io/appium/java_client/HasSessionDetails.java @@ -17,7 +17,7 @@ package io.appium.java_client; import static io.appium.java_client.MobileCommand.GET_SESSION; -import static java.util.Optional.of; +import static java.util.Optional.ofNullable; import com.google.common.collect.ImmutableMap; @@ -43,11 +43,17 @@ default Object getSessionDetail(String detail) { default String getPlatformName() { Object platformName = getSessionDetail("platformName"); - return of(platformName != null ? String.valueOf(platformName) : null).orElse(null); + return ofNullable(platformName != null ? String.valueOf(platformName) : null).orElse(null); } default String getAutomationName() { Object automationName = getSessionDetail("automationName"); - return of(automationName != null ? String.valueOf(automationName) : null).orElse(null); + return ofNullable(automationName != null ? String.valueOf(automationName) : null).orElse(null); + } + + default boolean isBrowser() { + Object browserName = getSessionDetail("browserName"); + return ofNullable(browserName != null ? String + .valueOf(browserName) : null).orElse(null) != null; } } diff --git a/src/main/java/io/appium/java_client/android/internal/JsonToAndroidElementConverter.java b/src/main/java/io/appium/java_client/android/internal/JsonToAndroidElementConverter.java index 78d7c98c0..7196065dd 100644 --- a/src/main/java/io/appium/java_client/android/internal/JsonToAndroidElementConverter.java +++ b/src/main/java/io/appium/java_client/android/internal/JsonToAndroidElementConverter.java @@ -29,7 +29,7 @@ public class JsonToAndroidElementConverter extends JsonToMobileElementConverter { public JsonToAndroidElementConverter(RemoteWebDriver driver) { - super(driver, null, null); + super(driver, null); } @Override protected MobileElement newMobileElement() { diff --git a/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java b/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java index ecfedba89..0fc67ee08 100644 --- a/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java +++ b/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java @@ -22,6 +22,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import io.appium.java_client.HasSessionDetails; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.remote.RemoteWebElement; @@ -38,19 +39,16 @@ public class JsonToMobileElementConverter extends JsonToWebElementConverter { protected final RemoteWebDriver driver; - private final String automation; - private final String platform; + private final HasSessionDetails hasSessionDetails; /** * @param driver an instance of {@link org.openqa.selenium.remote.RemoteWebDriver} subclass - * @param platform current session platform name - * @param automation current session automation name + * @param hasSessionDetails object that has session details */ - public JsonToMobileElementConverter(RemoteWebDriver driver, String platform, String automation) { + public JsonToMobileElementConverter(RemoteWebDriver driver, HasSessionDetails hasSessionDetails) { super(driver); this.driver = driver; - this.automation = String.valueOf(automation).toLowerCase(); - this.platform = String.valueOf(platform).toLowerCase(); + this.hasSessionDetails = hasSessionDetails; } /** @@ -88,8 +86,15 @@ public Object apply(Object result) { } protected RemoteWebElement newMobileElement() { - Class target = - getElementClass(platform, automation); + Class target; + if (hasSessionDetails.isBrowser()) { + target = getElementClass(null, null); + } + else { + target = getElementClass(hasSessionDetails.getPlatformName(), + hasSessionDetails.getAutomationName()); + } + try { Constructor constructor = target.getDeclaredConstructor(); constructor.setAccessible(true); diff --git a/src/main/java/io/appium/java_client/ios/internal/JsonToIOSElementConverter.java b/src/main/java/io/appium/java_client/ios/internal/JsonToIOSElementConverter.java index f0d10f49b..d88b01779 100644 --- a/src/main/java/io/appium/java_client/ios/internal/JsonToIOSElementConverter.java +++ b/src/main/java/io/appium/java_client/ios/internal/JsonToIOSElementConverter.java @@ -29,7 +29,7 @@ public class JsonToIOSElementConverter extends JsonToMobileElementConverter { public JsonToIOSElementConverter(RemoteWebDriver driver) { - super(driver, null, null); + super(driver, null); } @Override protected MobileElement newMobileElement() { diff --git a/src/main/java/io/appium/java_client/youiengine/internal/JsonToYouiEngineElementConverter.java b/src/main/java/io/appium/java_client/youiengine/internal/JsonToYouiEngineElementConverter.java index 01fc6a72c..c1071c57c 100644 --- a/src/main/java/io/appium/java_client/youiengine/internal/JsonToYouiEngineElementConverter.java +++ b/src/main/java/io/appium/java_client/youiengine/internal/JsonToYouiEngineElementConverter.java @@ -29,7 +29,7 @@ @Deprecated public class JsonToYouiEngineElementConverter extends JsonToMobileElementConverter { public JsonToYouiEngineElementConverter(RemoteWebDriver driver) { - super(driver, null, null); + super(driver, null); } @Override diff --git a/src/test/java/io/appium/java_client/appium/element/generation/android/AndroidElementGeneratingTest.java b/src/test/java/io/appium/java_client/appium/element/generation/android/AndroidElementGeneratingTest.java new file mode 100644 index 000000000..d06668107 --- /dev/null +++ b/src/test/java/io/appium/java_client/appium/element/generation/android/AndroidElementGeneratingTest.java @@ -0,0 +1,95 @@ +package io.appium.java_client.appium.element.generation.android; + +import io.appium.java_client.AppiumDriver; +import io.appium.java_client.MobileBy; +import io.appium.java_client.android.AndroidElement; +import io.appium.java_client.remote.AndroidMobileCapabilityType; +import io.appium.java_client.remote.MobileBrowserType; +import io.appium.java_client.remote.MobileCapabilityType; +import io.appium.java_client.service.local.AppiumServiceBuilder; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.remote.RemoteWebElement; + +import java.io.File; + +import static org.junit.Assert.assertTrue; + +public class AndroidElementGeneratingTest { + + @Test public void whenAndroidNativeAppIsLaunched() { + File appDir = new File("src/test/java/io/appium/java_client"); + File app = new File(appDir, "ApiDemos-debug.apk"); + + DesiredCapabilities serverCapabilities = new DesiredCapabilities(); + serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android"); + serverCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); + serverCapabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); + + AppiumServiceBuilder builder = new AppiumServiceBuilder().withCapabilities(serverCapabilities); + + DesiredCapabilities clientCapabilities = new DesiredCapabilities(); + clientCapabilities.setCapability(MobileCapabilityType.FULL_RESET, true); + clientCapabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 60); + + AppiumDriver driver = new AppiumDriver<>(builder, clientCapabilities); + try { + WebElement element = driver.findElement(MobileBy + .AndroidUIAutomator("new UiSelector().clickable(true)")); + assertTrue(element.getClass().equals(AndroidElement.class)); + } finally { + driver.quit(); + } + } + + @Test public void whenAndroidHybridAppIsLaunched() { + File appDir = new File("src/test/java/io/appium/java_client"); + File app = new File(appDir, "ApiDemos-debug.apk"); + + DesiredCapabilities serverCapabilities = new DesiredCapabilities(); + serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android"); + serverCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); + serverCapabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); + + AppiumServiceBuilder builder = new AppiumServiceBuilder().withCapabilities(serverCapabilities); + + DesiredCapabilities clientCapabilities = new DesiredCapabilities(); + clientCapabilities + .setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "io.appium.android.apis"); + clientCapabilities + .setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ".view.WebView1"); + + AppiumDriver driver = new AppiumDriver<>(builder, clientCapabilities); + try { + driver.context("WEBVIEW_io.appium.android.apis"); + WebElement element = driver.findElement(By.tagName("a")); + assertTrue(element.getClass().equals(RemoteWebElement.class)); + } finally { + driver.quit(); + } + } + + @Test public void whenAndroidBrowserIsLaunched() { + DesiredCapabilities serverCapabilities = new DesiredCapabilities(); + serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android"); + serverCapabilities.setCapability(MobileCapabilityType.BROWSER_NAME, MobileBrowserType.BROWSER); + + AppiumServiceBuilder builder = new AppiumServiceBuilder().withCapabilities(serverCapabilities); + + DesiredCapabilities clientCapabilities = new DesiredCapabilities(); + clientCapabilities + .setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); + + AppiumDriver driver = new AppiumDriver<>(builder, clientCapabilities); + try { + driver.get("https://www.google.com"); + WebElement element = driver.findElementByClassName("gsfi"); + assertTrue(element.getClass().equals(RemoteWebElement.class)); + } + finally { + driver.quit(); + } + } +} diff --git a/src/test/java/io/appium/java_client/localserver/StartingAppLocallyTest.java b/src/test/java/io/appium/java_client/localserver/StartingAppLocallyTest.java index 40a1c1917..02263e914 100644 --- a/src/test/java/io/appium/java_client/localserver/StartingAppLocallyTest.java +++ b/src/test/java/io/appium/java_client/localserver/StartingAppLocallyTest.java @@ -83,43 +83,6 @@ public class StartingAppLocallyTest { } } - @Test public void startingAndroidAppWithCapabilitiesOnServerSideTest() { - File appDir = new File("src/test/java/io/appium/java_client"); - File app = new File(appDir, "ApiDemos-debug.apk"); - - File pageFactoryDir = new File("src/test/java/io/appium/java_client/pagefactory_tests"); - File chrome = new File(pageFactoryDir, "chromedriver.exe"); - - DesiredCapabilities serverCapabilities = new DesiredCapabilities(); - serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android"); - serverCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); - serverCapabilities.setCapability(MobileCapabilityType.FULL_RESET, true); - serverCapabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 60); - serverCapabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); - serverCapabilities.setCapability(AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE, - chrome.getAbsolutePath()); - - AppiumServiceBuilder builder = - new AppiumServiceBuilder().withCapabilities(serverCapabilities); - - DesiredCapabilities clientCapabilities = new DesiredCapabilities(); - clientCapabilities - .setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "io.appium.android.apis"); - clientCapabilities - .setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ".view.WebView1"); - - AndroidDriver driver = new AndroidDriver<>(builder, clientCapabilities); - try { - Capabilities caps = driver.getCapabilities(); - - assertEquals(true, caps.getCapability(MobileCapabilityType.PLATFORM_NAME) - .equals(MobilePlatform.ANDROID)); - assertNotEquals(null, caps.getCapability(MobileCapabilityType.DEVICE_NAME)); - } finally { - driver.quit(); - } - } - @Test public void startingAndroidAppWithCapabilitiesAndFlagsOnServerSideTest() { File appDir = new File("src/test/java/io/appium/java_client"); File app = new File(appDir, "ApiDemos-debug.apk"); From b945ba654e106f92e80364d4932419c02603dda6 Mon Sep 17 00:00:00 2001 From: Sergey Tikhomirov Date: Sat, 14 Jan 2017 00:36:37 +0300 Subject: [PATCH 3/9] #552 fix: iOS - test - IOSElementGenerationTest was designed - AndroidElementGeneratingTest was re-designed --- .../generation/BaseElementGenerationTest.java | 42 ++++++ .../android/AndroidElementGeneratingTest.java | 129 ++++++++--------- .../ios/IOSElementGenerationTest.java | 132 ++++++++++++++++++ .../localserver/StartingAppLocallyTest.java | 26 ---- 4 files changed, 233 insertions(+), 96 deletions(-) create mode 100644 src/test/java/io/appium/java_client/appium/element/generation/BaseElementGenerationTest.java create mode 100644 src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java diff --git a/src/test/java/io/appium/java_client/appium/element/generation/BaseElementGenerationTest.java b/src/test/java/io/appium/java_client/appium/element/generation/BaseElementGenerationTest.java new file mode 100644 index 000000000..39254b4ab --- /dev/null +++ b/src/test/java/io/appium/java_client/appium/element/generation/BaseElementGenerationTest.java @@ -0,0 +1,42 @@ +package io.appium.java_client.appium.element.generation; + +import static org.junit.Assert.assertTrue; + +import io.appium.java_client.AppiumDriver; +import io.appium.java_client.service.local.AppiumServiceBuilder; +import org.junit.After; +import org.openqa.selenium.By; +import org.openqa.selenium.Capabilities; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.DesiredCapabilities; + +import java.util.function.BiPredicate; +import java.util.function.Supplier; + +public class BaseElementGenerationTest { + protected AppiumDriver driver; + protected final BiPredicate> commonPredicate = (by, aClass) -> { + WebElement element = driver.findElement(by); + assertTrue(element.getClass().equals(aClass)); + return true; + }; + + @After + public void tearDown() { + if (driver != null) { + driver.quit(); + } + driver = null; + } + + protected boolean check(Supplier serverCapabilitiesSupplier, + Supplier clientCapabilitiesSupplier, + BiPredicate> filter, + By by, Class clazz) { + AppiumServiceBuilder builder = new AppiumServiceBuilder() + .withCapabilities(serverCapabilitiesSupplier.get()); + driver = new AppiumDriver<>(builder, clientCapabilitiesSupplier.get());; + return filter.test(by, clazz); + } + +} diff --git a/src/test/java/io/appium/java_client/appium/element/generation/android/AndroidElementGeneratingTest.java b/src/test/java/io/appium/java_client/appium/element/generation/android/AndroidElementGeneratingTest.java index d06668107..935651166 100644 --- a/src/test/java/io/appium/java_client/appium/element/generation/android/AndroidElementGeneratingTest.java +++ b/src/test/java/io/appium/java_client/appium/element/generation/android/AndroidElementGeneratingTest.java @@ -1,95 +1,84 @@ package io.appium.java_client.appium.element.generation.android; -import io.appium.java_client.AppiumDriver; -import io.appium.java_client.MobileBy; +import static io.appium.java_client.MobileBy.AndroidUIAutomator; +import static org.junit.Assert.assertTrue; +import static org.openqa.selenium.By.className; +import static org.openqa.selenium.By.tagName; + import io.appium.java_client.android.AndroidElement; +import io.appium.java_client.appium.element.generation.BaseElementGenerationTest; import io.appium.java_client.remote.AndroidMobileCapabilityType; import io.appium.java_client.remote.MobileBrowserType; import io.appium.java_client.remote.MobileCapabilityType; -import io.appium.java_client.service.local.AppiumServiceBuilder; +import io.appium.java_client.remote.MobilePlatform; import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebElement; import java.io.File; +import java.util.function.Supplier; -import static org.junit.Assert.assertTrue; - -public class AndroidElementGeneratingTest { - - @Test public void whenAndroidNativeAppIsLaunched() { - File appDir = new File("src/test/java/io/appium/java_client"); - File app = new File(appDir, "ApiDemos-debug.apk"); +public class AndroidElementGeneratingTest extends BaseElementGenerationTest { + private final File app = new File(new File("src/test/java/io/appium/java_client"), + "ApiDemos-debug.apk"); + private final Supplier serverCapabilitiesSupplier = () -> { DesiredCapabilities serverCapabilities = new DesiredCapabilities(); - serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android"); + serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID); serverCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); serverCapabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); + return serverCapabilities; + }; - AppiumServiceBuilder builder = new AppiumServiceBuilder().withCapabilities(serverCapabilities); - - DesiredCapabilities clientCapabilities = new DesiredCapabilities(); - clientCapabilities.setCapability(MobileCapabilityType.FULL_RESET, true); - clientCapabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 60); - - AppiumDriver driver = new AppiumDriver<>(builder, clientCapabilities); - try { - WebElement element = driver.findElement(MobileBy - .AndroidUIAutomator("new UiSelector().clickable(true)")); - assertTrue(element.getClass().equals(AndroidElement.class)); - } finally { - driver.quit(); - } + @Test public void whenAndroidNativeAppIsLaunched() { + assertTrue(check(serverCapabilitiesSupplier, + () -> { + DesiredCapabilities clientCapabilities = new DesiredCapabilities(); + clientCapabilities.setCapability(MobileCapabilityType.FULL_RESET, true); + clientCapabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 60); + return clientCapabilities; + }, + commonPredicate, + AndroidUIAutomator("new UiSelector().clickable(true)"), + AndroidElement.class)); } @Test public void whenAndroidHybridAppIsLaunched() { - File appDir = new File("src/test/java/io/appium/java_client"); - File app = new File(appDir, "ApiDemos-debug.apk"); - - DesiredCapabilities serverCapabilities = new DesiredCapabilities(); - serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android"); - serverCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); - serverCapabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); - - AppiumServiceBuilder builder = new AppiumServiceBuilder().withCapabilities(serverCapabilities); - - DesiredCapabilities clientCapabilities = new DesiredCapabilities(); - clientCapabilities - .setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "io.appium.android.apis"); - clientCapabilities - .setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ".view.WebView1"); - - AppiumDriver driver = new AppiumDriver<>(builder, clientCapabilities); - try { - driver.context("WEBVIEW_io.appium.android.apis"); - WebElement element = driver.findElement(By.tagName("a")); - assertTrue(element.getClass().equals(RemoteWebElement.class)); - } finally { - driver.quit(); - } + assertTrue(check(serverCapabilitiesSupplier, + () -> { + DesiredCapabilities clientCapabilities = new DesiredCapabilities(); + clientCapabilities + .setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "io.appium.android.apis"); + clientCapabilities + .setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ".view.WebView1"); + return clientCapabilities; + }, + (by, aClass) -> { + driver.context("WEBVIEW_io.appium.android.apis"); + return commonPredicate.test(by, aClass); + }, + tagName("a"), + RemoteWebElement.class)); } @Test public void whenAndroidBrowserIsLaunched() { - DesiredCapabilities serverCapabilities = new DesiredCapabilities(); - serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android"); - serverCapabilities.setCapability(MobileCapabilityType.BROWSER_NAME, MobileBrowserType.BROWSER); - - AppiumServiceBuilder builder = new AppiumServiceBuilder().withCapabilities(serverCapabilities); - - DesiredCapabilities clientCapabilities = new DesiredCapabilities(); - clientCapabilities - .setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); - - AppiumDriver driver = new AppiumDriver<>(builder, clientCapabilities); - try { - driver.get("https://www.google.com"); - WebElement element = driver.findElementByClassName("gsfi"); - assertTrue(element.getClass().equals(RemoteWebElement.class)); - } - finally { - driver.quit(); - } + assertTrue(check(() -> { + DesiredCapabilities serverCapabilities = new DesiredCapabilities(); + serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID); + serverCapabilities.setCapability(MobileCapabilityType.BROWSER_NAME, MobileBrowserType.BROWSER); + return serverCapabilities; + }, + () -> { + DesiredCapabilities clientCapabilities = new DesiredCapabilities(); + clientCapabilities + .setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); + return clientCapabilities; + }, + (by, aClass) -> { + driver.get("https://www.google.com"); + return commonPredicate.test(by, aClass); + }, + className("gsfi"), + RemoteWebElement.class)); } } diff --git a/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java b/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java new file mode 100644 index 000000000..f5312bf80 --- /dev/null +++ b/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java @@ -0,0 +1,132 @@ +package io.appium.java_client.appium.element.generation.ios; + +import static io.appium.java_client.MobileBy.IosUIAutomation; +import static org.junit.Assert.assertTrue; +import static org.openqa.selenium.By.className; +import static org.openqa.selenium.By.id; + +import io.appium.java_client.appium.element.generation.BaseElementGenerationTest; +import io.appium.java_client.ios.IOSElement; +import io.appium.java_client.remote.IOSMobileCapabilityType; +import io.appium.java_client.remote.MobileBrowserType; +import io.appium.java_client.remote.MobileCapabilityType; +import io.appium.java_client.remote.MobilePlatform; +import org.junit.Test; +import org.openqa.selenium.Capabilities; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.remote.RemoteWebElement; + +import java.io.File; +import java.util.function.Function; +import java.util.function.Supplier; + +public class IOSElementGenerationTest extends BaseElementGenerationTest { + + private final File testApp = new File(new File("src/test/java/io/appium/java_client"), + "TestApp.app.zip"); + + private final File webViewApp = new File(new File("src/test/java/io/appium/java_client"), + "WebViewApp.app.zip"); + + private Supplier serverAppCapabilitiesSupplier = () -> { + DesiredCapabilities serverCapabilities = new DesiredCapabilities(); + serverCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator"); + serverCapabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, + 500000); //some environment is too slow + serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9.2"); + serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS); + return serverCapabilities; + }; + + private Function> appFileSupplierFunction = file -> { + final DesiredCapabilities clientCapabilities = new DesiredCapabilities(); + return () -> { + clientCapabilities.setCapability(MobileCapabilityType.APP, file.getAbsolutePath()); + return clientCapabilities; + }; + }; + + private final Supplier serverBrowserCapabilitiesSupplier = () -> { + DesiredCapabilities serverCapabilities = new DesiredCapabilities(); + serverCapabilities.setCapability(MobileCapabilityType.BROWSER_NAME, MobileBrowserType.SAFARI); + serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9.2"); + serverCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator"); + //sometimes environment has performance problems + serverCapabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, 500000); + return serverCapabilities; + }; + + private final Supplier clientBrowserCapabilitiesSupplier = () -> { + DesiredCapabilities clientCapabilities = new DesiredCapabilities(); + clientCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS); + return clientCapabilities; + }; + + @Test + public void whenIOSNativeAppIsLaunched() { + assertTrue(check(serverAppCapabilitiesSupplier, + appFileSupplierFunction.apply(testApp), + commonPredicate, + IosUIAutomation(".elements().withName(\"Answer\")"), + IOSElement.class)); + } + + @Test public void whenIOSHybridAppIsLaunched() throws Exception { + assertTrue(check(serverAppCapabilitiesSupplier, + appFileSupplierFunction.apply(webViewApp), + (by, aClass) -> { + IOSElement element1 = (IOSElement) driver + .findElementByXPath("//UIATextField[@value='Enter URL']"); + element1.sendKeys("www.google.com"); + driver.findElementByClassName("UIAButton").click(); + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + driver.getContextHandles().forEach((handle) -> { + if (handle.contains("WEBVIEW")) { + driver.context(handle); + } + }); + return commonPredicate.test(by, aClass); + }, + className("gsfi"), + RemoteWebElement.class)); + } + + @Test public void whenIOSBrowserIsLaunched() { + assertTrue(check(serverBrowserCapabilitiesSupplier, + clientBrowserCapabilitiesSupplier, + commonPredicate, + className("gsfi"), + RemoteWebElement.class)); + } + + @Test + public void whenIOSNativeAppIsLaunched2() { + assertTrue(check( + () -> { + DesiredCapabilities serverCapabilities = serverAppCapabilitiesSupplier.get(); + serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.1"); + return serverCapabilities; + }, + appFileSupplierFunction.apply(testApp), + commonPredicate, + id("IntegerA"), + IOSElement.class)); + } + + @Test public void whenIOSBrowserIsLaunched2() { + assertTrue(check( + () -> { + DesiredCapabilities serverCapabilities = serverBrowserCapabilitiesSupplier.get(); + serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.1"); + return serverCapabilities; + }, + clientBrowserCapabilitiesSupplier, + commonPredicate, + className("gsfi"), + RemoteWebElement.class)); + } +} diff --git a/src/test/java/io/appium/java_client/localserver/StartingAppLocallyTest.java b/src/test/java/io/appium/java_client/localserver/StartingAppLocallyTest.java index 02263e914..a7c037bf3 100644 --- a/src/test/java/io/appium/java_client/localserver/StartingAppLocallyTest.java +++ b/src/test/java/io/appium/java_client/localserver/StartingAppLocallyTest.java @@ -179,32 +179,6 @@ public class StartingAppLocallyTest { } } - @Test public void startingIOSAppWithCapabilitiesOnServerSideTest() { - DesiredCapabilities serverCapabilities = new DesiredCapabilities(); - serverCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator"); - serverCapabilities.setCapability(IOSMobileCapabilityType.LAUNCH_TIMEOUT, - 500000); //some environment is too slow - serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9.2"); - - File appDir = new File("src/test/java/io/appium/java_client"); - File app = new File(appDir, "UICatalog.app.zip"); - DesiredCapabilities clientCapabilities = new DesiredCapabilities(); - clientCapabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); - - AppiumServiceBuilder builder = - new AppiumServiceBuilder().withCapabilities(serverCapabilities); - - IOSDriver driver = new IOSDriver<>(builder, clientCapabilities); - try { - Capabilities caps = driver.getCapabilities(); - assertEquals(true, - caps.getCapability(MobileCapabilityType.PLATFORM_NAME).equals(MobilePlatform.IOS)); - assertNotEquals(null, caps.getCapability(MobileCapabilityType.DEVICE_NAME)); - } finally { - driver.quit(); - } - } - @Test public void startingIOSAppWithCapabilitiesAndFlagsOnServerSideTest() { DesiredCapabilities serverCapabilities = new DesiredCapabilities(); serverCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator"); From ca06e97aecd1bac2ac04a723d29263867d437064 Mon Sep 17 00:00:00 2001 From: Sergey Tikhomirov Date: Sat, 14 Jan 2017 22:42:36 +0300 Subject: [PATCH 4/9] improvement of WebView tests --- .../appium/java_client/android/AndroidContextTest.java | 2 ++ .../io/appium/java_client/ios/BaseIOSWebViewTest.java | 9 +++++++++ .../java/io/appium/java_client/ios/IOSContextTest.java | 10 +++++++--- .../java/io/appium/java_client/ios/IOSWebViewTest.java | 9 ++------- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/test/java/io/appium/java_client/android/AndroidContextTest.java b/src/test/java/io/appium/java_client/android/AndroidContextTest.java index 363f6a139..2002582f4 100644 --- a/src/test/java/io/appium/java_client/android/AndroidContextTest.java +++ b/src/test/java/io/appium/java_client/android/AndroidContextTest.java @@ -17,6 +17,7 @@ package io.appium.java_client.android; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import io.appium.java_client.NoSuchContextException; import org.junit.BeforeClass; @@ -46,6 +47,7 @@ public class AndroidContextTest extends BaseAndroidTest { @Test(expected = NoSuchContextException.class) public void testContextError() { driver.context("Planet of the Ape-ium"); + assertTrue(driver.getContext().equals("Planet of the Ape-ium")); } } diff --git a/src/test/java/io/appium/java_client/ios/BaseIOSWebViewTest.java b/src/test/java/io/appium/java_client/ios/BaseIOSWebViewTest.java index 183a4e362..c83262c71 100644 --- a/src/test/java/io/appium/java_client/ios/BaseIOSWebViewTest.java +++ b/src/test/java/io/appium/java_client/ios/BaseIOSWebViewTest.java @@ -46,4 +46,13 @@ public class BaseIOSWebViewTest extends BaseIOSTest { capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath()); driver = new IOSDriver<>(service.getUrl(), capabilities); } + + protected void findAndSwitchToWebView() throws InterruptedException { + Thread.sleep(10000); + driver.getContextHandles().forEach((handle) -> { + if (handle.contains("WEBVIEW")) { + driver.context(handle); + } + }); + } } diff --git a/src/test/java/io/appium/java_client/ios/IOSContextTest.java b/src/test/java/io/appium/java_client/ios/IOSContextTest.java index b99618bc0..55b53cbff 100644 --- a/src/test/java/io/appium/java_client/ios/IOSContextTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSContextTest.java @@ -16,7 +16,10 @@ package io.appium.java_client.ios; +import static org.hamcrest.core.StringContains.containsString; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; import io.appium.java_client.NoSuchContextException; import org.junit.Test; @@ -31,14 +34,15 @@ public class IOSContextTest extends BaseIOSWebViewTest { assertEquals(driver.getContextHandles().size(), 2); } - @Test public void testSwitchContext() { + @Test public void testSwitchContext() throws InterruptedException { driver.getContextHandles(); - driver.context("WEBVIEW_1"); - assertEquals(driver.getContext(), "WEBVIEW_1"); + findAndSwitchToWebView(); + assertThat(driver.getContext(), containsString("WEBVIEW")); driver.context("NATIVE_APP"); } @Test(expected = NoSuchContextException.class) public void testContextError() { driver.context("Planet of the Ape-ium"); + assertTrue(driver.getContext().equals("Planet of the Ape-ium")); } } diff --git a/src/test/java/io/appium/java_client/ios/IOSWebViewTest.java b/src/test/java/io/appium/java_client/ios/IOSWebViewTest.java index 9217aedb4..ddacf8d3f 100644 --- a/src/test/java/io/appium/java_client/ios/IOSWebViewTest.java +++ b/src/test/java/io/appium/java_client/ios/IOSWebViewTest.java @@ -8,16 +8,11 @@ public class IOSWebViewTest extends BaseIOSWebViewTest { - @Test public void webViewPageTestCase() throws Throwable { + @Test public void webViewPageTestCase() throws InterruptedException { driver.findElementByXPath("//UIATextField[@value='Enter URL']") .sendKeys("www.google.com"); driver.findElementByClassName("UIAButton").click(); - Thread.sleep(10000); - driver.getContextHandles().forEach((handle) -> { - if (handle.contains("WEBVIEW")) { - driver.context(handle); - } - }); + findAndSwitchToWebView(); WebElement el = driver.findElementByClassName("gsfi"); el.sendKeys("Appium"); el.sendKeys(Keys.ENTER); From 3b1618474899748917b377a5d0e0b825840b23df Mon Sep 17 00:00:00 2001 From: Sergey Tikhomirov Date: Wed, 18 Jan 2017 11:29:38 +0300 Subject: [PATCH 5/9] Checkstyle issue fix --- .../appium/java_client/HasSessionDetails.java | 3 + .../JsonToMobileElementConverter.java | 3 +- .../generation/BaseElementGenerationTest.java | 2 +- .../android/AndroidElementGeneratingTest.java | 70 ++++++++----------- .../ios/IOSElementGenerationTest.java | 63 +++++++---------- 5 files changed, 58 insertions(+), 83 deletions(-) diff --git a/src/main/java/io/appium/java_client/HasSessionDetails.java b/src/main/java/io/appium/java_client/HasSessionDetails.java index 4cb292937..e4182d66b 100644 --- a/src/main/java/io/appium/java_client/HasSessionDetails.java +++ b/src/main/java/io/appium/java_client/HasSessionDetails.java @@ -51,6 +51,9 @@ default String getAutomationName() { return ofNullable(automationName != null ? String.valueOf(automationName) : null).orElse(null); } + /** + * @return is focus on browser or on native content. + */ default boolean isBrowser() { Object browserName = getSessionDetail("browserName"); return ofNullable(browserName != null ? String diff --git a/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java b/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java index 0fc67ee08..a2bb01437 100644 --- a/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java +++ b/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java @@ -89,8 +89,7 @@ protected RemoteWebElement newMobileElement() { Class target; if (hasSessionDetails.isBrowser()) { target = getElementClass(null, null); - } - else { + } else { target = getElementClass(hasSessionDetails.getPlatformName(), hasSessionDetails.getAutomationName()); } diff --git a/src/test/java/io/appium/java_client/appium/element/generation/BaseElementGenerationTest.java b/src/test/java/io/appium/java_client/appium/element/generation/BaseElementGenerationTest.java index 39254b4ab..0e4bb6a7f 100644 --- a/src/test/java/io/appium/java_client/appium/element/generation/BaseElementGenerationTest.java +++ b/src/test/java/io/appium/java_client/appium/element/generation/BaseElementGenerationTest.java @@ -35,7 +35,7 @@ protected boolean check(Supplier serverCapabilitiesSupplier By by, Class clazz) { AppiumServiceBuilder builder = new AppiumServiceBuilder() .withCapabilities(serverCapabilitiesSupplier.get()); - driver = new AppiumDriver<>(builder, clientCapabilitiesSupplier.get());; + driver = new AppiumDriver<>(builder, clientCapabilitiesSupplier.get()); return filter.test(by, clazz); } diff --git a/src/test/java/io/appium/java_client/appium/element/generation/android/AndroidElementGeneratingTest.java b/src/test/java/io/appium/java_client/appium/element/generation/android/AndroidElementGeneratingTest.java index 935651166..ae2d11129 100644 --- a/src/test/java/io/appium/java_client/appium/element/generation/android/AndroidElementGeneratingTest.java +++ b/src/test/java/io/appium/java_client/appium/element/generation/android/AndroidElementGeneratingTest.java @@ -31,54 +31,40 @@ public class AndroidElementGeneratingTest extends BaseElementGenerationTest { }; @Test public void whenAndroidNativeAppIsLaunched() { - assertTrue(check(serverCapabilitiesSupplier, - () -> { - DesiredCapabilities clientCapabilities = new DesiredCapabilities(); - clientCapabilities.setCapability(MobileCapabilityType.FULL_RESET, true); - clientCapabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 60); - return clientCapabilities; - }, - commonPredicate, - AndroidUIAutomator("new UiSelector().clickable(true)"), - AndroidElement.class)); + assertTrue(check(serverCapabilitiesSupplier, () -> { + DesiredCapabilities clientCapabilities = new DesiredCapabilities(); + clientCapabilities.setCapability(MobileCapabilityType.FULL_RESET, true); + clientCapabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 60); + return clientCapabilities; + }, commonPredicate, AndroidUIAutomator("new UiSelector().clickable(true)"), + AndroidElement.class)); } @Test public void whenAndroidHybridAppIsLaunched() { - assertTrue(check(serverCapabilitiesSupplier, - () -> { - DesiredCapabilities clientCapabilities = new DesiredCapabilities(); - clientCapabilities - .setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "io.appium.android.apis"); - clientCapabilities - .setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ".view.WebView1"); - return clientCapabilities; - }, - (by, aClass) -> { - driver.context("WEBVIEW_io.appium.android.apis"); - return commonPredicate.test(by, aClass); - }, - tagName("a"), - RemoteWebElement.class)); + assertTrue(check(serverCapabilitiesSupplier, () -> { + DesiredCapabilities clientCapabilities = new DesiredCapabilities(); + clientCapabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "io.appium.android.apis"); + clientCapabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ".view.WebView1"); + return clientCapabilities; + }, (by, aClass) -> { + driver.context("WEBVIEW_io.appium.android.apis"); + return commonPredicate.test(by, aClass); + }, tagName("a"), RemoteWebElement.class)); } @Test public void whenAndroidBrowserIsLaunched() { assertTrue(check(() -> { - DesiredCapabilities serverCapabilities = new DesiredCapabilities(); - serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID); - serverCapabilities.setCapability(MobileCapabilityType.BROWSER_NAME, MobileBrowserType.BROWSER); - return serverCapabilities; - }, - () -> { - DesiredCapabilities clientCapabilities = new DesiredCapabilities(); - clientCapabilities - .setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); - return clientCapabilities; - }, - (by, aClass) -> { - driver.get("https://www.google.com"); - return commonPredicate.test(by, aClass); - }, - className("gsfi"), - RemoteWebElement.class)); + DesiredCapabilities serverCapabilities = new DesiredCapabilities(); + serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID); + serverCapabilities.setCapability(MobileCapabilityType.BROWSER_NAME, MobileBrowserType.BROWSER); + return serverCapabilities; + }, () -> { + DesiredCapabilities clientCapabilities = new DesiredCapabilities(); + clientCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); + return clientCapabilities; + }, (by, aClass) -> { + driver.get("https://www.google.com"); + return commonPredicate.test(by, aClass); + }, className("gsfi"), RemoteWebElement.class)); } } diff --git a/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java b/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java index f5312bf80..20137bb5f 100644 --- a/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java +++ b/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java @@ -74,25 +74,22 @@ public void whenIOSNativeAppIsLaunched() { @Test public void whenIOSHybridAppIsLaunched() throws Exception { assertTrue(check(serverAppCapabilitiesSupplier, appFileSupplierFunction.apply(webViewApp), - (by, aClass) -> { - IOSElement element1 = (IOSElement) driver - .findElementByXPath("//UIATextField[@value='Enter URL']"); - element1.sendKeys("www.google.com"); - driver.findElementByClassName("UIAButton").click(); - try { - Thread.sleep(10000); - } catch (InterruptedException e) { - e.printStackTrace(); + (by, aClass) -> { + IOSElement element1 = (IOSElement) driver.findElementByXPath("//UIATextField[@value='Enter URL']"); + element1.sendKeys("www.google.com"); + driver.findElementByClassName("UIAButton").click(); + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + driver.getContextHandles().forEach((handle) -> { + if (handle.contains("WEBVIEW")) { + driver.context(handle); } - driver.getContextHandles().forEach((handle) -> { - if (handle.contains("WEBVIEW")) { - driver.context(handle); - } - }); - return commonPredicate.test(by, aClass); - }, - className("gsfi"), - RemoteWebElement.class)); + }); + return commonPredicate.test(by, aClass); + }, className("gsfi"), RemoteWebElement.class)); } @Test public void whenIOSBrowserIsLaunched() { @@ -105,28 +102,18 @@ public void whenIOSNativeAppIsLaunched() { @Test public void whenIOSNativeAppIsLaunched2() { - assertTrue(check( - () -> { - DesiredCapabilities serverCapabilities = serverAppCapabilitiesSupplier.get(); - serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.1"); - return serverCapabilities; - }, - appFileSupplierFunction.apply(testApp), - commonPredicate, - id("IntegerA"), - IOSElement.class)); + assertTrue(check(() -> { + DesiredCapabilities serverCapabilities = serverAppCapabilitiesSupplier.get(); + serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.1"); + return serverCapabilities; + }, appFileSupplierFunction.apply(testApp), commonPredicate, id("IntegerA"), IOSElement.class)); } @Test public void whenIOSBrowserIsLaunched2() { - assertTrue(check( - () -> { - DesiredCapabilities serverCapabilities = serverBrowserCapabilitiesSupplier.get(); - serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.1"); - return serverCapabilities; - }, - clientBrowserCapabilitiesSupplier, - commonPredicate, - className("gsfi"), - RemoteWebElement.class)); + assertTrue(check(() -> { + DesiredCapabilities serverCapabilities = serverBrowserCapabilitiesSupplier.get(); + serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.1"); + return serverCapabilities; + }, clientBrowserCapabilitiesSupplier, commonPredicate, className("gsfi"), RemoteWebElement.class)); } } From 45a76f1be8cb02e0a96924cda03041bb1dd85530 Mon Sep 17 00:00:00 2001 From: Sergey Tikhomirov Date: Wed, 18 Jan 2017 23:41:40 +0300 Subject: [PATCH 6/9] The bug of the isBrowser() method was fixed. --- src/main/java/io/appium/java_client/HasSessionDetails.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/appium/java_client/HasSessionDetails.java b/src/main/java/io/appium/java_client/HasSessionDetails.java index e4182d66b..2e91b7b8d 100644 --- a/src/main/java/io/appium/java_client/HasSessionDetails.java +++ b/src/main/java/io/appium/java_client/HasSessionDetails.java @@ -18,6 +18,7 @@ import static io.appium.java_client.MobileCommand.GET_SESSION; import static java.util.Optional.ofNullable; +import static org.apache.commons.lang3.StringUtils.isBlank; import com.google.common.collect.ImmutableMap; @@ -56,7 +57,6 @@ default String getAutomationName() { */ default boolean isBrowser() { Object browserName = getSessionDetail("browserName"); - return ofNullable(browserName != null ? String - .valueOf(browserName) : null).orElse(null) != null; + return browserName != null && !isBlank(String.valueOf(browserName)); } } From e4a2a85d58a78053c7dbb2e5f02788a552bfb4b6 Mon Sep 17 00:00:00 2001 From: Sergey Tikhomirov Date: Thu, 19 Jan 2017 23:58:51 +0300 Subject: [PATCH 7/9] The bug of the isBrowser() method was fixed. --- src/main/java/io/appium/java_client/AppiumDriver.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index 8bf55ab9c..2d74a554d 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -76,6 +76,7 @@ public class AppiumDriver private ExecuteMethod executeMethod; private final String platformName; private final String automationName; + private String currentContext; /** @@ -119,6 +120,7 @@ public Response execute(String driverCommand) { .orElse(capabilityAutomation2 != null ? String.valueOf(capabilityAutomation2) : null); this.setElementConverter(new JsonToMobileElementConverter(this, this)); + currentContext = getContext(); } public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities) { @@ -350,6 +352,7 @@ public void zoom(int x, int y) { @Override public WebDriver context(String name) { checkNotNull(name, "Must supply a context name"); execute(DriverCommand.SWITCH_TO_CONTEXT, ImmutableMap.of("name", name)); + currentContext = name; return this; } @@ -425,4 +428,11 @@ public URL getRemoteAddress() { @Override public String getAutomationName() { return automationName; } + + @Override public boolean isBrowser() { + if (super.isBrowser()) { + return true; + } + return !currentContext.toLowerCase().contains("NATIVE_APP".toLowerCase()); + } } From 3047a97f86556cec6d1946fad8b2571c2f1d3ec8 Mon Sep 17 00:00:00 2001 From: Sergey Tikhomirov Date: Fri, 20 Jan 2017 00:29:43 +0300 Subject: [PATCH 8/9] Check style issue and bug fixes --- README.md | 8 +- docs/Installing-the-project.md | 4 +- .../io/appium/java_client/AppiumDriver.java | 11 +++ .../appium/java_client/HasSessionDetails.java | 7 +- .../JsonToMobileElementConverter.java | 3 +- .../remote/IOSMobileCapabilityType.java | 26 ++++--- .../generation/BaseElementGenerationTest.java | 2 +- .../android/AndroidElementGeneratingTest.java | 70 +++++++----------- .../ios/IOSElementGenerationTest.java | 74 ++++++++----------- 9 files changed, 104 insertions(+), 101 deletions(-) diff --git a/README.md b/README.md index bcd36d1bc..652161dc5 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,13 @@ This is the Java language binding for writing Appium Tests, conforms to [Mobile ##Changelog## *5.0.0 (under construction yet)* -**[BUG FIX]**:Issue report: [#549](https://github.com/appium/java-client/issues/549). Fix: [#551](https://github.com/appium/java-client/pull/551) +- **[BUG FIX]**:Issue report: [#549](https://github.com/appium/java-client/issues/549). Fix: [#551](https://github.com/appium/java-client/pull/551) +- New capabilities were added [#533](https://github.com/appium/java-client/pull/553): + - `IOSMobileCapabilityType#USE_NEW_WDA` + - `IOSMobileCapabilityType#WDA_LAUNCH_TIMEOUT` + - `IOSMobileCapabilityType#WDA_CONNECTION_TIMEOUT` + +The capability `IOSMobileCapabilityType#REAL_DEVICE_LOGGER` was removed. [#533](https://github.com/appium/java-client/pull/553) *5.0.0-BETA1* - **[MAJOR ENHANCEMENT]**: Migration to Java 8. Epic: [#399](https://github.com/appium/java-client/issues/399) diff --git a/docs/Installing-the-project.md b/docs/Installing-the-project.md index 9ed5c46e8..02c874766 100644 --- a/docs/Installing-the-project.md +++ b/docs/Installing-the-project.md @@ -13,7 +13,7 @@ Add the following to pom.xml: io.appium java-client ${version.you.require} - test + test ``` @@ -40,7 +40,7 @@ If it is necessary to change the version of Selenium then you can configure pom. ``` -#Gardle +#Gradle Add the following to build.gradle: diff --git a/src/main/java/io/appium/java_client/AppiumDriver.java b/src/main/java/io/appium/java_client/AppiumDriver.java index 8bf55ab9c..5fb9c6cad 100644 --- a/src/main/java/io/appium/java_client/AppiumDriver.java +++ b/src/main/java/io/appium/java_client/AppiumDriver.java @@ -76,6 +76,7 @@ public class AppiumDriver private ExecuteMethod executeMethod; private final String platformName; private final String automationName; + private String currentContext; /** @@ -119,6 +120,7 @@ public Response execute(String driverCommand) { .orElse(capabilityAutomation2 != null ? String.valueOf(capabilityAutomation2) : null); this.setElementConverter(new JsonToMobileElementConverter(this, this)); + currentContext = getContext(); } public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities) { @@ -350,6 +352,7 @@ public void zoom(int x, int y) { @Override public WebDriver context(String name) { checkNotNull(name, "Must supply a context name"); execute(DriverCommand.SWITCH_TO_CONTEXT, ImmutableMap.of("name", name)); + currentContext = name; return this; } @@ -425,4 +428,12 @@ public URL getRemoteAddress() { @Override public String getAutomationName() { return automationName; } + + @Override public boolean isBrowser() { + + if (super.isBrowser()) { + return true; + } + return !currentContext.toLowerCase().contains("NATIVE_APP".toLowerCase()); + } } diff --git a/src/main/java/io/appium/java_client/HasSessionDetails.java b/src/main/java/io/appium/java_client/HasSessionDetails.java index 4cb292937..2e91b7b8d 100644 --- a/src/main/java/io/appium/java_client/HasSessionDetails.java +++ b/src/main/java/io/appium/java_client/HasSessionDetails.java @@ -18,6 +18,7 @@ import static io.appium.java_client.MobileCommand.GET_SESSION; import static java.util.Optional.ofNullable; +import static org.apache.commons.lang3.StringUtils.isBlank; import com.google.common.collect.ImmutableMap; @@ -51,9 +52,11 @@ default String getAutomationName() { return ofNullable(automationName != null ? String.valueOf(automationName) : null).orElse(null); } + /** + * @return is focus on browser or on native content. + */ default boolean isBrowser() { Object browserName = getSessionDetail("browserName"); - return ofNullable(browserName != null ? String - .valueOf(browserName) : null).orElse(null) != null; + return browserName != null && !isBlank(String.valueOf(browserName)); } } diff --git a/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java b/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java index 0fc67ee08..a2bb01437 100644 --- a/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java +++ b/src/main/java/io/appium/java_client/internal/JsonToMobileElementConverter.java @@ -89,8 +89,7 @@ protected RemoteWebElement newMobileElement() { Class target; if (hasSessionDetails.isBrowser()) { target = getElementClass(null, null); - } - else { + } else { target = getElementClass(hasSessionDetails.getPlatformName(), hasSessionDetails.getAutomationName()); } diff --git a/src/main/java/io/appium/java_client/remote/IOSMobileCapabilityType.java b/src/main/java/io/appium/java_client/remote/IOSMobileCapabilityType.java index 9640c1621..9d72f8d0f 100644 --- a/src/main/java/io/appium/java_client/remote/IOSMobileCapabilityType.java +++ b/src/main/java/io/appium/java_client/remote/IOSMobileCapabilityType.java @@ -195,14 +195,6 @@ public interface IOSMobileCapabilityType extends CapabilityType { */ String SHOW_XCODE_LOG = "showXcodeLog"; - /** - * Device logger for real devices. It could be path to deviceconsole - * (installed with npm install deviceconsole, a compiled binary named - * deviceconsole will be added to ./node_modules/deviceconsole/) - * or idevicesyslog (comes with libimobiledevice). Defaults to idevicesyslog - */ - String REAL_DEVICE_LOGGER = "realDeviceLogger"; - /** * Time in milliseconds to pause between installing the application * and starting WebDriverAgent on the device. Used particularly for larger applications. @@ -255,4 +247,20 @@ public interface IOSMobileCapabilityType extends CapabilityType { */ String KEYCHAIN_PATH = "keychainPath"; -} \ No newline at end of file + /** + * Forces uninstall of any existing WebDriverAgent app on device. + * This can provide stability in some situations. Defaults to false. + */ + String USE_NEW_WDA = "useNewWDA"; + + /** + * Time, in ms, to wait for WebDriverAgewnt to be pingable. Defaults to 60000ms. + */ + String WDA_LAUNCH_TIMEOUT = "wdaLaunchTimeout"; + + /** + * Timeout, in ms, for waiting for a resonse from WebDriverAgent. Defaults to 240000ms. + */ + String WDA_CONNECTION_TIMEOUT = "wdaConnectionTimeout"; + +} diff --git a/src/test/java/io/appium/java_client/appium/element/generation/BaseElementGenerationTest.java b/src/test/java/io/appium/java_client/appium/element/generation/BaseElementGenerationTest.java index 39254b4ab..0e4bb6a7f 100644 --- a/src/test/java/io/appium/java_client/appium/element/generation/BaseElementGenerationTest.java +++ b/src/test/java/io/appium/java_client/appium/element/generation/BaseElementGenerationTest.java @@ -35,7 +35,7 @@ protected boolean check(Supplier serverCapabilitiesSupplier By by, Class clazz) { AppiumServiceBuilder builder = new AppiumServiceBuilder() .withCapabilities(serverCapabilitiesSupplier.get()); - driver = new AppiumDriver<>(builder, clientCapabilitiesSupplier.get());; + driver = new AppiumDriver<>(builder, clientCapabilitiesSupplier.get()); return filter.test(by, clazz); } diff --git a/src/test/java/io/appium/java_client/appium/element/generation/android/AndroidElementGeneratingTest.java b/src/test/java/io/appium/java_client/appium/element/generation/android/AndroidElementGeneratingTest.java index 935651166..ae2d11129 100644 --- a/src/test/java/io/appium/java_client/appium/element/generation/android/AndroidElementGeneratingTest.java +++ b/src/test/java/io/appium/java_client/appium/element/generation/android/AndroidElementGeneratingTest.java @@ -31,54 +31,40 @@ public class AndroidElementGeneratingTest extends BaseElementGenerationTest { }; @Test public void whenAndroidNativeAppIsLaunched() { - assertTrue(check(serverCapabilitiesSupplier, - () -> { - DesiredCapabilities clientCapabilities = new DesiredCapabilities(); - clientCapabilities.setCapability(MobileCapabilityType.FULL_RESET, true); - clientCapabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 60); - return clientCapabilities; - }, - commonPredicate, - AndroidUIAutomator("new UiSelector().clickable(true)"), - AndroidElement.class)); + assertTrue(check(serverCapabilitiesSupplier, () -> { + DesiredCapabilities clientCapabilities = new DesiredCapabilities(); + clientCapabilities.setCapability(MobileCapabilityType.FULL_RESET, true); + clientCapabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 60); + return clientCapabilities; + }, commonPredicate, AndroidUIAutomator("new UiSelector().clickable(true)"), + AndroidElement.class)); } @Test public void whenAndroidHybridAppIsLaunched() { - assertTrue(check(serverCapabilitiesSupplier, - () -> { - DesiredCapabilities clientCapabilities = new DesiredCapabilities(); - clientCapabilities - .setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "io.appium.android.apis"); - clientCapabilities - .setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ".view.WebView1"); - return clientCapabilities; - }, - (by, aClass) -> { - driver.context("WEBVIEW_io.appium.android.apis"); - return commonPredicate.test(by, aClass); - }, - tagName("a"), - RemoteWebElement.class)); + assertTrue(check(serverCapabilitiesSupplier, () -> { + DesiredCapabilities clientCapabilities = new DesiredCapabilities(); + clientCapabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "io.appium.android.apis"); + clientCapabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, ".view.WebView1"); + return clientCapabilities; + }, (by, aClass) -> { + driver.context("WEBVIEW_io.appium.android.apis"); + return commonPredicate.test(by, aClass); + }, tagName("a"), RemoteWebElement.class)); } @Test public void whenAndroidBrowserIsLaunched() { assertTrue(check(() -> { - DesiredCapabilities serverCapabilities = new DesiredCapabilities(); - serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID); - serverCapabilities.setCapability(MobileCapabilityType.BROWSER_NAME, MobileBrowserType.BROWSER); - return serverCapabilities; - }, - () -> { - DesiredCapabilities clientCapabilities = new DesiredCapabilities(); - clientCapabilities - .setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); - return clientCapabilities; - }, - (by, aClass) -> { - driver.get("https://www.google.com"); - return commonPredicate.test(by, aClass); - }, - className("gsfi"), - RemoteWebElement.class)); + DesiredCapabilities serverCapabilities = new DesiredCapabilities(); + serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID); + serverCapabilities.setCapability(MobileCapabilityType.BROWSER_NAME, MobileBrowserType.BROWSER); + return serverCapabilities; + }, () -> { + DesiredCapabilities clientCapabilities = new DesiredCapabilities(); + clientCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator"); + return clientCapabilities; + }, (by, aClass) -> { + driver.get("https://www.google.com"); + return commonPredicate.test(by, aClass); + }, className("gsfi"), RemoteWebElement.class)); } } diff --git a/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java b/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java index f5312bf80..3c4cd9e7c 100644 --- a/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java +++ b/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java @@ -74,59 +74,49 @@ public void whenIOSNativeAppIsLaunched() { @Test public void whenIOSHybridAppIsLaunched() throws Exception { assertTrue(check(serverAppCapabilitiesSupplier, appFileSupplierFunction.apply(webViewApp), - (by, aClass) -> { - IOSElement element1 = (IOSElement) driver - .findElementByXPath("//UIATextField[@value='Enter URL']"); - element1.sendKeys("www.google.com"); - driver.findElementByClassName("UIAButton").click(); - try { - Thread.sleep(10000); - } catch (InterruptedException e) { - e.printStackTrace(); + (by, aClass) -> { + IOSElement element1 = (IOSElement) driver.findElementByXPath("//UIATextField[@value='Enter URL']"); + element1.sendKeys("www.google.com"); + driver.findElementByClassName("UIAButton").click(); + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + driver.getContextHandles().forEach((handle) -> { + if (handle.contains("WEBVIEW")) { + driver.context(handle); } - driver.getContextHandles().forEach((handle) -> { - if (handle.contains("WEBVIEW")) { - driver.context(handle); - } - }); - return commonPredicate.test(by, aClass); - }, - className("gsfi"), - RemoteWebElement.class)); + }); + return commonPredicate.test(by, aClass); + }, className("gsfi"), RemoteWebElement.class)); } @Test public void whenIOSBrowserIsLaunched() { assertTrue(check(serverBrowserCapabilitiesSupplier, - clientBrowserCapabilitiesSupplier, - commonPredicate, - className("gsfi"), - RemoteWebElement.class)); + clientBrowserCapabilitiesSupplier, (by, aClass) -> { + driver.get("https://www.google.com"); + return commonPredicate.test(by, aClass); + }, className("gsfi"), RemoteWebElement.class)); } @Test public void whenIOSNativeAppIsLaunched2() { - assertTrue(check( - () -> { - DesiredCapabilities serverCapabilities = serverAppCapabilitiesSupplier.get(); - serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.1"); - return serverCapabilities; - }, - appFileSupplierFunction.apply(testApp), - commonPredicate, - id("IntegerA"), - IOSElement.class)); + assertTrue(check(() -> { + DesiredCapabilities serverCapabilities = serverAppCapabilitiesSupplier.get(); + serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.1"); + return serverCapabilities; + }, appFileSupplierFunction.apply(testApp), commonPredicate, id("IntegerA"), IOSElement.class)); } @Test public void whenIOSBrowserIsLaunched2() { - assertTrue(check( - () -> { - DesiredCapabilities serverCapabilities = serverBrowserCapabilitiesSupplier.get(); - serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.1"); - return serverCapabilities; - }, - clientBrowserCapabilitiesSupplier, - commonPredicate, - className("gsfi"), - RemoteWebElement.class)); + assertTrue(check(() -> { + DesiredCapabilities serverCapabilities = serverBrowserCapabilitiesSupplier.get(); + serverCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.1"); + return serverCapabilities; + }, clientBrowserCapabilitiesSupplier, (by, aClass) -> { + driver.get("https://www.google.com"); + return commonPredicate.test(by, aClass); + }, className("gsfi"), RemoteWebElement.class)); } } From d94015815e3e3be6badcc9660c6052f35b776314 Mon Sep 17 00:00:00 2001 From: Sergey Tikhomirov Date: Fri, 20 Jan 2017 00:44:46 +0300 Subject: [PATCH 9/9] IOSElementGenerationTest improvement --- .../element/generation/ios/IOSElementGenerationTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java b/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java index 0f8417e62..3c4cd9e7c 100644 --- a/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java +++ b/src/test/java/io/appium/java_client/appium/element/generation/ios/IOSElementGenerationTest.java @@ -94,10 +94,10 @@ public void whenIOSNativeAppIsLaunched() { @Test public void whenIOSBrowserIsLaunched() { assertTrue(check(serverBrowserCapabilitiesSupplier, - clientBrowserCapabilitiesSupplier, - commonPredicate, - className("gsfi"), - RemoteWebElement.class)); + clientBrowserCapabilitiesSupplier, (by, aClass) -> { + driver.get("https://www.google.com"); + return commonPredicate.test(by, aClass); + }, className("gsfi"), RemoteWebElement.class)); } @Test