There is 1 update, 1 comment.
 
 
XWiki Platform / cid:jira-generated-image-avatar-0e736a13-e2f7-43a8-a6c4-7f8b9e125c0e XWIKI-22272 Open

Add support for testing with multiple users/browsers

 
View issue   ยท   Add comment
 

1 update

 
cid:jira-generated-image-avatar-054a03a7-4696-4cfa-a886-6a09c4bf1f2b Changes by Vincent Massol on 02/Jul/24 16:23
 
Description: Use case from Marius:

{quote}
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?
{quote}

Answer from Vincent:

{quote}
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:

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

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

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 = \ { 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
{quote}
 
 

1 comment

 
cid:jira-generated-image-avatar-054a03a7-4696-4cfa-a886-6a09c4bf1f2b Vincent Massol on 02/Jul/24 16:25
 

Thanks Marius Dumitru Florea for the info and the work. We can probably close the issue (and document it on xwiki.org in the docker-based test fwk page) and we'll decide in the future if we want another implementation.

I think it's not to hard to implement what I mentioned (the devil is probably in the details) and I feel it's a bit cleaner, but we can open a new jira issue for this in the future if we want to do it.