From 0a938098492bb9d32b9b06095dfc2324575356d1 Mon Sep 17 00:00:00 2001 From: Chris Trevarthen Date: Tue, 10 Dec 2019 23:27:27 -0500 Subject: [PATCH] Allow tester to specify the platform when device lookup isn't working. --- pom.xml | 2 +- .../katalonmobileutil/device/Platform.java | 15 ++++++- .../katalonmobileutil/testobject/Finder.java | 44 +++++++++++++++---- .../testobject/FinderTest.java | 10 +++++ 4 files changed, 61 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index aab0ea6..c33924f 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.detroitlabs katalon-mobile-util - 1.13.1 + 1.13.2 jar katalon-mobile-util diff --git a/src/main/java/com/detroitlabs/katalonmobileutil/device/Platform.java b/src/main/java/com/detroitlabs/katalonmobileutil/device/Platform.java index f9ae52d..dd063ae 100644 --- a/src/main/java/com/detroitlabs/katalonmobileutil/device/Platform.java +++ b/src/main/java/com/detroitlabs/katalonmobileutil/device/Platform.java @@ -1,5 +1,18 @@ package com.detroitlabs.katalonmobileutil.device; public enum Platform { - ANDROID, IOS, MOBILE, WEB + ANDROID("Android"), + IOS("iOS"), + MOBILE("Mobile"), + WEB("Web"); + + private String name; + + Platform(String name) { + this.name = name; + } + + public String getName() { + return name; + } } diff --git a/src/main/java/com/detroitlabs/katalonmobileutil/testobject/Finder.java b/src/main/java/com/detroitlabs/katalonmobileutil/testobject/Finder.java index 27ba792..377211e 100644 --- a/src/main/java/com/detroitlabs/katalonmobileutil/testobject/Finder.java +++ b/src/main/java/com/detroitlabs/katalonmobileutil/testobject/Finder.java @@ -2,6 +2,7 @@ import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject; +import com.detroitlabs.katalonmobileutil.device.Platform; import org.openqa.selenium.WebDriverException; import org.openqa.selenium.remote.RemoteWebElement; @@ -20,6 +21,8 @@ public class Finder { private static String androidRepository = "Android Objects"; private static String webRepository = "Web Objects"; + private static Platform platform; + public static void setIOSRepository(String repository) { iOSRepository = repository; } @@ -32,6 +35,11 @@ public static void setWebRepository(String repository) { webRepository = repository; } + public static void setPlatform(Platform platformPref) { + platform = platformPref; + Logger.debug("Finder is now using platform: " + platform.getName()); + } + public static TestObject findAlert(String name) { return findObject(TestObjectType.ALERT, name); } @@ -318,14 +326,34 @@ public static TestObject findCheckboxWithText(String checkboxText) { private static TestObject findObject(TestObjectType type, String name) { - String typeDirectory = ""; - - String objectRepo = ""; - if (Device.isWeb()) { - objectRepo = webRepository; - } - else { - objectRepo = Device.isIOS() ? iOSRepository : androidRepository; + String typeDirectory; + String objectRepo; + + // First, check if the tester has set the platform for Finder directly + if (platform != null) { + Logger.debug("Finder is using user-specified platform: " + platform.getName() + " to find the Test Object named '" + name + "'"); + switch (platform) { + case IOS: + objectRepo = iOSRepository; + break; + case ANDROID: + objectRepo = androidRepository; + break; + case WEB: + objectRepo = webRepository; + break; + default: + objectRepo = ""; + } + } else { + // Fall back on checking the device's platform to set the test object location + Logger.debug("Finder is using device platform: " + Device.getDeviceOS() + " to find the Test Object named " + name + "'"); + if (Device.isWeb()) { + objectRepo = webRepository; + } + else { + objectRepo = Device.isIOS() ? iOSRepository : androidRepository; + } } typeDirectory = type != null && type.getName() != null ? type.getName() + "/" : ""; diff --git a/src/test/java/com/detroitlabs/katalonmobileutil/testobject/FinderTest.java b/src/test/java/com/detroitlabs/katalonmobileutil/testobject/FinderTest.java index 7c119d4..04265c8 100644 --- a/src/test/java/com/detroitlabs/katalonmobileutil/testobject/FinderTest.java +++ b/src/test/java/com/detroitlabs/katalonmobileutil/testobject/FinderTest.java @@ -1,6 +1,7 @@ package com.detroitlabs.katalonmobileutil.testobject; import com.detroitlabs.katalonmobileutil.device.Device; +import com.detroitlabs.katalonmobileutil.device.Platform; import com.kms.katalon.core.logging.KeywordLogger; import com.kms.katalon.core.testobject.ObjectRepository; import com.kms.katalon.core.testobject.TestObject; @@ -47,4 +48,13 @@ public void findingAGenericTestObject_callsFindTestObjectWithGenericPath() { assertNotNull(label); } + @Test + @DisplayName("setting a device makes subsequent calls to findTestObject use that device's test object locations") + public void settingDevice_callsFindTestObjectWithPlatformPath() { + Finder.setPlatform(Platform.IOS); + PowerMockito.when(ObjectRepository.findTestObject("iOS Objects/Labels/Test Label")).thenReturn(new TestObject()); + TestObject label = Finder.findLabel("Test Label"); + assertNotNull(label); + } + }