// Fill the target destination the page to be copied to.
copyPage.setTargetSpaceName(targetSpaceName);
copyPage.setTargetPageName(targetPageName);
// Click copy button
CopyOverwritePromptPage copyOverwritePrompt = copyPage.clickCopyButtonExpectingOverwritePrompt();
// Check overwrite warning
Assert.assertEquals(OVERWRITE_PROMPT1 + targetSpaceName + '.' + targetPageName + OVERWRITE_PROMPT2,
copyOverwritePrompt.getWarningMessage());
// Cancel the copy
viewPage = copyOverwritePrompt.clickCancelButton();
// Verify that we have been sent back to the original page
Assert.assertEquals(sourcePageName, viewPage.getDocumentTitle());
// Click on Copy from the Page top menu.
copyPage = viewPage.copy();
// Fill the target destination the page to be copied to.
copyPage.setTargetSpaceName(targetSpaceName);
copyPage.setTargetPageName(targetPageName);
// Click copy button
copyOverwritePrompt = copyPage.clickCopyButtonExpectingOverwritePrompt();
// Click change target
copyPage = copyOverwritePrompt.clickChangeTargetButton();
// Check form content
Assert.assertEquals(sourceSpaceName, copyPage.getSourceSpaceName());
Assert.assertEquals(sourcePageName, copyPage.getSourcePageName());
Assert.assertEquals(sourceSpaceName, copyPage.getTargetSpaceName());
Assert.assertEquals(sourcePageName, copyPage.getTargetPageName());
// Fill the target destination the page to be copied to.
copyPage.setTargetSpaceName(targetSpaceName);
copyPage.setTargetPageName(targetPageName);
// Copy and confirm overwrite
copyOverwritePrompt = copyPage.clickCopyButtonExpectingOverwritePrompt();
CopyConfirmationPage copyConfirmationPage = copyOverwritePrompt.clickCopyButton();
// Check successful copy confirmation
Assert.assertTrue(copyConfirmationPage.getInfoMessage().contains(COPY_SUCCESSFUL));
viewPage = copyConfirmationPage.goToNewPage();