This issue has been created
 
 
XWiki Platform / cid:jira-generated-image-avatar-e9665c4f-fac6-4e52-a877-b2bfd39d6409 XWIKI-22272 Open

Add support for testing with multiple users/browsers

 
View issue   ยท   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-23a23b22-c516-4d8b-8570-a92c273ae5c6 Vincent Massol created this issue on 18/Jun/24 11:15
 
Summary: Add support for testing with multiple users/browsers
Issue Type: cid:jira-generated-image-avatar-e9665c4f-fac6-4e52-a877-b2bfd39d6409 New Feature
Affects Versions: 15.10
Assignee: Unassigned
Components: Test Framework
Created: 18/Jun/24 11:15
Priority: cid:jira-generated-image-static-major-7f2084b9-1aea-4018-ac05-79cc8d2c4da1 Major
Reporter: Vincent Massol
Description:

Use case from Marius:

I look at bit on how to test functionally https://jira.xwiki.org/browse/XWIKI-21949 and I don't see any "easy" way. I need to open two browser instances with different user sessions, so different WebDriver instances. So far I tested realtime editing using a single browser instance with multiple tabs, and thus using a single real XWik authenticated user.
Dorian OUAKLI
has written some fake multi-user tests that rely on the fact that when you logout in a browser tab (and login with a different user), the realtime sessions from other existing tabs are not affected, BUT, this works until you need to make server-side requests that expect and check the CSRF token, which doesn't match anymore the currently authenticated user (based on the cookies sent by the browser). So for XWIKI-21949 I really need to use two separate browser windows with separate user sessions and thus WebDriver instances, but that requires considerable refactoring of how we current run Docker tests. I imagine that such a multi-user functional test would be written using multiple threads, each thread having its own WebDriver instance (stored using ThreadLocal fields on the PO such as BaseElement), and thus communicating with its own browser instance. All this sounds pretty complex to do, unless I'm missing something. WDYT?

Answer from Vincent:

Indeed, for now you probably wouldn't be able to use our docker-based test fwk and you'd need to use the TC API directly by using 2 selenium containers probably. Right now our code is at https://github.com/xwiki/xwiki-platform/blob/3b871d906e664fa1875fbeb088404cf31e9f0094/xwiki-platform-core/xwiki-platform-test/xwiki-platform-test-docker/src/main/java/org/xwiki/test/docker/internal/junit5/browser/BrowserContainerExecutor.java#L70

The TC doc is at https://java.testcontainers.org/modules/webdriver_containers/

So you'd need something like:

@Rule
public BrowserWebDriverContainer<?> chrome1 = new BrowserWebDriverContainer<>()
.withCapabilities(new ChromeOptions());

@Rule
public BrowserWebDriverContainer<?> chrome2 = new BrowserWebDriverContainer<>()
.withCapabilities(new ChromeOptions())

Now, I don't think it would be too hard to refactor our docker-based fwk to allow more than 1 browser, we could introduce a new @UITest(browsers =

Unknown macro: { Browser.CHROME, Browser.FIREFOX }

, ...) syntax. We then need to also add support for List<XWikiWebDriver> parameters in test methods (easy) + save screenshots and videos from all browsers (easy too). Something like this