Skip to content
Snippets Groups Projects
Commit 31aabed1 authored by Marius Dumitru Florea's avatar Marius Dumitru Florea
Browse files

XWIKI-22272: Add support for testing with multiple users/browsers

* Don't create a MultiUserTestUtils instance each time it is injected
* Bulletproof test

(cherry picked from commit b118cb05)
parent 1069404e
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List; import java.util.List;
import java.util.Locale;
import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
...@@ -1094,6 +1095,11 @@ void restrictScriptMacroExecution(TestUtils setup, TestReference testReference, ...@@ -1094,6 +1095,11 @@ void restrictScriptMacroExecution(TestUtils setup, TestReference testReference,
// currently). // currently).
firstTextArea.waitUntilTextContains("Failed to execute the [velocity] macro."); firstTextArea.waitUntilTextContains("Failed to execute the [velocity] macro.");
// It's not enough to wait for the Velocity macro error message because the content is re-rendered twice (first
// time when the Velocity macro is inserted and a second time when the Velocity macro is edited), but the output
// is the same.
firstTextArea.waitUntilContentEditable();
// Change the content (without modifying the script macro). // Change the content (without modifying the script macro).
firstTextArea.sendKeys(Keys.END, " dinner"); firstTextArea.sendKeys(Keys.END, " dinner");
...@@ -1126,6 +1132,9 @@ void restrictScriptMacroExecution(TestUtils setup, TestReference testReference, ...@@ -1126,6 +1132,9 @@ void restrictScriptMacroExecution(TestUtils setup, TestReference testReference,
multiUserSetup.switchToBrowserTab(multiUserSetup.getFirstTabHandle()); multiUserSetup.switchToBrowserTab(multiUserSetup.getFirstTabHandle());
firstTextArea.waitUntilTextContains("lunch"); firstTextArea.waitUntilTextContains("lunch");
// The second user has modified the Velocity macro, which triggered a re-rendering of the content on this tab.
firstTextArea.waitUntilContentEditable();
// Try to inject a script macro. // Try to inject a script macro.
firstTextArea.sendKeys(Keys.HOME); firstTextArea.sendKeys(Keys.HOME);
firstTextArea.sendKeys(Keys.chord(Keys.CONTROL, Keys.ARROW_RIGHT)); firstTextArea.sendKeys(Keys.chord(Keys.CONTROL, Keys.ARROW_RIGHT));
...@@ -1156,6 +1165,9 @@ void restrictScriptMacroExecution(TestUtils setup, TestReference testReference, ...@@ -1156,6 +1165,9 @@ void restrictScriptMacroExecution(TestUtils setup, TestReference testReference,
text = secondTextArea.getText(); text = secondTextArea.getText();
assertFalse(text.contains("injected"), "Unexpected text content: " + text); assertFalse(text.contains("injected"), "Unexpected text content: " + text);
// The content is re-rendered twice because the first user has inserted and modified the Velocity macro.
secondTextArea.waitUntilContentEditable();
// Edit again the macro to see that the script level doesn't change. // Edit again the macro to see that the script level doesn't change.
secondTextArea.sendKeys(Keys.ARROW_RIGHT, Keys.ENTER); secondTextArea.sendKeys(Keys.ARROW_RIGHT, Keys.ENTER);
new MacroDialogEditModal().waitUntilReady().setMacroContent("Current: $xcontext.userReference").clickSubmit(); new MacroDialogEditModal().waitUntilReady().setMacroContent("Current: $xcontext.userReference").clickSubmit();
...@@ -1176,7 +1188,10 @@ void editPageTranslations(TestUtils setup, TestReference testReference, MultiUse ...@@ -1176,7 +1188,10 @@ void editPageTranslations(TestUtils setup, TestReference testReference, MultiUse
// Start fresh. // Start fresh.
setup.deletePage(testReference); setup.deletePage(testReference);
RealtimeWYSIWYGEditPage firstEditPage = RealtimeWYSIWYGEditPage.gotoPage(testReference); // Force the English locale, in case this test is run multiple times (it switches to German locale at some
// point).
DocumentReference testReferenceEN = new DocumentReference(testReference, Locale.ENGLISH);
RealtimeWYSIWYGEditPage firstEditPage = RealtimeWYSIWYGEditPage.gotoPage(testReferenceEN);
RealtimeCKEditor firstEditor = firstEditPage.getContenEditor(); RealtimeCKEditor firstEditor = firstEditPage.getContenEditor();
RealtimeRichTextAreaElement firstTextArea = firstEditor.getRichTextArea(); RealtimeRichTextAreaElement firstTextArea = firstEditor.getRichTextArea();
......
...@@ -46,12 +46,22 @@ public boolean supportsParameter(ParameterContext parameterContext, ExtensionCon ...@@ -46,12 +46,22 @@ public boolean supportsParameter(ParameterContext parameterContext, ExtensionCon
@Override @Override
public MultiUserTestUtils resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) public MultiUserTestUtils resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
{ {
TestConfiguration testConfiguration = DockerTestUtils.getTestConfiguration(extensionContext);
ExtensionContext.Store store = DockerTestUtils.getStore(extensionContext); ExtensionContext.Store store = DockerTestUtils.getStore(extensionContext);
PersistentTestContext testContext = store.get(PersistentTestContext.class, PersistentTestContext.class); // All tests that share the same context should share the same MultiUserTestUtils instance because:
TestUtils testUtils = testContext.getUtil(); // * MultiUserTestUtils has state (keeps track of the opened tabs and their base URLs and secret tokens)
// * the browser instance is shared by all tests in the same context
MultiUserTestUtils multiUsersSetup = store.get(MultiUserTestUtils.class, MultiUserTestUtils.class);
if (multiUsersSetup == null) {
TestConfiguration testConfiguration = DockerTestUtils.getTestConfiguration(extensionContext);
PersistentTestContext testContext = store.get(PersistentTestContext.class, PersistentTestContext.class);
TestUtils testUtils = testContext.getUtil();
multiUsersSetup = new MultiUserTestUtils(testUtils, testConfiguration);
store.put(MultiUserTestUtils.class, multiUsersSetup);
}
return new MultiUserTestUtils(testUtils, testConfiguration); return multiUsersSetup;
} }
} }
...@@ -116,7 +116,12 @@ public void closeTabs() ...@@ -116,7 +116,12 @@ public void closeTabs()
{ {
// Close all tabs except the first one. // Close all tabs except the first one.
this.setup.getDriver().getWindowHandles().stream().filter(handle -> !handle.equals(this.firstTabHandle)) this.setup.getDriver().getWindowHandles().stream().filter(handle -> !handle.equals(this.firstTabHandle))
.forEach(handle -> this.setup.getDriver().switchTo().window(handle).close()); .forEach(handle -> {
this.setup.getDriver().switchTo().window(handle).close();
// Clean up the state associated with the closed tab.
this.baseURLByTab.remove(handle);
this.secretTokenByTab.remove(handle);
});
// Switch back to the first tab. // Switch back to the first tab.
this.setup.getDriver().switchTo().window(this.firstTabHandle); this.setup.getDriver().switchTo().window(this.firstTabHandle);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment