getUtil().createPage(space, existingPageName, "Page that already exists", "Existing page");
String existingSpace = this.getClass().getSimpleName() + ((int) (Math.random() * 1000));
getUtil().createPage(existingSpace, "WebHome", "{{spaceindex /}}", "New random space");
// 1/ create an empty page that already exists
HomePage homePage = new HomePage();
homePage.gotoPage();
CreatePagePage createPage = homePage.createPage();
createPage.setSpace(space);
createPage.setPage(existingPageName);
String currentURL = getDriver().getCurrentUrl();
createPage.clickCreate();
// make sure that we stay on the same page and that an error is displayed to the user. Maybe we should check the
// error
Assert.assertEquals(currentURL, getDriver().getCurrentUrl());
createPage.waitForErrorMessage();
// 2/ create a page from template that already exists
// restart everything to make sure it's not the error before
homePage.gotoPage();
createPage = homePage.createPage();
createPage.setSpace(space);
createPage.setPage(existingPageName);
createPage.setTemplate(space + "." + templateProviderName);
currentURL = getDriver().getCurrentUrl();
createPage.clickCreate();
// make sure that we stay on the same page and that an error is displayed to the user. Maybe we should check the
// error
Assert.assertEquals(currentURL, getDriver().getCurrentUrl());
createPage.waitForErrorMessage();
// 3/ create a space that already exists
homePage.gotoPage();
CreateSpacePage createSpace = homePage.createSpace();
currentURL = getDriver().getCurrentUrl();
// strip the parameters out of this URL
currentURL =
currentURL.substring(0, currentURL.indexOf('?') > 0 ? currentURL.indexOf('?') : currentURL.length());
createSpace.createSpace(existingSpace);