Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,31 @@ void testAngularRunParagraph() throws Exception {

assertTrue(isNotBlank(secondParagraphId), "Cannot find paragraph id for the 2nd paragraph");

// Update first paragraph to call z.runParagraph() with 2nd paragraph id
setTextOfParagraph(1,
"%angular <div id=\\'angularRunParagraph\\' ng-click=\\'z.runParagraph(\""
// Update first paragraph to call z.runParagraph() with 2nd paragraph id.
// Bypass ACE + the play button: setTextOfParagraph toggles editor
// visibility and then calls ace.edit().setValue(), which races with the
// editor re-init that follows the toggle. ACE setValue also does not
// fire the 'input' event paragraph.controller.js binds to, so
// paragraph.text never commits — and when $scope.editor is falsy or
// freshly rebound, getEditorValue() falls back to the previous text or
// the empty buffer, causing the rerun to echo stale/empty ANGULAR data.
// Drive the paragraph straight through its controller scope instead.
final String newAngularText =
"%angular <div id='angularRunParagraph' ng-click='z.runParagraph(\""
+ secondParagraphId.trim()
+ "\")\\'>Run second paragraph</div>");
+ "\")'>Run second paragraph</div>";

// Capture old output element before re-run to detect when it gets replaced
WebElement oldAngularDiv = manager.getWebDriver().findElement(By.xpath(
getParagraphXPath(1) + "//div[@id=\"angularRunParagraph\"]"));

runParagraph(1);
((JavascriptExecutor) manager.getWebDriver()).executeScript(
"var els = document.querySelectorAll('div[ng-controller=\"ParagraphCtrl\"]');"
+ "var s = angular.element(els[0]).scope();"
+ "s.paragraph.text = arguments[0];"
+ "if (s.editor) { s.editor.setValue(arguments[0], 1); s.editor.clearSelection(); }"
+ "s.runParagraph(arguments[0], true, false);",
newAngularText);

// Wait for the old output element to become stale (proves the paragraph output
// was actually refreshed, avoiding race where waitForParagraph sees the old FINISHED state)
Expand All @@ -344,9 +358,23 @@ void testAngularRunParagraph() throws Exception {

waitForParagraph(1, "FINISHED");

// Wait for new Angular output to render
WebElement newAngularDiv = visibilityWait(By.xpath(
getParagraphXPath(1) + "//div[@id=\"angularRunParagraph\"]"), MAX_BROWSER_TIMEOUT_SEC);
// Poll for the new render: visible, expected text, and the ng-click
// attribute from the second version. Re-find each iteration to tolerate
// mid-$compile detaches; requiring ng-click rejects an empty/stale rerun
// where the same "Run second paragraph" string slips through.
final By newAngularDivLocator = By.xpath(
getParagraphXPath(1) + "//div[@id=\"angularRunParagraph\"]");
WebElement newAngularDiv = new WebDriverWait(manager.getWebDriver(),
Duration.ofSeconds(MAX_BROWSER_TIMEOUT_SEC))
.ignoring(StaleElementReferenceException.class)
.until(driver -> {
WebElement el = driver.findElement(newAngularDivLocator);
String ngClick = el.getAttribute("ng-click");
return el.isDisplayed()
&& "Run second paragraph".equals(el.getText())
&& ngClick != null && ngClick.contains("z.runParagraph")
? el : null;
});

// Set new text value for 2nd paragraph
setTextOfParagraph(2, "%sh echo NEW_VALUE");
Expand Down
Loading