[CUS-12573] hides keyboard fastly in ios devices.#389
Conversation
|
|
📝 WalkthroughWalkthroughThis PR introduces a new iOS test automation module ChangesiOS Hide Keyboard Module
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@hide_keyboard/src/main/java/com/testsigma/addons/ios/HideKeyboard.java`:
- Around line 97-110: The implicit wait is being overwritten to 0
unconditionally; wrap the short-lived change in a try/finally and restore the
prior implicit-wait after the click attempts: before calling
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(1)) capture the
current implicit wait into a variable (e.g., prevImplicit), set the 1-second
timeout, perform the List.of(...).forEach(...) clicks, and in a finally block
restore the saved prevImplicit via
driver.manage().timeouts().implicitlyWait(prevImplicit); update the code around
the driver.manage().timeouts().implicitlyWait(...) calls in HideKeyboard (the
block that sets to 1s and later to 0) so the original timeout is always
reinstated even on exceptions.
- Around line 123-132: The isKeyboardShown() method currently catches all
exceptions and returns false, which masks driver errors and can cause execute()
to incorrectly treat failures as success; change isKeyboardShown() to stop
swallowing exceptions—catch only expected exceptions if needed but otherwise log
the error and rethrow (e.g., throw new RuntimeException(e)) so execute()
surfaces the failure instead of receiving a false; keep the implicit wait
adjustments and ensure any thrown exception carries context about the keyboard
check.
In `@hide_keyboard/src/main/resources/testsigma-sdk.properties`:
- Line 1: Remove the hard-coded API key value for testsigma-sdk.api.key from
testsigma-sdk.properties and replace it with a runtime secret reference (e.g.,
read from an environment variable or secret manager); update any code that reads
testsigma-sdk.api.key to fallback to process/env lookup (or equivalent in your
runtime) and ensure CI injects the secret. After replacing the file, rotate the
exposed credential immediately and purge the leaked value from git history (git
filter-repo/BFG) before merging to prevent further exposure.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 99d671fb-ec52-4409-8aaf-cdef9ac4533b
📒 Files selected for processing (3)
hide_keyboard/pom.xmlhide_keyboard/src/main/java/com/testsigma/addons/ios/HideKeyboard.javahide_keyboard/src/main/resources/testsigma-sdk.properties
| driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(1)); | ||
| List.of("Return", "return", "done", "Done", "search", "Search", "Next", "next", "Go", "go").forEach(button -> { | ||
| try { | ||
| driver.findElement(By.xpath("//*[contains(@name, '" + button + "')]")).click(); | ||
| } catch (Exception e) { | ||
| logger.info("XPath click failed for key '" + button + "': " + e.getMessage()); | ||
| } | ||
| try { | ||
| driver.findElement(AppiumBy.name(button)).click(); | ||
| } catch (Exception e) { | ||
| logger.info("Name lookup failed for key '" + button + "': " + e.getMessage()); | ||
| } | ||
| }); | ||
| driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(0)); |
There was a problem hiding this comment.
Restore implicit wait safely; avoid leaking driver timeout state.
Lines 110 and 127 unconditionally set implicit wait to 0. If another timeout was configured before this action, it gets clobbered and can affect later steps.
Suggested fix pattern
- driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(1));
- // ... operations ...
- driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(0));
+ Duration previous = driver.manage().timeouts().getImplicitWaitTimeout();
+ try {
+ driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(1));
+ // ... operations ...
+ } finally {
+ driver.manage().timeouts().implicitlyWait(previous);
+ }Also applies to: 125-127
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@hide_keyboard/src/main/java/com/testsigma/addons/ios/HideKeyboard.java`
around lines 97 - 110, The implicit wait is being overwritten to 0
unconditionally; wrap the short-lived change in a try/finally and restore the
prior implicit-wait after the click attempts: before calling
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(1)) capture the
current implicit wait into a variable (e.g., prevImplicit), set the 1-second
timeout, perform the List.of(...).forEach(...) clicks, and in a finally block
restore the saved prevImplicit via
driver.manage().timeouts().implicitlyWait(prevImplicit); update the code around
the driver.manage().timeouts().implicitlyWait(...) calls in HideKeyboard (the
block that sets to 1s and later to 0) so the original timeout is always
reinstated even on exceptions.
| private boolean isKeyboardShown() { | ||
| try { | ||
| driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(1)); | ||
| boolean shown = ((IOSDriver) driver).isKeyboardShown(); | ||
| driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(0)); | ||
| return shown; | ||
| } catch (Exception e) { | ||
| logger.info("Exception while checking keyboard visibility: " + e.getMessage()); | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Do not treat keyboard-check exceptions as “keyboard hidden.”
In Line 131, returning false on exception can produce a false SUCCESS in execute(). This should fail closed (or surface failure) instead of masking driver/check errors.
Suggested fix
private boolean isKeyboardShown() {
try {
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(1));
boolean shown = ((IOSDriver) driver).isKeyboardShown();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(0));
return shown;
} catch (Exception e) {
logger.info("Exception while checking keyboard visibility: " + e.getMessage());
- return false;
+ return true; // fail-closed: don't report hidden when check failed
}
}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@hide_keyboard/src/main/java/com/testsigma/addons/ios/HideKeyboard.java`
around lines 123 - 132, The isKeyboardShown() method currently catches all
exceptions and returns false, which masks driver errors and can cause execute()
to incorrectly treat failures as success; change isKeyboardShown() to stop
swallowing exceptions—catch only expected exceptions if needed but otherwise log
the error and rethrow (e.g., throw new RuntimeException(e)) so execute()
surfaces the failure instead of receiving a false; keep the implicit wait
adjustments and ensure any thrown exception carries context about the keyboard
check.
| @@ -0,0 +1 @@ | |||
| testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyNDBkMjhiNS0xNmUwLThlNmYtOWQ0ZS05MjYxMGNiZTcyYzciLCJ1bmlxdWVJZCI6IjYxODUiLCJpZGVudGl0eUFjY291bnRVVUlkIjoiNDMifQ.Ktf9Ejac32ZAAKDwJFa9NerBc-xymkf_msZ0sr2C-o7gQ6tI1F8UVdfUYHwjGDY2P3R_4_7JZ4dIQ-lnL5Xceg No newline at end of file | |||
There was a problem hiding this comment.
Remove the committed API key from source control before merge.
Line 1 exposes a real credential in plaintext. For a PUBLIC addon, this is a release blocker and a credential-compromise risk. Replace this with runtime secret injection (env var / secure vault / CI secret), rotate this key immediately, and purge it from git history.
Suggested secure change
-testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyNDBkMjhiNS0xNmUwLThlNmYtOWQ0ZS05MjYxMGNiZTcyYzciLCJ1bmlxdWVJZCI6IjYxODUiLCJpZGVudGl0eUFjY291bnRVVUlkIjoiNDMifQ.Ktf9Ejac32ZAAKDwJFa9NerBc-xymkf_msZ0sr2C-o7gQ6tI1F8UVdfUYHwjGDY2P3R_4_7JZ4dIQ-lnL5Xceg
+testsigma-sdk.api.key=${TESTSIGMA_SDK_API_KEY}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyNDBkMjhiNS0xNmUwLThlNmYtOWQ0ZS05MjYxMGNiZTcyYzciLCJ1bmlxdWVJZCI6IjYxODUiLCJpZGVudGl0eUFjY291bnRVVUlkIjoiNDMifQ.Ktf9Ejac32ZAAKDwJFa9NerBc-xymkf_msZ0sr2C-o7gQ6tI1F8UVdfUYHwjGDY2P3R_4_7JZ4dIQ-lnL5Xceg | |
| testsigma-sdk.api.key=${TESTSIGMA_SDK_API_KEY} |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@hide_keyboard/src/main/resources/testsigma-sdk.properties` at line 1, Remove
the hard-coded API key value for testsigma-sdk.api.key from
testsigma-sdk.properties and replace it with a runtime secret reference (e.g.,
read from an environment variable or secret manager); update any code that reads
testsigma-sdk.api.key to fallback to process/env lookup (or equivalent in your
runtime) and ensure CI injects the secret. After replacing the file, rotate the
exposed credential immediately and purge the leaked value from git history (git
filter-repo/BFG) before merging to prevent further exposure.
please review this addon and publish as PUBLIC
Addon name : hide_keyboard
Addon accont: https://jarvis.testsigma.com/ui/tenants/3072/addons
Jira: https://testsigma.atlassian.net/browse/CUS-12573
fix
reduced the time for isKeyboardShown method from 5 seconds to 2 seconds.
Summary by CodeRabbit