-
-
Notifications
You must be signed in to change notification settings - Fork 50
Follow-up changes to TealAppDriver #1653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Marcin <[email protected]>
Code Coverage SummaryDiff against mainResults for commit: 9f231ca Minimum allowed coverage is ♻️ This comment has been updated with latest results |
Unit Tests Summary 1 files 32 suites 2m 45s ⏱️ Results for commit 9f231ca. ♻️ This comment has been updated with latest results. |
Unit Test Performance Difference
Results for commit ca193a6 ♻️ This comment has been updated with latest results. |
llrs-roche
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any test failing and I agree this might be more sensible.
Is there a test case where the difference that makes on tests are clear?
What I noticed is that with TRUE it will have #:
app_driver$namespaces(FALSE)$module("a > img")
## [1] "teal-teal_modules-nav-summary_by_row_groups_table-module-a-plot_main > img"
app_driver$namespaces(TRUE)$module("a > img")
## [1] "#teal-teal_modules-nav-summary_by_row_groups_table-module-a-plot_main > img"Couldn't that be an option of get_active_module_plot_output to control for this?
# Fix e2e tests Fixes #1440 Companion #1441 To verify the result of tests, you should do the following: 1. Install [this branch](insightsengineering/teal#1653) of teal 2. Install teal modules clinical on this version 3. ``` devtools::load_all() library(shinytest2) source("tests/testthat/helper-TealAppDriver.R") source("tests/testthat/helper-testing-depth.R") testthat::test_file("tests/testthat/test-shinytest2-tm_g_pp_patient_timeline.R") testthat::test_file("tests/testthat/test-shinytest2-tm_g_pp_vitals.R") testthat::test_file("tests/testthat/test-shinytest2-tm_g_pp_therapy.R") testthat::test_file("tests/testthat/test-shinytest2-tm_g_pp_adverse_events.R") ``` --------- Co-authored-by: osenan <[email protected]> Co-authored-by: Lluís Revilla <[email protected]> Co-authored-by: Marcin <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR modifies the TealAppDriver class to improve the robustness of namespace detection by changing when and how the active module namespace is determined. The changes address timing issues where namespace extraction was failing due to the page not being fully loaded or stable.
Key changes:
- Moved
set_active_ns()call to afterwait_for_idle()in the initialization sequence - Updated
get_active_module_plot_output()to usenamespaces(TRUE)for proper CSS selector generation - Added comprehensive fallback logic in
set_active_ns()to handle cases where active module detection fails
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
get_active_input/output
osenan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR fixes our issues of reviewing plot content and other problems while executing e2e tests.
I only added a suggestion to control better the additional Sys.sleep as suggested by @copilot.
I think in the future we should do a performance analysis of teal app and of teal_app_driver in order to optimize the performance execution of e2e tests.
|
@copilot we do not need any new PR, please do not do any action for the moment |
Co-authored-by: Oriol Senan <[email protected]> Signed-off-by: Lluís Revilla <[email protected]>
averissimo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some concerns on this, please don't merge yet
R/TealAppDriver.R
Outdated
| selector = sprintf(".teal-modules-tree li a.module-button[data-value='%s']", active_tab_inputs), | ||
| attribute = "href" | ||
| # If no active_module_id input found, find the selected/active tab button directly | ||
| if (!length(active_tab_inputs) || active_tab_inputs == "") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This clause makes more sense if we start with the positive case when active_tab_inputs is available
R/TealAppDriver.R
Outdated
| # Try one more time after a short wait - the page might still be loading | ||
| Sys.sleep(sleep_time) | ||
| active_wrapper_id <- private$extract_wrapper_id( | ||
| ".teal-modules-tree li a.module-button[href*='-wrapper']:not([href='#'])" | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to make more sense to sleep and call the method again with sleep_time = sleep_time - 1 that skips this part if time is negative (or NULL to simply skip it).
R/TealAppDriver.R
Outdated
| stop(sprintf( | ||
| paste0( | ||
| "Could not determine active module namespace. ", | ||
| "Make sure a module tab is selected and the page has finished loading. Found wrapper IDs: %s" | ||
| ), | ||
| if (length(found_ids) > 0) found_ids else "none" | ||
| )) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not good clear and simple code, please refactor and take advantage that stop pastes together all its elements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| stop(sprintf( | |
| paste0( | |
| "Could not determine active module namespace. ", | |
| "Make sure a module tab is selected and the page has finished loading. Found wrapper IDs: %s" | |
| ), | |
| if (length(found_ids) > 0) found_ids else "none" | |
| )) | |
| stop( | |
| "Could not determine active module namespace. ", | |
| "Make sure a module tab is selected and the page has finished loading. Found wrapper IDs: " | |
| if (length(found_ids) > 0) found_ids else "none" | |
| )) |
R/TealAppDriver.R
Outdated
| self$get_attr( | ||
| selector = sprintf(".teal-modules-tree li a.module-button[data-value='%s']", active_tab_inputs), | ||
| attribute = "href" | ||
| # If no active_module_id input found, find the selected/active tab button directly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get why would DOM have the input id if the input does not exist in shiny.
How would that work?
- Is it because of
bslibdoing some magic? This creates additional overhead when/if the navigation selectors are changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure I follow your thought. Note that self$get_attr is also used by extract_wrapper_id
llrs-roche
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double checking the logic of the changes I have some concerns too:
- We omit some selectors on
extract_wrapper_idand then we have to try so hard onset_active_nsto get new ones. - On
set_active_nswe duplicate searching withextract_wrapper_id(".teal-modules-tree li a.module-button[href*='-wrapper']:not([href='#'])"). This suggest the order or logic could be improved. set_active_nshas a waiting period that might affects public methodsinitialize,navigate_teal_tab,add_filter_var. This requires longer testing time without changing the application itself.
I think extract_wrapper_id could return multiple ids, and then it is the responsibility of set_active_ns to pick the right one of the valid ones.
| private$wait_for_page_stability() | ||
|
|
||
| all_inputs <- self$get_values()$input | ||
| active_tab_inputs <- all_inputs[grepl("-active_module_id$", names(all_inputs))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use AppDriver$wait_for_value to make sure we have a value and then discard the rest of the added complexity.
The ignore = list(NULL, "") argument will allow us to avoid any of the initialization
spoiler... same can be done with javascript code and AppDriver$wait_for_js (let's say for is_visible())... I'm trying it out in widgets.
Companion to
Changes