From 0e5512aedee0cb3c0014368a67d2e034893a2062 Mon Sep 17 00:00:00 2001 From: Maciej Kwidzinski Date: Tue, 18 Jun 2024 10:16:40 +0200 Subject: [PATCH] Avoid premature navigation when clicking the admin cog To reproduce this here, we would need to slow down the browser network. We'd need Selenium 4 for that. So for now, it's a fix without a test, sorry! --- CHANGELOG.md | 3 +++ .../tools/jiraactions/api/WebJira.kt | 22 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a40e8c4..9ef1a2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,9 @@ Dropping a requirement of a major version of a dependency is a new contract. ## [Unreleased] [Unreleased]: https://github.com/atlassian/jira-actions/compare/release-3.28.0...master +### Fixed +- Avoid premature navigation when clicking the administration cog. + ## [3.28.0] - 2024-06-17 [3.28.0]: https://github.com/atlassian/jira-actions/compare/release-3.27.0...release-3.28.0 diff --git a/src/main/kotlin/com/atlassian/performance/tools/jiraactions/api/WebJira.kt b/src/main/kotlin/com/atlassian/performance/tools/jiraactions/api/WebJira.kt index 4d12416..af81f99 100644 --- a/src/main/kotlin/com/atlassian/performance/tools/jiraactions/api/WebJira.kt +++ b/src/main/kotlin/com/atlassian/performance/tools/jiraactions/api/WebJira.kt @@ -3,7 +3,9 @@ package com.atlassian.performance.tools.jiraactions.api import com.atlassian.performance.tools.jiraactions.administration.JiraAdministrationMenu import com.atlassian.performance.tools.jiraactions.api.page.* import org.openqa.selenium.By +import org.openqa.selenium.JavascriptExecutor import org.openqa.selenium.WebDriver +import org.openqa.selenium.support.ui.ExpectedCondition import java.net.URI import java.net.URLEncoder @@ -108,8 +110,26 @@ data class WebJira( internal fun administrate(): JiraAdministrationMenu { NotificationPopUps(driver).waitUntilAuiFlagsAreGone() - driver.findElement(By.id("admin_menu")).click() + val adminCog = By.id("admin_menu") + waitForAdminCog() + driver.findElement(adminCog).click() val menu = driver.findElement(By.id("system-admin-menu-content")) return JiraAdministrationMenu(driver, menu) } + + /** + * If we click on the administration cog too fast + * we would navigate to `plugins/servlet/applications/versions-licenses` + * and be asked for websudo password [AdminAccess]. + */ + private fun waitForAdminCog() = waitForDomComplete() + + private fun waitForDomComplete() { + val js = driver as JavascriptExecutor + val domComplete = ExpectedCondition { + val state = js.executeScript("return document.readyState") as String? + state == "complete" + } + driver.wait(domComplete) + } }