@Test
  public void testWatchThisPageAndWholeSpace() throws Exception {
    // Clear the list of watched documents and spaces
    getUtil()
        .updateObject(
            "XWiki",
            this.profilePage.getUsername(),
            "XWiki.WatchListClass",
            0,
            "spaces",
            "",
            "documents",
            "");

    // Watch Test.TestWatchThisPage
    ViewPage page = getUtil().createPage("Test", "TestWatchThisPage", "TestWatchThisPage ui", null);
    page.watchDocument();

    // Watch TestWatchWholeSpace.Test1
    page = getUtil().createPage("TestWatchWholeSpace", "Test1", "TestWatchWholeSpace ui", null);
    page.watchSpace();

    // Verify that the watched page & space are present in the watchlist manager
    this.watchlistPage = WatchlistUserProfilePage.gotoPage(this.watchlistPage.getUsername());
    // TODO: use LiveTableElement instead but does not seems to work...
    // LiveTableElement watchlist = this.watchlistPage.getWatchList();
    // watchlist.waitUntilReady();
    this.watchlistPage.waitUntilElementIsVisible(
        By.xpath(
            "//tbody[@id='mywatchlist-display']/tr/td/a[@href='/xwiki/bin/view/Test/TestWatchThisPage']"));
    Assert.assertTrue(this.watchlistPage.isWatched("Test", "TestWatchThisPage"));
    Assert.assertTrue(this.watchlistPage.isWatched("TestWatchWholeSpace"));

    // Ensure that the watchlist notified is set to Daily since we're going to trigger that notifier
    // scheduler job
    WatchlistPreferencesEditPage watchlistPreferences = this.watchlistPage.editPreferences();
    watchlistPreferences.setNotifierDaily();
    watchlistPreferences.clickSaveAndContinue();

    // Switch to Admin user and go to the scheduler home page
    SchedulerHomePage schedulerHomePage = new SchedulerHomePage();
    getDriver().get(getUtil().getURLToLoginAsAdminAndGotoPage(schedulerHomePage.getURL()));
    getUtil().recacheSecretToken();

    // Trigger the notification for the Daily job
    schedulerHomePage.clickJobActionTrigger("WatchList daily notifier");

    // Wait for the email with a timeout
    Assert.assertTrue("Mail not received", this.greenMail.waitForIncomingEmail(70000, 1));

    // Verify email content
    String messageFromXWiki = GreenMailUtil.getBody(this.greenMail.getReceivedMessages()[0]);
    Assert.assertFalse(messageFromXWiki.contains("Exception"));
    Assert.assertTrue(messageFromXWiki.contains("TestWatchThisPage"));
    Assert.assertTrue(messageFromXWiki.contains("TestWatchWholeSpace"));
  }
  @Override
  @Before
  public void setUp() {
    super.setUp();

    // Set the SMTP port to the default port used by Greenmail (3025)
    getUtil()
        .updateObject("XWiki", "XWikiPreferences", "XWiki.XWikiPreferences", 0, "smtp_port", 3025);

    // Start GreenMail test server
    this.greenMail = new GreenMail();
    this.greenMail.start();

    // Create a user for the test
    String userName = RandomStringUtils.randomAlphanumeric(5);
    this.profilePage = new ProfileUserProfilePage(userName);
    getUtil().registerLoginAndGotoPage(profilePage.getUsername(), "password", profilePage.getURL());

    // Set the Admin user's email address to use a localhost domain so that the mail is caught by
    // our
    // GreenMail Mock mail server.
    getUtil()
        .updateObject(
            "XWiki",
            this.profilePage.getUsername(),
            "XWiki.XWikiUsers",
            0,
            "email",
            "admin@localhost");

    this.watchlistPage = this.profilePage.switchToWatchlist();

    // Disable auto watch
    WatchlistPreferencesEditPage watchlistPreferences = this.watchlistPage.editPreferences();
    watchlistPreferences.setAutomaticWatchNone();
    watchlistPreferences.clickSaveAndContinue();
  }