You are on page 1of 14

package com.twx.ux.composer.classic.mashup.widgets.

blog;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.twx.base.BaseTest;
import com.twx.common.requirements.Requirements;
import com.twx.common.utilities.ScreenCapture;
import com.twx.common.utilities.TWConstants;
import com.twx.common.utilities.ThingworxRESTUtils;

/***
* This class verifies the Blog Widget by creating screenshots for different
testing scenarios for use with visual comparison. Scenarios
* include: 1) List View, 2) Log View - AddNewPostInLine(Enabled/Disabled), 3)
Expanded View, 4) BlogButtonsActiveStyle, 5)
* BlogButtonsHoverStyle, 6) BlogButtonsStyle, BlogPostToolbarStyle, BlogPostStyle,
BlogHeaderStyle, BlogStyle 7) BlogLinksStyle
*
* Story TW-23101.
*
* @author akgupta
*
*/

public class VisualBlogTests extends BaseTest {

public static final String BLOG_VOCABULARY_TERM = "Widget_Blog";

public static final String MASHUP_NAME = "Mashup_Widget_Blog";

public static final String MASHUP_NAME_BLOG_LIST_VIEW =


"Mashup_Widget_Blog_TestForListView";

public static final String MASHUP_NAME_BLOG_LOG_VIEW_1 =


"Mashup_Widget_Blog_TestForLogtView1";

public static final String MASHUP_NAME_BLOG_LOG_VIEW_2 =


"Mashup_Widget_Blog_TestForLogtView2";

public static final String MASHUP_NAME_BLOG_EXPANDED_VIEW =


"Mashup_Widget_Blog_ExpandedView";

public static final String MASHUP_NAME_BLOG_3 = "Mashup_Widget_Blog3";


public static final String CUSTOM_BLOG_5_WIDGET_ID = "blog-5";

public static final String CUSTOM_BLOG_6_WIDGET_ID = "blog-6";

public static final String CUSTOM_BLOG_1_WIDGET_ID = "blog-1";

public static final String CUSTOM_BLOG_1_TITLE = "CustomBlogTest1";

public static final String POST_TITLE1 = "Title1";

public static final String POST_TITLE2 = "Title2";

public static final String POST_TITLE1_CONTENT = "Example Content 1";

public static final String POST_TITLE2_CONTENT = "Example Content 2";

public static final String TEST_ENTITIES_FILE_NAME =


"Widget_Blog_Entities.xml";

public static final String PURGE_BLOG_ENTRIES_SERVICE_NAME =


"PurgeBlogEntries";

public static final String INPUT_TITLE_TEXTBOX_WIDGET_ID = "textbox-9";

public static final String INPUT_BLOG_TEXTBOX_WIDGET_ID = "textbox-8";

public static final String NEW_TITLE = "New Title for this Blog Long Text New
Title for this Blog Long Text New Title for this";

public static final LinkedHashMap<String, String> PURGE_BLOG_ENTRIES_PARAMETERS


= new LinkedHashMap<String, String>();

public static final LinkedHashMap<String, String> BLOG_POST_ENTRIES = new


LinkedHashMap<String, String>();

private static final DateTimeZone DATETIME_ZONE =


DateTimeZone.forID("America/New_York");

public static final Long END_DATE = new


DateTime(DATETIME_ZONE).plusDays(1).getMillis();

public static final String VERIFY_ELEMENT_VISIBILITY = "Visibility";

public static final String VERIFY_ELEMENT_FOCUS = "Focus";

@BeforeClass(alwaysRun = true)
public void beforeClass() throws Exception {
// Import entities
getThingworxRESTUtils().importXmlEntities(TEST_ENTITIES_FILE_NAME, true,
ThingworxRESTUtils.HTTP_OK);

// set the end Date to post 1 day to be able to delete all blog entries
PURGE_BLOG_ENTRIES_PARAMETERS.put("endDate", END_DATE.toString());
}

// Overrides baseTest so that loginToExplorerPage() is called in beforeClass


@BeforeMethod(alwaysRun = true)
public void beforeMethod() {
}

@AfterMethod(alwaysRun = true)
public void afterMethod() throws UnsupportedEncodingException {
// clear all Blog Post Entries from HashMap(if Any)
BLOG_POST_ENTRIES.clear();
}

@AfterClass(alwaysRun = true)
public void afterClass() throws Exception {
// Delete entities created for test class

getThingworxRESTUtils().deleteEntitiesByApplicationModelTag(BLOG_VOCABULARY_TERM);
}

@Requirements(reqs = { "TW-23101" })
@Test(description = "Verify blog widget list view by taking screenshots for
visual comparison", groups = { "VISUAL_TESTING", "BLOG" })
public void blogWidgetListViewTest() throws Exception {

BLOG_POST_ENTRIES.put(POST_TITLE1, POST_TITLE1_CONTENT);
BLOG_POST_ENTRIES.put(POST_TITLE2, POST_TITLE2_CONTENT);

try {
// navigate to Mashup Widget Blog
navigateMashupRuntimeFullyLoaded(MASHUP_NAME_BLOG_LIST_VIEW,
CUSTOM_BLOG_1_WIDGET_ID, VERIFY_ELEMENT_VISIBILITY);

// add 2 new posts and verify they are added successfully


addNewPostsToBlog(CUSTOM_BLOG_1_WIDGET_ID, BLOG_POST_ENTRIES);
verifyAllPostsTitleInBlog(CUSTOM_BLOG_1_WIDGET_ID, BLOG_POST_ENTRIES);

// Take screenshot to verify changes.


ScreenCapture.captureScreenshot(webdriver.getWebDriver(),
getScreenshotDestination(1, "ListView"));
} finally {
// delete all the blogEntries
getThingworxRESTUtils().executeService(TWConstants.THINGS,
CUSTOM_BLOG_1_TITLE, PURGE_BLOG_ENTRIES_SERVICE_NAME,
PURGE_BLOG_ENTRIES_PARAMETERS);
}
}

@Requirements(reqs = { "TW-23101" })
@Test(
description = "Verify blog posts(log view) are displayed without related
tags or comments " +
"and InLinePost boxes are shown by taking screenshots for
visual comparison",
groups = { "VISUAL_TESTING", "BLOG" })
public void blogWidgetLogViewAddNewPostInLineEnabledTest() throws Exception {

BLOG_POST_ENTRIES.put(POST_TITLE1, POST_TITLE1_CONTENT);
BLOG_POST_ENTRIES.put(POST_TITLE2, POST_TITLE2_CONTENT);

try {
// navigate to Mashup Widget Blog
navigateMashupRuntimeFullyLoaded(MASHUP_NAME_BLOG_LOG_VIEW_1,
CUSTOM_BLOG_1_WIDGET_ID, VERIFY_ELEMENT_VISIBILITY);
// add 2 new posts and verify they are added successfully through post
inline title and inline text
for (Entry<String, String> blogEntry : BLOG_POST_ENTRIES.entrySet()) {

addNewInlinePost(CUSTOM_BLOG_1_WIDGET_ID, blogEntry);
}
verifyAllPostsInBlog(CUSTOM_BLOG_1_WIDGET_ID, BLOG_POST_ENTRIES);

// Take screenshot to verify changes.


ScreenCapture.captureScreenshot(webdriver.getWebDriver(),
getScreenshotDestination(1, "NewPostInLineEnabled"));
} finally {
// delete all the blogEntries
getThingworxRESTUtils().executeService(TWConstants.THINGS,
CUSTOM_BLOG_1_TITLE, PURGE_BLOG_ENTRIES_SERVICE_NAME,
PURGE_BLOG_ENTRIES_PARAMETERS);
}
}

@Requirements(reqs = { "TW-23101" })
@Test(
description = "Verify blog posts(log view) are displayed without related
tags or comments " +
"and InLinePost boxes are not shown by taking screenshots
for visual comparison",
groups = { "VISUAL_TESTING", "BLOG" })
public void blogWidgetLogViewAddNewPostInLineDisabledTest() throws Exception {

BLOG_POST_ENTRIES.put(POST_TITLE1, POST_TITLE1_CONTENT);
BLOG_POST_ENTRIES.put(POST_TITLE2, POST_TITLE2_CONTENT);
try {
// navigate to Mashup Widget Blog
navigateMashupRuntimeFullyLoaded(MASHUP_NAME_BLOG_LOG_VIEW_2,
CUSTOM_BLOG_1_WIDGET_ID, VERIFY_ELEMENT_VISIBILITY);

// add 2 new posts and verify they are added successfully via add New
Post Button
addNewPostsToBlog(CUSTOM_BLOG_1_WIDGET_ID, BLOG_POST_ENTRIES);
verifyAllPostsInBlog(CUSTOM_BLOG_1_WIDGET_ID, BLOG_POST_ENTRIES);

// Take screenshot to verify changes.


ScreenCapture.captureScreenshot(webdriver.getWebDriver(),
getScreenshotDestination(1, "LogView-NewPostInLineDisabled"));
} finally {
// delete all the blogEntries
getThingworxRESTUtils().executeService(TWConstants.THINGS,
CUSTOM_BLOG_1_TITLE, PURGE_BLOG_ENTRIES_SERVICE_NAME,
PURGE_BLOG_ENTRIES_PARAMETERS);
}
}

@Requirements(reqs = { "TW-23101" })
@Test(
description = "Verify blog posts(expanded view) are displayed with all its
content and also related tags " +
"or comments are displayed by taking screenshots for visual
comparison",
groups = { "VISUAL_TESTING", "BLOG" })
public void blogWidgetExpandedViewTest() throws Exception {

BLOG_POST_ENTRIES.put(POST_TITLE1, POST_TITLE1_CONTENT);
BLOG_POST_ENTRIES.put(POST_TITLE2, POST_TITLE2_CONTENT);
try {
// navigate to Mashup Widget Blog
navigateMashupRuntimeFullyLoaded(MASHUP_NAME_BLOG_EXPANDED_VIEW,
CUSTOM_BLOG_1_WIDGET_ID, VERIFY_ELEMENT_VISIBILITY);

// add 2 new posts and verify they are added successfully via add New
Post Button
addNewPostsToBlog(CUSTOM_BLOG_1_WIDGET_ID, BLOG_POST_ENTRIES);
verifyAllPostsInBlog(CUSTOM_BLOG_1_WIDGET_ID, BLOG_POST_ENTRIES);

// Take screenshot to verify changes.


ScreenCapture.captureScreenshot(webdriver.getWebDriver(),
getScreenshotDestination(1, "ExpandedView"));
} finally {
// delete all the blogEntries
getThingworxRESTUtils().executeService(TWConstants.THINGS,
CUSTOM_BLOG_1_TITLE, PURGE_BLOG_ENTRIES_SERVICE_NAME,
PURGE_BLOG_ENTRIES_PARAMETERS);
}
}

@Requirements(reqs = { "TW-23101" })
@Test(
description = "Verify blog button Active Style test. Click on AddNewPost in
Blog Widget. As the click is" +
" pressed in to select the button, notice the button turns
light blue, take a screenshot",
groups = { "VISUAL_TESTING", "BLOG" })
public void blogWidgetBlogButtonsActiveStyleTest() throws Exception {

// navigate to Mashup Widget Blog


navigateMashupRuntimeFullyLoaded(MASHUP_NAME_BLOG_3,
CUSTOM_BLOG_6_WIDGET_ID, VERIFY_ELEMENT_VISIBILITY);

getPages().mashupRuntimePage().addPostButtonBlogWidget(CUSTOM_BLOG_6_WIDGET_ID).wai
tForVisibilityOfElement();

getPages().mashupRuntimePage().addPostButtonBlogWidget(CUSTOM_BLOG_6_WIDGET_ID).cli
ckAndHold();

// Take screenshot to verify changes.


ScreenCapture.captureScreenshot(webdriver.getWebDriver(),
getScreenshotDestination(1, "ButtonsActiveStyle"));
}

@Requirements(reqs = { "TW-23101" })
@Test(
description = "Verify blog button Hover Style test. Hover over clock icon
on upper right corner in Blog Widget" +
" next to Sort By. Wait for MostRecent to show for the
button hover. Take a screenshot then.",
groups = { "VISUAL_TESTING", "BLOG" })
public void blogWidgetBlogButtonsHoverOverStyleTest() throws Exception {
// navigate to Mashup Widget Blog
navigateMashupRuntimeFullyLoaded(MASHUP_NAME_BLOG_3,
CUSTOM_BLOG_6_WIDGET_ID, VERIFY_ELEMENT_VISIBILITY);

// wait for sort Icon to be visible in blog widget

getPages().mashupRuntimePage().postMostRecentSortByIconBlogWidget(CUSTOM_BLOG_6_WID
GET_ID).waitForVisibilityOfElement();

// verify tooltip message from the <title> tag of the most Recent Icon
webElement. Limitation : cannot capture tooltip through
// selenium as it is browser tooltip
Assert.assertEquals(

getPages().mashupRuntimePage().postMostRecentSortByIconBlogWidget(CUSTOM_BLOG_6_WID
GET_ID).getAttribute("title"), "Most Recent",
"ToolTip message doesn't match");

// mouse hover 'most Recent' sort by icon in blog widget

getPages().mashupRuntimePage().postMostRecentSortByIconBlogWidget(CUSTOM_BLOG_6_WID
GET_ID).mouseOver();

// Take screenshot to verify changes.


ScreenCapture.captureScreenshot(webdriver.getWebDriver(),
getScreenshotDestination(1, "ButtonsHoverStyle"));
}

@Requirements(reqs = { "TW-23101" })
@Test(
description = "Verify BlogButtonsStyle, BlogPostToolbarStyle,
BlogPostStyle, BlogHeaderStyle, BlogStyle" +
"by taking a screenshot for visual comparison",
groups = { "VISUAL_TESTING", "BLOG" })
public void blogWidgetBlogStyleTest() throws Exception {

BLOG_POST_ENTRIES.put(POST_TITLE1, POST_TITLE1_CONTENT);
BLOG_POST_ENTRIES.put(POST_TITLE2, POST_TITLE2_CONTENT);

try {
// navigate to Mashup Widget Blog
navigateMashupRuntimeFullyLoaded(MASHUP_NAME_BLOG_3,
CUSTOM_BLOG_6_WIDGET_ID, VERIFY_ELEMENT_VISIBILITY);

// add 2 new posts and verify they are added successfully via add New
Post Button
addNewPostsToBlog(CUSTOM_BLOG_6_WIDGET_ID, BLOG_POST_ENTRIES);
verifyAllPostsInBlog(CUSTOM_BLOG_6_WIDGET_ID, BLOG_POST_ENTRIES);

// Take screenshot to verify changes.


ScreenCapture.captureScreenshot(webdriver.getWebDriver(),
getScreenshotDestination(1, "BlogStyle"));
} finally {
// delete all the blogEntries
getThingworxRESTUtils().executeService(TWConstants.THINGS,
CUSTOM_BLOG_1_TITLE, PURGE_BLOG_ENTRIES_SERVICE_NAME,
PURGE_BLOG_ENTRIES_PARAMETERS);
}
}
@Requirements(reqs = { "TW-23101" })
@Test(
description = "Verify Blog post link style by taking screenshot for visual
comparison. Click on AddNewPost in" +
" Blog Widget to add a new post with title 'Title1' and in
content section click on " +
"Link -> Insert Link, then add 'www'ptc.com in URL box and
'PTC' as Text box. ",
groups = { "VISUAL_TESTING", "BLOG" })
public void blogWidgetBlogLinksStyleTest() throws Exception {

final String urlLink = "www.ptc.com";


final String urlText = "PTC";
try {

// navigate to Mashup Widget Blog


navigateMashupRuntimeFullyLoaded(MASHUP_NAME_BLOG_3,
CUSTOM_BLOG_6_WIDGET_ID, VERIFY_ELEMENT_VISIBILITY);

// add 2 new posts and verify they are added successfully via add New
Post Button
addNewPostWithLinkToBlog(CUSTOM_BLOG_6_WIDGET_ID, POST_TITLE1, urlLink,
urlText);
verifyPostTitleAndContentInBlog(CUSTOM_BLOG_6_WIDGET_ID, POST_TITLE1,
urlText);

// Take screenshot to verify changes.


ScreenCapture.captureScreenshot(webdriver.getWebDriver(),
getScreenshotDestination(1, "BlogLinkStyle"));
} finally {
// delete all the blogEntries
getThingworxRESTUtils().executeService(TWConstants.THINGS,
CUSTOM_BLOG_1_TITLE, PURGE_BLOG_ENTRIES_SERVICE_NAME,
PURGE_BLOG_ENTRIES_PARAMETERS);
}
}

@Requirements(reqs = { "TW-23101" })
@Test(
description = "Verifies Long Title property of Blog widget - 1) Enter Long
title in the text area labelled " +
"as 'Input Title' 2) Click on refresh icon on upper left
corner of 'CustomBlogTest1' blog entity." +
"3) Verify the title of 'CustomBlogTest1' blog entity
updated with dots in the end by taking screenshot " +
"for visual Comparison",
groups = { "VISUAL_TESTING", "BLOG" })
public void blogWidgetTitlePropertyTest() throws Exception {

// navigate to Mashup Widget Blog


navigateMashupRuntimeFullyLoaded(MASHUP_NAME, INPUT_BLOG_TEXTBOX_WIDGET_ID,
VERIFY_ELEMENT_FOCUS);

// enter value in Input Blog(linked to Blog name on right pane) as


'NotBlogEntity'
getPages().mashupRuntimePage().textBoxInput(INPUT_TITLE_TEXTBOX_WIDGET_ID,
NEW_TITLE);
// click refresh Blog button

getPages().mashupRuntimePage().refreshButtonBlogWidget(CUSTOM_BLOG_5_WIDGET_ID).cli
ck();

// wait for Blog title to change

getPages().mashupRuntimePage().titleOfBlogWidget(CUSTOM_BLOG_5_WIDGET_ID).waitForEl
ementAttributeValueToBeEqualTo("title",
NEW_TITLE);

// Take screenshot to Verify the title of 'CustomBlogTest1' blog entity


updated with dots in the end.
ScreenCapture.captureScreenshot(webdriver.getWebDriver(),
getScreenshotDestination(1, "LongBlogTitleEndedWithDots"));
}

private void addNewPostsToBlog(String blogWidgetID, Map<String, String>


postDetails) throws Exception {

// add multiple posts


int postSequence = 0;
for (Entry<String, String> newPostEntry : postDetails.entrySet()) {
addNewPostToBlog(blogWidgetID, postSequence, newPostEntry.getKey(),
newPostEntry.getValue());
postSequence++;
}
}

private void addNewPostToBlog(String blogWidgetID, int postContentID, String


postTitleName, String postContent)
throws InterruptedException {

// wait for visibility of desired blog

getPages().mashupRuntimePage().widgetContainer(blogWidgetID).waitForVisibilityOfEle
ment();

// click on 'Add Post Button'.

getPages().mashupRuntimePage().addPostButtonBlogWidget(blogWidgetID).click();

// add blog post title


addBlogPostTitle(postTitleName);

// add new Post Content


addNewBlogPostContent(postContentID, postContent);

// Click on Post button


getPages().mashupRuntimePage().postSaveButtonBlogWidget().click();

// refresh to move to main blog window(in case of 'List view' there is no


way to navigate back other than click outside the List
// popup or refresh browser)
getWebdriver().navigate().refresh();
}

private void addNewPostWithLinkToBlog(String blogWidgetID, String


postTitleName, String urlName, String urlText)
throws InterruptedException {

// wait for visibility of desired blog

getPages().mashupRuntimePage().widgetContainer(blogWidgetID).waitForVisibilityOfEle
ment();

// click on 'Add Post Button'.

getPages().mashupRuntimePage().addPostButtonBlogWidget(blogWidgetID).click();

// add blog post title


addBlogPostTitle(postTitleName);

// add Link in post of blog


addLinkToBlogPost(urlName, urlText);

// Click on Post button


getPages().mashupRuntimePage().postSaveButtonBlogWidget().click();
}

private void addLinkToBlogPost(String urlName, String urlText) throws


InterruptedException {

// Select 'Link' from blog post toolbar


getPages().mashupRuntimePage().postToolBarItemsBlogWidget("Link").click();

// click to insert Link option from dropdown

getPages().mashupRuntimePage().postInsertLinkDropdownBlogWidget().waitForVisibility
OfElement();
getPages().mashupRuntimePage().postInsertLinkDropdownBlogWidget().click();

// Enter Link url

getPages().mashupRuntimePage().postAddUrlBlogWidget().waitForVisibilityOfElement();
final int retry = 3;
// added retries to add title as sometimes it is not able to add title
completely
for (int i = 0; i < retry; i++) {
try {

getPages().mashupRuntimePage().postAddUrlBlogWidget().enter(urlName);

getPages().mashupRuntimePage().postAddUrlBlogWidget().waitForElementAttributeValueT
oBeEqualTo("value", urlName);
break;
} catch (Exception e) {
if (i == retry - 1) {
throw e;
}
}
}

// Enter Link url text


for (int i = 0; i < retry; i++) {
try {

getPages().mashupRuntimePage().postAddUrlTextBlogWidget().enter(urlText);
getPages().mashupRuntimePage().postAddUrlTextBlogWidget().waitForElementAttributeVa
lueToBeEqualTo("value", urlText);
break;
} catch (Exception e) {
if (i == retry - 1) {
throw e;
}
}
}

// click on button 'Insert', wait for invisibility is added to release


control from modal action buttons

getPages().mashupRuntimePage().redactorToolBarDropActOnBlogPostBlogWidget().waitFor
InvisibilityOfElement();

getPages().mashupRuntimePage().insertButtonOnInsertLinkOnBlogPostBlogWidget().click
();

getPages().mashupRuntimePage().redactorModalDialogFadeOutOnBlogPostBlogWidget().wai
tForInvisibilityOfElement();
}

private void addBlogPostTitle(String postTitleName) {

// Enter new post title

getPages().mashupRuntimePage().postTitleTextboxBlogWidget().waitForVisibilityOfElem
ent();
final int retry = 3;
// added retries to add title as sometimes it is not able to add title
completely
for (int i = 0; i < retry; i++) {
try {

getPages().mashupRuntimePage().postTitleTextboxBlogWidget().enter(postTitleName);

getPages().mashupRuntimePage().postTitleTextboxBlogWidget().waitForElementAttribute
ValueToBeEqualTo("value", postTitleName);
break;
} catch (Exception e) {
if (i == retry - 1) {
throw e;
}
}
}
}

private void addNewBlogPostContent(int postContentID, String postContent) {

// Enter new post content

getPages().mashupRuntimePage().postContentTextareaBlogWidget().waitForVisibilityOfE
lement();

final int retry = 3;


// added retries to add post contents as sometimes it is not able to add
contents completely 1st time (SendKeys issue)
for (int i = 0; i < retry; i++) {
try {

getPages().mashupRuntimePage().postContentTextareaBlogWidget().enter(postContent);

getPages().mashupRuntimePage().postContentTextareaBlogWidget().waitForElementTextVa
lueToBeEqualTo(postContent);
break;
} catch (Exception e) {
if (i == retry - 1) {
throw e;
}
}
}
}

private void verifyAllPostsInBlog(String blogWidgetID, Map<String, String>


postDetails) throws Exception {

final int retry = 5;

List<String> blogEntriesTitles = null;


List<String> blogEntriesContents = null;

// wait until all blog post gets loaded in blog


for (int i = 0; i < retry; i++) {
try {
blogEntriesTitles = new ArrayList<String>();
blogEntriesContents = new ArrayList<String>();
if
(getPages().mashupRuntimePage().titlesOfPostsBlogWidget(blogWidgetID).size() ==
postDetails.size()) {
// add all the titles and its contents to respective arrayList
for (int j = 0; j < postDetails.size(); j++) {

blogEntriesTitles.add(getPages().mashupRuntimePage().titlesOfPostsBlogWidget(blogWi
dgetID).get(j).getText());

blogEntriesContents.add(getPages().mashupRuntimePage().contentOfPostsBlogWidget(blo
gWidgetID).get(j).getText());
}
break;
}
} catch (Exception e) {
if (i == retry - 1) {
throw e;
}
}
}

Assert.assertEquals(blogEntriesTitles.size(), postDetails.size(), "Not All


Blog Entries titles are captured");
Assert.assertEquals(blogEntriesContents.size(), postDetails.size(), "Not
All Blog Entries Post Contents are captured");

// verify all expected blog titles are present in blog


Assert.assertTrue(blogEntriesTitles.containsAll(postDetails.keySet()),
"All Expected Blog titles are not present. Expected : " +
postDetails.keySet() + "Actual :" + blogEntriesTitles);

// verify all expected blog contents are present in blog


Assert.assertTrue(blogEntriesContents.containsAll(postDetails.values()),
"All Expected Blog post contents are not present. Expected : " +
postDetails.values() + "Actual :" + blogEntriesContents);
}

private void verifyAllPostsTitleInBlog(String blogWidgetID, Map<String, String>


postDetails) throws Exception {

// added wait for 'Add Post' button of blog to verify that main blog page
is opened

getPages().mashupRuntimePage().addPostButtonBlogWidget(blogWidgetID).waitForVisibil
ityOfElement();

// wait until blog post gets loaded in blog

getPages().mashupRuntimePage().widgetContainer(blogWidgetID).getWebDriverFluentWait
()
.until((WebDriver wd) ->
getPages().mashupRuntimePage().titlesOfPostsBlogWidget(blogWidgetID).size() ==
postDetails.size());

List<String> blogEntriesTitles = new ArrayList<String>();

// add all the titles and its contents to respective arrayList


for (int i = 0; i < postDetails.size(); i++) {

blogEntriesTitles.add(getPages().mashupRuntimePage().titlesOfPostsBlogWidget(blogWi
dgetID).get(i).getText());
}

// verify all expected blog titles are present in blog


Assert.assertTrue(blogEntriesTitles.containsAll(postDetails.keySet()),
"All Expected Blog titles are not present. Expected : " +
postDetails.keySet() + "Actual :" + blogEntriesTitles);
}

private void verifyPostTitleAndContentInBlog(String blogWidgetID, String


postTitleName, String... postContents) {

// Verify the post title for added blog post

Assert.assertEquals(getPages().mashupRuntimePage().titleOfPostBlogWidget(blogWidget
ID, 1).getText(), postTitleName,
"Incorrect title dispalyed for blog post on blog list");

// Verify blocks of post contents for newly added blog post


for (String postContent : postContents) {

Assert.assertTrue(getPages().mashupRuntimePage().contentOfPostBlogWidget(blogWidget
ID, 1).getText().contains(postContent),
"Incorrect content displayed for blog post on blog list. Actual :"
+

getPages().mashupRuntimePage().contentOfPostBlogWidget(blogWidgetID, 1).getText() +
"Expected : " +
postContent);
}
}

private void addNewInlinePost(String widgetID, Entry<String, String> blogEntry)


throws InterruptedException {

// add inline Title


final int retry = 3;
// added retries to add post contents as sometimes it is not able to add
contents completely 1st time (SendKeys issue)
for (int i = 0; i < retry; i++) {
try {

getPages().mashupRuntimePage().postAddInlineTitleBlogWidget(widgetID).enter(blogEnt
ry.getKey().toString());

getPages().mashupRuntimePage().postAddInlineTitleBlogWidget(widgetID).waitForElemen
tAttributeValueToBeEqualTo("value",
blogEntry.getKey().toString());
break;
} catch (Exception e) {
if (i == retry - 1) {
throw e;
}
}
}

// add inline text


for (int i = 0; i < retry; i++) {
try {

getPages().mashupRuntimePage().postAddInlineTextBlogWidget(widgetID).enter(blogEntr
y.getValue().toString());

getPages().mashupRuntimePage().postAddInlineTextBlogWidget(widgetID).waitForElement
AttributeValueToBeEqualTo("value",
blogEntry.getValue().toString());
break;
} catch (Exception e) {
if (i == retry - 1) {
throw e;
}
}
}

// click on submit button

getPages().mashupRuntimePage().postInlineSubmitButtonBlogWidget(widgetID).click();
}

private void navigateMashupRuntimeFullyLoaded(String mashupName, String


ensureElementName, String verifyElementFocusOrVisibility)
throws UnsupportedEncodingException {
navigateToMashupInRuntime(mashupName);
if (verifyElementFocusOrVisibility.equalsIgnoreCase("Visibility")) {

getPages().mashupRuntimePage().widgetContainer(ensureElementName).waitForVisibility
OfElement();
} else if (verifyElementFocusOrVisibility.equalsIgnoreCase("Focus")) {
try {

getPages().mashupRuntimePage().waitForFocusOfWidget(ensureElementName);
} catch (Exception e) {

getPages().mashupRuntimePage().textboxWidget(ensureElementName).click();
}
}
}
}

You might also like