Skip to content

Update get_targeted_hosts entity to work with new job inv wizard - #2487

Merged
LadislavVasina1 merged 1 commit into
SatelliteQE:masterfrom
LadislavVasina1:update_get_targeted_hosts_entity_to_work_with_new_wizard
Jul 23, 2026
Merged

Update get_targeted_hosts entity to work with new job inv wizard#2487
LadislavVasina1 merged 1 commit into
SatelliteQE:masterfrom
LadislavVasina1:update_get_targeted_hosts_entity_to_work_with_new_wizard

Conversation

@LadislavVasina1

@LadislavVasina1 LadislavVasina1 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

PF5 job invocation wizard landed and update is needed for it.

This PR is a direct fix for new failures of test_change_content_source

image

@LadislavVasina1 LadislavVasina1 self-assigned this Jul 22, 2026
@LadislavVasina1 LadislavVasina1 added No-CherryPick PR doesnt need CherryPick to previous branches Stream labels Jul 22, 2026
@LadislavVasina1

Copy link
Copy Markdown
Contributor Author
trigger: test-robottelo
pytest: tests/foreman/ui/test_host.py -k 'test_change_content_source'

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • Relying on multiple fixed time.sleep(3) calls will make this flow slow and potentially flaky; consider replacing them with explicit waits on the next button and the target hosts section being present/ready instead.
  • The method now conditionally advances the wizard by clicking next_button, which changes its side effects; consider either renaming/splitting the method to make this behavior clear or centralizing the wizard navigation logic in a dedicated helper to keep responsibilities separated.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Relying on multiple fixed `time.sleep(3)` calls will make this flow slow and potentially flaky; consider replacing them with explicit waits on the next button and the target hosts section being present/ready instead.
- The method now conditionally advances the wizard by clicking `next_button`, which changes its side effects; consider either renaming/splitting the method to make this behavior clear or centralizing the wizard navigation logic in a dedicated helper to keep responsibilities separated.

## Individual Comments

### Comment 1
<location path="airgun/entities/job_invocation.py" line_range="70" />
<code_context>
         time.sleep(3)
         view = JobInvocationCreateView(self.browser)
         time.sleep(3)
+        if view.next_button.is_displayed and view.next_button.is_enabled:
+            view.next_button.click()
</code_context>
<issue_to_address>
**suggestion (performance):** Consider replacing chained `time.sleep(3)` calls with an explicit wait on the relevant UI condition.

There are now two fixed 3-second sleeps around the `next_button` interaction, which both slow the test and remain brittle if the page timing changes. Please replace these with an explicit wait (e.g., waiting for `next_button` to be clickable or for the target hosts view to appear) to improve reliability and reduce runtime.

Suggested implementation:

```python
        view = JobInvocationCreateView(self.browser)
        # Explicitly wait until the "next" button is clickable instead of using fixed sleeps
        WebDriverWait(self.browser, 10).until(
            EC.element_to_be_clickable(view.next_button)
        )
        view.next_button.click()
        self.browser.plugin.ensure_page_safe()
        time.sleep(3)
        return view.target_hosts_and_inputs.read()

```

To fully implement this change, you will also need to:
1. Add the appropriate imports at the top of `airgun/entities/job_invocation.py`, for example:
   - `from selenium.webdriver.support.ui import WebDriverWait`
   - `from selenium.webdriver.support import expected_conditions as EC`
2. If `self.browser` is not the raw Selenium WebDriver instance, adjust the `WebDriverWait` call to use the underlying driver (e.g., `self.browser.driver`), consistent with how other explicit waits are implemented in this codebase.
3. If the project already has helper methods for explicit waits (e.g., in `self.browser.plugin`), you may prefer to replace the `WebDriverWait` block with the project-standard helper for waiting until an element is clickable.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -70,6 +70,10 @@ def get_targeted_hosts(self):
time.sleep(3)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (performance): Consider replacing chained time.sleep(3) calls with an explicit wait on the relevant UI condition.

There are now two fixed 3-second sleeps around the next_button interaction, which both slow the test and remain brittle if the page timing changes. Please replace these with an explicit wait (e.g., waiting for next_button to be clickable or for the target hosts view to appear) to improve reliability and reduce runtime.

Suggested implementation:

        view = JobInvocationCreateView(self.browser)
        # Explicitly wait until the "next" button is clickable instead of using fixed sleeps
        WebDriverWait(self.browser, 10).until(
            EC.element_to_be_clickable(view.next_button)
        )
        view.next_button.click()
        self.browser.plugin.ensure_page_safe()
        time.sleep(3)
        return view.target_hosts_and_inputs.read()

To fully implement this change, you will also need to:

  1. Add the appropriate imports at the top of airgun/entities/job_invocation.py, for example:
    • from selenium.webdriver.support.ui import WebDriverWait
    • from selenium.webdriver.support import expected_conditions as EC
  2. If self.browser is not the raw Selenium WebDriver instance, adjust the WebDriverWait call to use the underlying driver (e.g., self.browser.driver), consistent with how other explicit waits are implemented in this codebase.
  3. If the project already has helper methods for explicit waits (e.g., in self.browser.plugin), you may prefer to replace the WebDriverWait block with the project-standard helper for waiting until an element is clickable.

@Satellite-QE

Copy link
Copy Markdown
Contributor

PRT Result

Build Number: 874
Build Status: SUCCESS
PRT Comment: pytest tests/foreman/ui/test_host.py -k test_change_content_source --external-logging
Test Result : ========== 3 passed, 96 deselected, 23 warnings in 3364.84s (0:56:04) ==========

@Satellite-QE Satellite-QE added the PRT-Passed Indicates that latest PRT run is passed for the PR label Jul 22, 2026
@LadislavVasina1
LadislavVasina1 merged commit 8672964 into SatelliteQE:master Jul 23, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

No-CherryPick PR doesnt need CherryPick to previous branches PRT-Passed Indicates that latest PRT run is passed for the PR Stream

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants