Skip to content

Commit

Permalink
Allow tester to specify the platform when device lookup isn't working.
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrevarthen committed Dec 11, 2019
1 parent 290b0e1 commit 0a93809
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.detroitlabs</groupId>
<artifactId>katalon-mobile-util</artifactId>
<version>1.13.1</version>
<version>1.13.2</version>
<packaging>jar</packaging>

<name>katalon-mobile-util</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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() + "/" : "";
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}

}

0 comments on commit 0a93809

Please sign in to comment.