Professional Documents
Culture Documents
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 static final String NEW_TITLE = "New Title for this Blog Long Text New
Title for this Blog Long Text New Title for this";
@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());
}
@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);
@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);
@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);
@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);
@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 {
getPages().mashupRuntimePage().addPostButtonBlogWidget(CUSTOM_BLOG_6_WIDGET_ID).wai
tForVisibilityOfElement();
getPages().mashupRuntimePage().addPostButtonBlogWidget(CUSTOM_BLOG_6_WIDGET_ID).cli
ckAndHold();
@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);
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");
getPages().mashupRuntimePage().postMostRecentSortByIconBlogWidget(CUSTOM_BLOG_6_WID
GET_ID).mouseOver();
@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);
// 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);
@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 {
getPages().mashupRuntimePage().refreshButtonBlogWidget(CUSTOM_BLOG_5_WIDGET_ID).cli
ck();
getPages().mashupRuntimePage().titleOfBlogWidget(CUSTOM_BLOG_5_WIDGET_ID).waitForEl
ementAttributeValueToBeEqualTo("title",
NEW_TITLE);
getPages().mashupRuntimePage().widgetContainer(blogWidgetID).waitForVisibilityOfEle
ment();
getPages().mashupRuntimePage().addPostButtonBlogWidget(blogWidgetID).click();
getPages().mashupRuntimePage().widgetContainer(blogWidgetID).waitForVisibilityOfEle
ment();
getPages().mashupRuntimePage().addPostButtonBlogWidget(blogWidgetID).click();
getPages().mashupRuntimePage().postInsertLinkDropdownBlogWidget().waitForVisibility
OfElement();
getPages().mashupRuntimePage().postInsertLinkDropdownBlogWidget().click();
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;
}
}
}
getPages().mashupRuntimePage().postAddUrlTextBlogWidget().enter(urlText);
getPages().mashupRuntimePage().postAddUrlTextBlogWidget().waitForElementAttributeVa
lueToBeEqualTo("value", urlText);
break;
} catch (Exception e) {
if (i == retry - 1) {
throw e;
}
}
}
getPages().mashupRuntimePage().redactorToolBarDropActOnBlogPostBlogWidget().waitFor
InvisibilityOfElement();
getPages().mashupRuntimePage().insertButtonOnInsertLinkOnBlogPostBlogWidget().click
();
getPages().mashupRuntimePage().redactorModalDialogFadeOutOnBlogPostBlogWidget().wai
tForInvisibilityOfElement();
}
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;
}
}
}
}
getPages().mashupRuntimePage().postContentTextareaBlogWidget().waitForVisibilityOfE
lement();
getPages().mashupRuntimePage().postContentTextareaBlogWidget().enter(postContent);
getPages().mashupRuntimePage().postContentTextareaBlogWidget().waitForElementTextVa
lueToBeEqualTo(postContent);
break;
} catch (Exception e) {
if (i == retry - 1) {
throw e;
}
}
}
}
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;
}
}
}
// added wait for 'Add Post' button of blog to verify that main blog page
is opened
getPages().mashupRuntimePage().addPostButtonBlogWidget(blogWidgetID).waitForVisibil
ityOfElement();
getPages().mashupRuntimePage().widgetContainer(blogWidgetID).getWebDriverFluentWait
()
.until((WebDriver wd) ->
getPages().mashupRuntimePage().titlesOfPostsBlogWidget(blogWidgetID).size() ==
postDetails.size());
blogEntriesTitles.add(getPages().mashupRuntimePage().titlesOfPostsBlogWidget(blogWi
dgetID).get(i).getText());
}
Assert.assertEquals(getPages().mashupRuntimePage().titleOfPostBlogWidget(blogWidget
ID, 1).getText(), postTitleName,
"Incorrect title dispalyed for blog post on blog list");
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);
}
}
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;
}
}
}
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;
}
}
}
getPages().mashupRuntimePage().postInlineSubmitButtonBlogWidget(widgetID).click();
}
getPages().mashupRuntimePage().widgetContainer(ensureElementName).waitForVisibility
OfElement();
} else if (verifyElementFocusOrVisibility.equalsIgnoreCase("Focus")) {
try {
getPages().mashupRuntimePage().waitForFocusOfWidget(ensureElementName);
} catch (Exception e) {
getPages().mashupRuntimePage().textboxWidget(ensureElementName).click();
}
}
}
}