Skip to content

Commit

Permalink
Updated blog post edit comments tests (#96)
Browse files Browse the repository at this point in the history
* feature/APPS-871: Adjusted existing helper methods and deleted all java docs.

* feature/APPS-871: Adjusted existing methods and deleted java docs

* feature/APPS-871: Ajusted helper methods

* feature/APPS-871: Renamed methods

* feature/APPS-871: Addressed suggestions #1

* feature/APPS-871: Renamed test class

* feature/APPS-871: Adjusted helper methods, cleanup the code from unused methods/imports and renamed few methods

* feature/APPS-871: Added loggers and cleanup PageObject class

* feature/APPS-871: Renamed methods and decoupled chaining methods from different objects

* feature/APPS-871: Updated BlogPostEditCommentsTests

* Added BlogPostFilters and let only one method which is called filterPostBy(BlogPostFilters filters)

* deleted .html file
  • Loading branch information
araschitor authored Mar 30, 2021
1 parent 193701f commit 66196cc
Show file tree
Hide file tree
Showing 13 changed files with 212 additions and 818 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.alfresco.po.enums;

public enum BlogPostFilters
{
MY_DRAFTS_POSTS("ul.filterLink span.mydrafts>a", "My Draft Posts"),
MY_PUBLISHED_POSTS("ul.filterLink span.mypublished>a", "My Published Posts"),
LATEST_POSTS("ul.filterLink span.new>a", "New Posts"),
ALL_POSTS("ul.filterLink span.all>a", "All Posts");

private final String locator;
private final String expectedFilterLabel;

BlogPostFilters(String locator, String expectedFilterLabel)
{
this.locator = locator;
this.expectedFilterLabel = expectedFilterLabel;
}

public String getLocator()
{
return locator;
}

public String getExpectedFilterLabel()
{
return expectedFilterLabel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.List;
import java.util.Locale;
import lombok.extern.slf4j.Slf4j;
import org.alfresco.po.enums.BlogPostFilters;
import org.alfresco.po.share.site.SiteCommon;
import org.alfresco.utility.exception.PageOperationException;
import org.openqa.selenium.By;
Expand All @@ -38,19 +39,13 @@ public class BlogPostListPage extends SiteCommon<BlogPostListPage>
private final By noBlogPostsFound = By.xpath(".//tbody[@class='yui-dt-message']");
private final By simpleViewButton = By.cssSelector("button[id$='_default-simpleView-button-button']");
private final By newPostButton = By.cssSelector("div.new-blog span[id*='_default-create-button']");
private final By defaultBlogPostList = By.cssSelector("div[id$='_default-postlist']");
private final By nodeTitle = By.xpath(".//span[@class = 'nodeTitle']");
private final By simpleNodePost = By.cssSelector(".node.post.simple");
private final By postDateTime = By.xpath(".//div[@class = 'published']//span[@class = 'nodeAttrValue']");
private final By readLabel = By.xpath("div[@class = 'nodeFooter']//span[@class = 'nodeAttrValue']//a");

private final By editButton = By.xpath(".//../div[@class = 'nodeEdit']//div[@class = 'onEditBlogPost']//a//span[text() = 'Edit']");
private final By blogLinkName = By.id("HEADER_SITE_BLOG-POSTLIST");
private final By allFilter = By.cssSelector("ul.filterLink span.all>a");
private final By latestFilter = By.cssSelector("ul.filterLink span.new>a");
private final By myDraftsFilter = By.cssSelector("ul.filterLink span.mydrafts>a");
private final By listTitle = By.className("listTitle");
private final By myPublished = By.cssSelector("ul.filterLink span.mypublished>a");
private final By tag = By.xpath("//span[@class ='tag']/a");

private final String postRowPath = "//tr[contains(@class, 'yui-dt-rec')]//div[@class = 'nodeContent']//span/a[text() = '%s']/../../../..";
Expand Down Expand Up @@ -304,32 +299,15 @@ public boolean isBlogPostDisplayed(String title)
return isElementDisplayed(getBlogPostRow(title));
}

public BlogPostListPage navigateToAllFilter()
public BlogPostListPage filterPostBy(BlogPostFilters blogPostFilters)
{
log.info("Navigate to all filter");
clickElement(allFilter);
log.info("Filter blog post by {}", blogPostFilters);
By filter = By.cssSelector(blogPostFilters.getLocator());
clickElement(filter);
waitUntilElementContainsText(listTitle, blogPostFilters.getExpectedFilterLabel());
return this;
}

public void clickLatestFilter()
{
clickElement(latestFilter);
waitUntilElementContainsText(listTitle, "New Posts");
}

public BlogPostListPage navigateToMyDrafts()
{
clickElement(myDraftsFilter);
waitUntilElementContainsText(listTitle, "My Draft Posts");
return this;
}

public void clickMyPublishedFilter()
{
clickElement(myPublished);
waitUntilElementContainsText(listTitle, "My Published Posts");
}

public void clickTag(String tag)
{
mouseOver(selectTagsByTagName(tag));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.alfresco.po.share.site.blog;

import static org.testng.Assert.assertEquals;

import java.util.ArrayList;
import java.util.List;

Expand All @@ -15,8 +17,8 @@
@Slf4j
public class BlogPostViewPage extends SiteCommon<BlogPostViewPage>
{
public final By commentText = By.cssSelector("div[class ='comment-content'] p");
public final By noCommentsText = By.xpath("//tbody[@class = 'yui-dt-message']//div[@class = 'yui-dt-liner']");
private final By commentText = By.cssSelector("div[class ='comment-content'] p");
private final By blogPostTitle = By.cssSelector("div[id*='_blog-postview'] div.nodeTitle>a");
private final By blogPostContent = By.cssSelector("div[id*='_blog-postview'] div.content");
private final By blogPostAuthor = By.cssSelector(".published .nodeAttrValue>a");
Expand All @@ -25,7 +27,6 @@ public class BlogPostViewPage extends SiteCommon<BlogPostViewPage>
private final By editButton = By.cssSelector(".onEditBlogPost>a");
private final By deleteButton = By.cssSelector(".onDeleteBlogPost>a");
private final By addCommentButton = By.cssSelector(".onAddCommentClick button");
private final By commentAuthorName = By.xpath("//span[@class = 'info']/a");
private final By editCommentButton = By.xpath("//a[@title='Edit Comment']");
private final By deleteCommentButton = By.xpath("//a[@title = 'Delete Comment']");
private final By newPostButton = By.cssSelector("button[id$='_default-create-button-button']");
Expand Down Expand Up @@ -112,18 +113,17 @@ public List<String> getBlogPostTags()
return tagsList;
}

public String commentAuthorName(String user)
{
return getElementText(selectComment(user).findElement(commentAuthorName));
}

public String getCommentText(String user)
public BlogPostViewPage assertCommentEqualsTo(String user, String expectedComment)
{
return getElementText(selectComment(user).findElement(commentText));
log.info("Assert comment equals {}", expectedComment);
String actualComment = getElementText(selectComment(user).findElement(commentText));
assertEquals(actualComment, expectedComment, String.format("Comment not equals %s ", expectedComment));
return this;
}

public void clickEditComment(String user)
public void openEditCommentEditor(String user)
{
log.info("Open edit comment editor");
mouseOver(selectComment(user));
clickElement(editCommentButton);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
package org.alfresco.po.share.site.blog;

import static org.testng.Assert.assertEquals;

import lombok.extern.slf4j.Slf4j;
import org.alfresco.po.share.TinyMce.TinyMceEditor;
import org.alfresco.po.share.site.SiteCommon;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import static org.testng.Assert.assertEquals;

@Slf4j
public class BlogPromptWindow extends SiteCommon<BlogPromptWindow>
{
private TinyMceEditor tinyMceEditor;

private final By addCommentBoxLabel = By.xpath("//div[@class = 'comment-form']//h2[text()='Add Your Comment...']");
private final By addCommentButton = By.xpath("//button[contains(@id, '_default-add-submit-button')]");
private final By cancelButtonCommentWindow = By.xpath("//button[contains(@id, '_default-add-cancel')]");
private final By saveButtonEditCommentWindow = By.xpath("//button[text()='Save']");
private final By cancelButtonEditCommentWindow = By.xpath("//button[text()='Cancel']");
private final By editCommentBoxLabel = By.xpath("//div[@class = 'comment-form']//h2[text()='Edit Comment...']");
private final By editorIframe = By.xpath("//div[@class = 'comment-form']//form[contains(@id, '_default-add-form')]//div[@class = 'mce-tinymce mce-container mce-panel']//iframe");
private final By editor = By.id("tinymce");

private final String commentBoxLabel = "//div[@class = 'comment-form']//h2[text()='%s']";

public BlogPromptWindow(ThreadLocal<WebDriver> webDriver)
{
super(webDriver);
Expand All @@ -31,8 +27,7 @@ public BlogPromptWindow(ThreadLocal<WebDriver> webDriver)
@Override
public String getRelativePath()
{
// TODO Auto-generated method stub
return null;
return "Empty relative path!";
}

public BlogPromptWindow writePostComment(String postComment)
Expand All @@ -45,11 +40,11 @@ public BlogPromptWindow writePostComment(String postComment)
return this;
}

public BlogPromptWindow assertAddCommentLabelEqualsTo(String expectedLabel)
public BlogPromptWindow assertCommentBoxLabelEqualsTo(String expectedLabel)
{
log.info("Assert Add comment label equals to {}", expectedLabel);
String actualLabel = getElementText(addCommentBoxLabel);
assertEquals(actualLabel, expectedLabel, String.format("Add comment label not equals %s", expectedLabel));
log.info("Assert comment box label equals to {}", expectedLabel);
String actualLabel = getElementText(By.xpath(String.format(commentBoxLabel, expectedLabel)));
assertEquals(actualLabel, expectedLabel, String.format("Comment box label not equals %s", expectedLabel));
return this;
}

Expand All @@ -61,34 +56,18 @@ public BlogPromptWindow addPostComment()
return this;
}

public void clickCancelOnAddCommentWindow()
public void saveEditedComment()
{
findElement(cancelButtonCommentWindow).click();
}

public void clickSaveButtonOnEditComment()
{
findElement(saveButtonEditCommentWindow).click();
}


public void clickCancelButtonOnEditComment()
{
findElement(cancelButtonEditCommentWindow).click();
}

public boolean isEditCommentDisplayed()
{
return isElementDisplayed(By.xpath("//div[@class = 'comment-form']//h2[text()='Edit Comment...']"));
}

public String getEditCommentBoxLabel()
{
return findElement(editCommentBoxLabel).getText();
log.info("Save edited comment");
clickElement(saveButtonEditCommentWindow);
waitUntilNotificationMessageDisappears();
}

public void testEditComment(String comment)
public BlogPromptWindow editComment(String comment)
{
log.info("Edit comment {}", comment);
TinyMceEditor tinyMceEditor = new TinyMceEditor(webDriver);
tinyMceEditor.setText(comment);
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.alfresco.share.sitesFeatures.blog;

import static org.alfresco.po.enums.BlogPostFilters.ALL_POSTS;
import static org.alfresco.po.enums.BlogPostFilters.MY_DRAFTS_POSTS;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric;

import org.alfresco.dataprep.DashboardCustomization.Page;
import org.alfresco.dataprep.SitePagesService;
import org.alfresco.dataprep.SiteService;
import org.alfresco.po.enums.BlogPostFilters;
import org.alfresco.po.share.site.blog.BlogPostListPage;
import org.alfresco.po.share.site.blog.BlogPostViewPage;
import org.alfresco.po.share.site.blog.BlogPromptWindow;
Expand Down Expand Up @@ -69,11 +72,13 @@ public void shouldAddCommentToBlogPost()

blogPostListPage
.navigate(siteModel.get())
.readPost(blogTitle)
.openCommentEditor()
.assertAddCommentLabelEqualsTo(ADD_YOUR_COMMENT_LABEL);
.readPost(blogTitle);

blogPostViewPage
.openCommentEditor();

blogPromptWindow
.assertCommentBoxLabelEqualsTo(ADD_YOUR_COMMENT_LABEL)
.writePostComment(blogComment)
.addPostComment();

Expand All @@ -91,22 +96,24 @@ public void addCommentToDraftBlogPost()

blogPostListPage
.navigate(siteModel.get())
.navigateToMyDrafts()
.filterPostBy(MY_DRAFTS_POSTS)
.readPost(blogTitle);

blogPostViewPage
.openCommentEditor()
.assertAddCommentLabelEqualsTo(ADD_YOUR_COMMENT_LABEL)
.openCommentEditor();

blogPromptWindow
.assertCommentBoxLabelEqualsTo(ADD_YOUR_COMMENT_LABEL)
.writePostComment(blogComment)
.addPostComment();

blogPostViewPage
.navigateBackToBlogList()
.navigateToMyDrafts()
.filterPostBy(MY_DRAFTS_POSTS)
.assertPostNumberOfRepliesEqualTo(blogTitle, EXPECTED_NUMBER_OF_REPLIES);

blogPostListPage
.navigateToAllFilter()
.filterPostBy(ALL_POSTS)
.assertPostNumberOfRepliesEqualTo(blogTitle, EXPECTED_NUMBER_OF_REPLIES);
}

Expand Down
Loading

0 comments on commit 66196cc

Please sign in to comment.