Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-22272

Add support for testing with multiple users/browsers

    XMLWordPrintable

Details

    • Unit
    • Unknown
    • N/A

    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 = { 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

      Attachments

        Activity

          People

            mflorea Marius Dumitru Florea
            vmassol Vincent Massol
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: