Skip to content

Commit 485f9ff

Browse files
Address suggested changes
1 parent 93b761f commit 485f9ff

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

utam-core/src/main/java/utam/core/selenium/appium/MobileDriverAdapter.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import static utam.core.framework.UtamLogger.warning;
1313

1414
import com.fasterxml.jackson.core.JsonProcessingException;
15+
import com.fasterxml.jackson.databind.JsonNode;
1516
import com.fasterxml.jackson.databind.ObjectMapper;
1617
import io.appium.java_client.AppiumDriver;
1718
import io.appium.java_client.remote.SupportsContextSwitching;
@@ -140,15 +141,16 @@ private static AppiumDriver checkAndroidWebViewContext(
140141
for (Map<String, Object> page : pages) {
141142
String newTitle = (String) page.get(WEBVIEW_TITLE_KEY_ANDROID);
142143
// 'description' doesn't cast to Map, only String
143-
String jsonString = (String) page.get(WEBVIEW_PAGE_DESCRIPTION_KEY);
144-
Map description = null;
144+
String serializedDescription = (String) page.get(WEBVIEW_PAGE_DESCRIPTION_KEY);
145+
boolean visible = false;
145146
try {
146-
description = new ObjectMapper().readValue(jsonString, Map.class);
147+
JsonNode descriptionNode = new ObjectMapper().readTree(serializedDescription);
148+
if (descriptionNode.has(WEBVIEW_PAGE_DESCRIPTION_VISIBILITY_KEY)) {
149+
visible = descriptionNode.get(WEBVIEW_PAGE_DESCRIPTION_VISIBILITY_KEY).asBoolean();
150+
}
147151
} catch (JsonProcessingException e) {
148152
error(e);
149153
}
150-
boolean visible =
151-
description != null && (boolean) description.get(WEBVIEW_PAGE_DESCRIPTION_VISIBILITY_KEY);
152154
if (newTitle.equalsIgnoreCase(title) && visible) {
153155
String id = (String) page.get(WEBVIEW_PAGE_KEY);
154156
AppiumDriver newDriver = switchToContext(appiumDriver, webviewName, id);

utam-core/src/test/java/utam/core/selenium/appium/MobileDriverAdapterTests.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@
2222
import static org.mockito.Mockito.when;
2323
import static org.testng.Assert.assertThrows;
2424
import static org.testng.Assert.expectThrows;
25-
import static utam.core.selenium.appium.MobileDriverAdapter.*;
25+
import static utam.core.selenium.appium.MobileDriverAdapter.NATIVE_CONTEXT_HANDLE;
26+
import static utam.core.selenium.appium.MobileDriverAdapter.WEBVIEW_CONTEXT_HANDLE_PREFIX;
27+
import static utam.core.selenium.appium.MobileDriverAdapter.WEBVIEW_CONTEXT_KEY_ANDROID;
28+
import static utam.core.selenium.appium.MobileDriverAdapter.WEBVIEW_CONTEXT_KEY_IOS;
29+
import static utam.core.selenium.appium.MobileDriverAdapter.WEBVIEW_PAGES_KEY;
30+
import static utam.core.selenium.appium.MobileDriverAdapter.WEBVIEW_PAGE_DESCRIPTION_KEY;
31+
import static utam.core.selenium.appium.MobileDriverAdapter.WEBVIEW_PAGE_DESCRIPTION_VISIBILITY_KEY;
32+
import static utam.core.selenium.appium.MobileDriverAdapter.WEBVIEW_PAGE_KEY;
33+
import static utam.core.selenium.appium.MobileDriverAdapter.WEBVIEW_TITLE_KEY_ANDROID;
34+
import static utam.core.selenium.appium.MobileDriverAdapter.WEBVIEW_TITLE_KEY_IOS;
2635

2736
import io.appium.java_client.AppiumDriver;
2837
import io.appium.java_client.remote.SupportsContextSwitching;

0 commit comments

Comments
 (0)