|
33 | 33 | import org.junit.jupiter.api.BeforeEach; |
34 | 34 | import org.junit.jupiter.api.Disabled; |
35 | 35 | import org.junit.jupiter.api.Test; |
| 36 | +import java.time.Duration; |
36 | 37 | import org.openqa.selenium.By; |
| 38 | +import org.openqa.selenium.JavascriptExecutor; |
37 | 39 | import org.openqa.selenium.Keys; |
38 | 40 | import org.openqa.selenium.StaleElementReferenceException; |
39 | 41 | import org.openqa.selenium.TimeoutException; |
40 | | -import org.openqa.selenium.JavascriptExecutor; |
41 | 42 | import org.openqa.selenium.WebElement; |
| 43 | +import org.openqa.selenium.support.ui.ExpectedConditions; |
| 44 | +import org.openqa.selenium.support.ui.WebDriverWait; |
42 | 45 | import org.slf4j.Logger; |
43 | 46 | import org.slf4j.LoggerFactory; |
44 | 47 |
|
@@ -327,22 +330,30 @@ void testAngularRunParagraph() throws Exception { |
327 | 330 | "%angular <div id=\\'angularRunParagraph\\' ng-click=\\'z.runParagraph(\"" |
328 | 331 | + secondParagraphId.trim() |
329 | 332 | + "\")\\'>Run second paragraph</div>"); |
| 333 | + |
| 334 | + // Capture old output element before re-run to detect when it gets replaced |
| 335 | + WebElement oldAngularDiv = manager.getWebDriver().findElement(By.xpath( |
| 336 | + getParagraphXPath(1) + "//div[@id=\"angularRunParagraph\"]")); |
| 337 | + |
330 | 338 | runParagraph(1); |
| 339 | + |
| 340 | + // Wait for the old output element to become stale (proves the paragraph output |
| 341 | + // was actually refreshed, avoiding race where waitForParagraph sees the old FINISHED state) |
| 342 | + new WebDriverWait(manager.getWebDriver(), Duration.ofSeconds(MAX_BROWSER_TIMEOUT_SEC)) |
| 343 | + .until(ExpectedConditions.stalenessOf(oldAngularDiv)); |
| 344 | + |
331 | 345 | waitForParagraph(1, "FINISHED"); |
332 | 346 |
|
333 | | - // Wait for Angular to re-render the output with ng-click binding |
334 | | - waitForText("Run second paragraph", By.xpath( |
335 | | - getParagraphXPath(1) + "//div[@id=\"angularRunParagraph\"]")); |
| 347 | + // Wait for new Angular output to render |
| 348 | + WebElement newAngularDiv = visibilityWait(By.xpath( |
| 349 | + getParagraphXPath(1) + "//div[@id=\"angularRunParagraph\"]"), MAX_BROWSER_TIMEOUT_SEC); |
336 | 350 |
|
337 | 351 | // Set new text value for 2nd paragraph |
338 | 352 | setTextOfParagraph(2, "%sh echo NEW_VALUE"); |
339 | 353 |
|
340 | 354 | // Click on Angular-rendered div to trigger z.runParagraph() function. |
341 | | - // Use JavaScript click because Angular-compiled ng-click elements may not be |
342 | | - // considered "clickable" by Selenium's native click (overlay/stale issues). |
343 | | - WebElement angularDiv = visibilityWait(By.xpath( |
344 | | - getParagraphXPath(1) + "//div[@id=\"angularRunParagraph\"]"), MAX_BROWSER_TIMEOUT_SEC); |
345 | | - ((JavascriptExecutor) manager.getWebDriver()).executeScript("arguments[0].click();", angularDiv); |
| 355 | + // Use JavaScript click to bypass overlay/clickability issues with ng-click elements. |
| 356 | + ((JavascriptExecutor) manager.getWebDriver()).executeScript("arguments[0].click();", newAngularDiv); |
346 | 357 | ZeppelinITUtils.sleep(1000, false); |
347 | 358 |
|
348 | 359 | waitForParagraph(2, "FINISHED"); |
|
0 commit comments