@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"));
  }
  /** Tests that a scheduler job page default edit mode is "inline". */
  @Test
  public void testAutomaticWatchNewPage() {
    // create a new page
    getUtil().createPage(this.testSpace, "testpage", null, null);

    // go back to watchlist profile
    this.watchlistPage = WatchlistUserProfilePage.gotoPage(this.watchlistPage.getUsername());

    // check if it's registered in the watchlist
    Assert.assertTrue(
        "Newly created page is not watched",
        this.watchlistPage.isWatched(this.testSpace, "testpage"));
  }