Patch #42244
closedFix random failures in IssuesTest#test_bulk_copy due to StaleElementReferenceError
Description
This patch addresses the issue where IssuesTest#test_bulk_copy fails randomly.
Error: IssuesSystemTest#test_bulk_copy: Selenium::WebDriver::Error::StaleElementReferenceError: stale element reference: stale element not found in the current frame (Session info: chrome=132.0.6834.159); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#stale-element-reference-exception test/system/issues_test.rb:510:in `block in test_bulk_copy' test/system/issues_test.rb:509:in `test_bulk_copy' bin/rails test test/system/issues_test.rb:460
https://github.com/hidakatsuya/redmine/actions/runs/13212281635/job/36887301512
This StaleElementReferenceError is caused by the interference of DOM rewriting due to project change in page.find('#issue_project_id').select('OnlineStore')
.
def test_bulk_copy
# ...
page.find('#issue_project_id').select('OnlineStore')
# wait for ajax response
assert page.has_select?('issue_project_id', selected: 'OnlineStore')
# ...
assert_difference 'Issue.count', 2 do
submit_buttons[1].click
# ...
end
The existing implementation to wait for the project change assert page.has_select?('issue_project_id', selected: 'OnlineStore')
is not working properly, so we will fix it as follows:
diff --git a/test/system/issues_test.rb b/test/system/issues_test.rb
index c23cbd27c..80ef25e0c 100644
--- a/test/system/issues_test.rb
+++ b/test/system/issues_test.rb
@@ -497,8 +497,9 @@ class IssuesSystemTest < ApplicationSystemTestCase
assert_equal 'Copy', submit_buttons[0].value
page.find('#issue_project_id').select('OnlineStore')
- # wait for ajax response
- assert page.has_select?('issue_project_id', selected: 'OnlineStore')
+ # Verify that the target version field has been rewritten by the OnlineStore project settings
+ # and wait for the project change to complete.
+ assert_select 'issue_fixed_version_id', options: ['(No change)', 'none', 'Alpha', 'Systemwide visible version']
assert_selector 'input[type=submit]', count: 2
submit_buttons = page.all('input[type=submit]')
Files
Updated by Katsuya HIDAKA 13 days ago
For reference, here is a reproduction of the StaleElementReferenceError failure along with a detailed investigation of the root cause.
The reproduction code, including debug code, is available here:
https://github.com/hidakatsuya/redmine/commit/730ae259c1ca3df50b0d143c640deeb4a3b8b152
The test results before and after applying the fix patch for the above reproduction code are as follows:
Before patch application
Capybara starting Puma... ... ** 2025-02-09 04:05:11 +0000 page.find('#issue_project_id').select('OnlineStore'): begin ** 2025-02-09 04:05:12 +0000 IssuesController#bulk_edit by selecting OutlineStore project: begin ** 2025-02-09 04:05:12 +0000 page.find('#issue_project_id').select('OnlineStore'): end ** 2025-02-09 04:05:12 +0000 IssuesController#bulk_edit by selecting OutlineStore project: end [Screenshot Image]: /redmine/tmp/screenshots/failures_test_bulk_copy.png E Error: IssuesSystemTest#test_bulk_copy: Selenium::WebDriver::Error::StaleElementReferenceError: stale element reference: stale element not found in the current frame (Session info: chrome=131.0.6778.204); For documentation on this error, please visit: [https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#stale-element-reference-exception](https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#stale-element-reference-exception) test/system/issues_test.rb:512:in `block in test_bulk_copy' test/system/issues_test.rb:511:in `test_bulk_copy'
After patch application
Capybara starting Puma... ... ** 2025-02-09 04:06:53 +0000 page.find('#issue_project_id').select('OnlineStore'): begin ** 2025-02-09 04:06:53 +0000 IssuesController#bulk_edit by selecting OutlineStore project: begin ** 2025-02-09 04:06:53 +0000 IssuesController#bulk_edit by selecting OutlineStore project: end ** 2025-02-09 04:06:53 +0000 page.find('#issue_project_id').select('OnlineStore'): end .
You can see that after applying the patch, the subsequent tests are executed after waiting for the completion of IssuesController#bulk_edit (project change).