Skip to content

Commit

Permalink
Updated BlogPostFilter Tests (#97)
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

* feature/APPS-873: Adjusted helper methods from BlogPostListPage

* feature/APPS-873: Added checks for each info bar title

* feature/APPS-873: Renamed test class

* feature/APPS-873: commented line will be fixed in next PRS

* changed lines
  • Loading branch information
araschitor authored Apr 1, 2021
1 parent 66196cc commit 7c725c3
Show file tree
Hide file tree
Showing 11 changed files with 920 additions and 323 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,37 @@
import static org.alfresco.common.RetryTime.RETRY_TIME_30;
import static org.alfresco.common.Wait.WAIT_1;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.TextStyle;
import java.time.temporal.ChronoUnit;
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;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindAll;
import org.openqa.selenium.support.FindBy;

@Slf4j
public class BlogPostListPage extends SiteCommon<BlogPostListPage>
{
private final String BLOG_POST_LIST = "Blog Post List";
private final String POSTS_FOR_MONTH = "Posts for Month ";
private final String ARIA_LABEL_ATTRIBUTE = "aria-label";
private final String OPEN_PARENTHESIS = "(";
private final String CLOSE_PARENTHESIS = ")";

//Below fields will be delete in next PRs
@FindBy (css = "[class='listTitle']")
public WebElement pageTitle;

@FindAll (@FindBy (css = "div[id*='archives'] a.filter-link"))
private List<WebElement> archivesMonths;

private final By pageTitle = By.cssSelector("[class='listTitle']");
private final By archivesMonths = By.cssSelector("div[id*='archives'] a.filter-link");
private final By blogContent = By.xpath(".//div[@class = 'content yuieditor']");
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 nodeTitle = By.xpath(".//span[@class = 'nodeTitle']");
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");
Expand All @@ -52,12 +46,19 @@ public class BlogPostListPage extends SiteCommon<BlogPostListPage>
private final String labelPath = "//div[@class = 'nodeContent']//span/a[text() = '%s']/../..//span[@class='nodeAttrLabel' and normalize-space()= '%s']";
private final String valuePath = "//div[@class = 'nodeContent']//span/a[text() = '%s']/../..//span[@class='nodeAttrValue' and normalize-space()='%s']";
private final String postFooterPath = ".//div[@class = 'nodeFooter' ]//span[text() = '(%s)']";
private final String tagPath = "//div[@id = 'alf-filters']//div[contains(@id, '_blog-postlist')]//div[@class = 'filter']//span[@class = 'tag']/a[text() = '%s']";

public BlogPostListPage(ThreadLocal<WebDriver> webDriver)
{
super(webDriver);
}

@Override
public String getRelativePath()
{
return String.format("share/page/site/%s/blog-postlist", getCurrentSiteName());
}

private WebElement getBlogPostRow(String blogTitle)
{
return waitWithRetryAndReturnWebElement(By.xpath(String.format(postRowPath, blogTitle)),
Expand All @@ -69,33 +70,6 @@ public WebElement selectBlogPostWithTitle(String title)
return findElement(By.xpath("//tr[contains(@class, 'yui-dt-rec')]//div[@class = 'nodeContent']//span/a[text() = '" + title + "']/../.."));
}

private WebElement selectBlogPostFooter(String title)
{
return findElement(By.xpath("//tr[contains(@class, 'yui-dt-rec')]//div[@class = 'nodeContent']//span/a[text() = '" + title + "']/../../../.."));
}

private WebElement selectTagsByTagName(String tag)
{
return findElement(By.xpath(
"//div[@id = 'alf-filters']//div[contains(@id, '_blog-postlist')]//div[@class = 'filter']//span[@class = 'tag']/a[text() = '" + tag + "']"));
}

private WebElement selectArchiveMonth(String month)
{
return findFirstElementWithValue(archivesMonths, month);
}

public WebElement blogPostTitle(String title)
{
return findElement(By.xpath("//div[@class ='nodeContent']//span[@class = 'nodeTitle']//a[text() = '" + title + "']"));
}

@Override
public String getRelativePath()
{
return String.format("share/page/site/%s/blog-postlist", getCurrentSiteName());
}

public BlogPostListPage assertBlogContentEqualsTo(String expectedBlogContentText)
{
log.info("Assert blog content equals to {}", expectedBlogContentText);
Expand All @@ -114,11 +88,6 @@ public BlogPostListPage assertNoBlogPostFound(String expectedNoBlogPostsFoundLab
return this;
}

public boolean isNewPostButtonDisplayed()
{
return isElementDisplayed(newPostButton);
}

public BlogPostListPage assertNewBlogIsDisplayedInMenuBar(String expectedBlogName)
{
log.info("Assert new blog is displayed in menu bar {}", expectedBlogName);
Expand Down Expand Up @@ -148,16 +117,6 @@ private String getPostPublishedDateTime(String title)
return getElementText(getBlogPostRow(title).findElement(postDateTime));
}

public boolean isEditButtonPresentForBlogPost(String title)
{
return selectBlogPostWithTitle(title).findElement(By.xpath("//div[@class = 'onEditBlogPost']")).isDisplayed();
}

public boolean isDeleteButtonPresentForBlogPost(String title)
{
return selectBlogPostWithTitle(title).findElement(By.xpath("//div[@class = 'onDeleteBlogPost']")).isDisplayed();
}

/**
* Method to compare if blog post date from UI contains blog post date from server
*
Expand Down Expand Up @@ -191,32 +150,11 @@ private String formatDate(LocalDateTime localDateTime)
.concat(emptySpace).concat(year);
}

//this method will be replace in the remained classes with assertBlogAuthorPostEqualsTo
public String getBlogPostAuthor(String title)
{
WebElement post = getBlogPostRow(title);
List<WebElement> listLabels = post.findElements(By.xpath(".//span[@class='nodeAttrLabel']"));

int index;
for (index = 0; index < listLabels.size(); index++)
{
if (listLabels.get(index).getText().trim().equals("Author:"))
{
break;
}
}
if (index == listLabels.size())
{
throw new PageOperationException("Element not found");
}

List<WebElement> listAttribute = post.findElements(By.xpath(".//span[@class='nodeAttrValue']"));
return listAttribute.get(index).getText();
}

public BlogPostListPage assertBlogTitleEqualsTo(String expectedBlogTitle)
{
log.info("Assert blog title equals to {}", expectedBlogTitle);
waitUntilElementIsVisible(getBlogPostRow(expectedBlogTitle).findElement(nodeTitle));

String actualBlogTitle = getElementText(getBlogPostRow(expectedBlogTitle).findElement(nodeTitle));
assertEquals(actualBlogTitle, expectedBlogTitle, String.format("Blog title not equals %s ", expectedBlogTitle));
return this;
Expand Down Expand Up @@ -289,14 +227,21 @@ public BlogPostListPage assertBlogPostHaveTagEqualsTo(String title, String expec
return this;
}

public String getPageTitle()
public BlogPostListPage assertPostInfoBarTitleEqualsTo(String expectedPageTitle)
{
return pageTitle.getText();
log.info("Assert post info bar title equals to {}", expectedPageTitle);
String actualPageTitle = getElementText(pageTitle);
assertEquals(actualPageTitle, expectedPageTitle,
String.format("Post info bar title not equals %s", expectedPageTitle));
return this;
}

public boolean isBlogPostDisplayed(String title)
public BlogPostListPage assertBlogPostIsNotDisplayed(String title)
{
return isElementDisplayed(getBlogPostRow(title));
log.info("Assert blog post {} is not displayed", title);
By blogPost = By.xpath(String.format(postRowPath, title));
assertFalse(isElementDisplayed(blogPost), String.format("Blog post is displayed %s", title));
return this;
}

public BlogPostListPage filterPostBy(BlogPostFilters blogPostFilters)
Expand All @@ -308,17 +253,13 @@ public BlogPostListPage filterPostBy(BlogPostFilters blogPostFilters)
return this;
}

public void clickTag(String tag)
public BlogPostListPage filterPostByTag(String tag)
{
mouseOver(selectTagsByTagName(tag));
clickElement(selectTagsByTagName(tag));
waitUntilElementContainsText(listTitle, "Blog Post List");
}

public void clickArchiveMonth(String month)
{
selectArchiveMonth(month).click();
waitUntilElementContainsText(pageTitle, "Posts for Month " + month);
log.info("Filter post by tag {}", tag);
By tagLocator = By.xpath(String.format(tagPath, tag.toLowerCase()));
clickElement(tagLocator);
waitUntilElementContainsText(listTitle, BLOG_POST_LIST);
return this;
}

public BlogPostViewPage readPost(String postTitle)
Expand All @@ -334,11 +275,6 @@ public boolean isBlogPostContentDisplayed(String title)
return isElementDisplayed(By.xpath(".//div[@class = 'content yuieditor']"));
}

public String getButtonName()
{
return findElement(simpleViewButton).getText();
}

public BlogPostViewPage clickOnThePostTitle(String title)
{
findElement(By.xpath("//tr[contains(@class, 'yui-dt-rec')]//div[@class = 'nodeContent']//span/a[text() = '" + title + "']")).click();
Expand Down Expand Up @@ -369,4 +305,17 @@ public BlogPostListPage assertButtonTextEqualsTo(String expectedButtonText)
String.format("Button text not equals %s ", expectedButtonText));
return this;
}
}

public BlogPostListPage filterPostByMonthAndYearFromArchive(String monthAndYear)
{
log.info("filter post by month and year from archive {}", monthAndYear);
clickElement(selectArchiveMonth(monthAndYear));
waitUntilElementContainsText(pageTitle, POSTS_FOR_MONTH.concat(monthAndYear));
return this;
}

private WebElement selectArchiveMonth(String month)
{
return findFirstElementWithValue(archivesMonths, month);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.alfresco.share.sitesFeatures.blog;

import static org.alfresco.po.enums.BlogPostFilters.LATEST_POSTS;
import static org.alfresco.po.share.site.SitePageType.BLOG;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric;

Expand Down Expand Up @@ -119,6 +120,7 @@ public void shouldDisplayBlogPostSimpleDetails()
.assertBlogPostDontHaveTag(blogTitle, language.translate(NONE))
.openBlogSimpleView()
.assertButtonTextEqualsTo(language.translate(DETAILED_VIEW))
.assertPostInfoBarTitleEqualsTo(LATEST_POSTS.getExpectedFilterLabel())
.assertBlogTitleEqualsTo(blogTitle)
.assertBlogPublishDateContains(blogTitle, language.translate(PUBLISHED_ON_LABEL),
getPublishDateFromResponse(formatter), formatter)
Expand All @@ -137,9 +139,12 @@ public void shouldDisplayBlogPostDetailedView()
blogPostListPage.navigate(siteModel.get());

blogPostListPage
.assertPostInfoBarTitleEqualsTo(LATEST_POSTS.getExpectedFilterLabel())
.assertBlogTitleEqualsTo(blogTitle)
.assertBlogPublishDateContains(blogTitle, language.translate(PUBLISHED_ON_LABEL),
getPublishDateFromResponse(formatter), formatter);
.assertBlogPublishDateContains(
blogTitle, language.translate(PUBLISHED_ON_LABEL),
getPublishDateFromResponse(formatter),
formatter);

blogPostListPage
.assertBlogAuthorPostEqualsTo(blogTitle, language.translate(AUTHOR_LABEL), authorValue)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.alfresco.share.sitesFeatures.blog;

import static org.alfresco.po.enums.BlogPostFilters.ALL_POSTS;
import static org.alfresco.po.enums.BlogPostFilters.LATEST_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 @@ -72,6 +72,8 @@ public void shouldAddCommentToBlogPost()

blogPostListPage
.navigate(siteModel.get())
.assertPostInfoBarTitleEqualsTo(LATEST_POSTS.getExpectedFilterLabel())
.assertBlogTitleEqualsTo(blogTitle)
.readPost(blogTitle);

blogPostViewPage
Expand All @@ -89,14 +91,15 @@ public void shouldAddCommentToBlogPost()

@TestRail(id = "C6035")
@Test(groups = {TestGroup.SANITY, TestGroup.SITES_FEATURES})
public void addCommentToDraftBlogPost()
public void shouldAddCommentToDraftBlogPost()
{
sitePagesService.createBlogPost(userModel.get().getUsername(), userModel.get().getPassword(),
siteModel.get().getId(), blogTitle, blogContent, true, noTags);

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

blogPostViewPage
Expand All @@ -114,6 +117,7 @@ public void addCommentToDraftBlogPost()

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.alfresco.share.sitesFeatures.blog;

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

Expand Down Expand Up @@ -47,7 +48,7 @@ public class BlogPostEditCommentsTests extends BaseTest
private final List<String> noTags = Collections.synchronizedList(new ArrayList<>());

private String fullUsername;
private String editedComment = "Edited Comment".concat(randomAlphanumeric(5));
private final String editedComment = "Edited Comment".concat(randomAlphanumeric(5));

@BeforeMethod(alwaysRun = true)
public void setupTest()
Expand Down Expand Up @@ -78,6 +79,7 @@ public void shouldEditBlogPostComment()

blogPostListPage
.navigate(siteModel.get())
.assertPostInfoBarTitleEqualsTo(LATEST_POSTS.getExpectedFilterLabel())
.readPost(blogTitle);

blogPostViewPage
Expand Down Expand Up @@ -105,6 +107,7 @@ public void shouldEditDraftBlogPostComment()
blogPostListPage
.navigate(siteModel.get())
.filterPostBy(MY_DRAFTS_POSTS)
.assertPostInfoBarTitleEqualsTo(MY_DRAFTS_POSTS.getExpectedFilterLabel())
.readPost(blogTitle);

blogPostViewPage
Expand Down
Loading

0 comments on commit 7c725c3

Please sign in to comment.