Skip to content

Commit

Permalink
fix(#412): adds check for blog post type. (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
hemanik authored and bartoszmajsak committed Dec 20, 2017
1 parent 975e710 commit e792799
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 75 deletions.
54 changes: 38 additions & 16 deletions src/test/java/org/arquillian/tests/pagetests/BlogPageTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.arquillian.tests.pagetests;

import org.arquillian.tests.utilities.BlogVerifier;
import org.arquillian.tests.pom.pageObjects.BlogPage;
import org.arquillian.tests.pom.pageObjects.MainPage;
import org.arquillian.tests.pom.pageObjects.StandalonePage;
Expand All @@ -12,6 +13,11 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(Arquillian.class)
@RunAsClient
Expand All @@ -35,15 +41,16 @@ public void open() {
}

@Test
public void should_have_content_listing_all_blogs_with_title_and_release_notes() throws Exception {
public void should_have_content_listing_all_release_blogs_with_title_and_release_notes() throws Exception {

mainPage.menu()
.navigate().to("Blog");

blogPage.blogContent()
.verify()
.hasTitle()
.hasReleaseNotes();
List<WebElement> releaseBlogs = blogPage.releaseBlogs();

assertThat(releaseBlogs)
.allSatisfy(BlogVerifier::hasTitle)
.allSatisfy(BlogVerifier::hasReleaseNotes);
}

@Test
Expand All @@ -53,7 +60,7 @@ public void should_have_sidebar_with_sub_sections() throws Exception {

blogPage.sidebar()
.verify()
.hasSubSectionHeaders("Subscribe to the Arquillian Blog", "Latest Posts", "Popular Posts", "Tags");
.hasSubSectionHeaders("Subscribe to the Arquillian Blog", "Latest Posts", "Popular Posts", "Tags");
}

@Test
Expand All @@ -67,10 +74,11 @@ public void should_be_able_to_go_to_jacoco_blog_from_cloud_tag() {
fetchedBlogPage.verify().hasTitle("Arquillian Blog · Arquillian")
.hasContent();

blogPage.blogContent()
.verify()
.hasTitle()
.hasReleaseNotes();
List<WebElement> releaseBlogs = blogPage.releaseBlogs();

assertThat(releaseBlogs)
.allSatisfy(BlogVerifier::hasTitle)
.allSatisfy(BlogVerifier::hasReleaseNotes);
}

@Test
Expand All @@ -81,15 +89,29 @@ public void should_redirect_to_new_announcement_if_banner_is_present() throws Ex
blogPage.cloudTag()
.navigate().to("drone");

blogPage.blogContent()
.verify()
.hasAnnouncementBanner(true);
List<WebElement> releaseBlogs = blogPage.releaseBlogs();

assertThat(releaseBlogs).anySatisfy(BlogVerifier::haveAnnouncementBanner);

blogPage.newAnnouncementBanner()
.navigate().to("Check our latest announcement");

blogPage.blogContent()
.verify()
.hasAnnouncementBanner(false);
WebElement newReleaseBlog = blogPage.releaseBlogs().get(0);

assertThat(newReleaseBlog).satisfies(BlogVerifier::doesNotHaveAnnouncementBanner);
}

@Test
public void should_ignore_release_notes_for_non_release_blog_posts() throws Exception {
mainPage.menu()
.navigate().to("Blog");

blogPage.cloudTag()
.navigate().to("nonrelease");

List<WebElement> nonReleaseBlogs = blogPage.nonReleaseBlogs();

assertThat(nonReleaseBlogs)
.allSatisfy(BlogVerifier::hasTitle);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package org.arquillian.tests.pom.fragmentObjects;

import org.arquillian.tests.utilities.BlogVerifier;
import org.arquillian.tests.utilities.PageNavigator;
import org.jboss.arquillian.graphene.fragment.Root;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

public class BlogFragment {

@Root
Expand All @@ -19,56 +14,6 @@ public BlogVerifier verify() {
return new BlogVerifier();
}

public class BlogVerifier {

final List<WebElement> fragmentItems = contentRoot.findElements(By.cssSelector("[class='post']"));

public BlogVerifier hasTitle() {
for (WebElement blog : fragmentItems) {
WebElement blogTitle = getBlogTitle(blog);
assertThat(blogTitle.isDisplayed()).isTrue();
}
return this;
}

public BlogVerifier hasReleaseNotes() {
for (WebElement item : fragmentItems) {
try {
WebElement releaseNoteTitle =
item.findElement(By.xpath(".//h3[contains(text(),'Release notes and resolved issues')]"));
List<WebElement> releaseNoteContents = item.findElements(By.xpath(".//dl"));

assertThat(releaseNoteTitle.isDisplayed() && releaseNoteContents.stream()
.allMatch(WebElement::isDisplayed)).isTrue();

} catch (NoSuchElementException e) {
throw new NoSuchElementException(
"Missing release notes for blog post titled: " + getBlogTitle(item).getText() + ".\n" +
"If the release was performed manually, this happen because we forgot to: \n" +
"- close the milestone on GitHub or release version on JIRA\n" +
"- push tag to the upstream repo after releasing to Maven Central (git push origin --tags)");
}
}
return this;
}

public BlogVerifier hasAnnouncementBanner(boolean status) {
try {
WebElement announcementBanner = contentRoot.findElement(By.partialLinkText("Check our latest announcement"));
assertThat(announcementBanner.isDisplayed()).isEqualTo(status);
} catch (NoSuchElementException e) {
if(status) {
throw new NoSuchElementException("Missing announcement banner for the blog post.", e);
}
}
return this;
}

private WebElement getBlogTitle(WebElement blog) {
return blog.findElement(By.cssSelector("[class='title'] a"));
}
}

public PageNavigator navigate() {
return new PageNavigator(contentRoot);
}
Expand Down
19 changes: 16 additions & 3 deletions src/test/java/org/arquillian/tests/pom/pageObjects/BlogPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
import org.arquillian.tests.utilities.PageVerifier;
import org.jboss.arquillian.drone.api.annotation.Drone;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import java.util.List;

public class BlogPage {

@Drone
Expand All @@ -22,9 +25,11 @@ public class BlogPage {
@FindBy(css = "[class = 'tag-cloud']")
private CloudTagFragment cloudTag;

public BlogFragment blogContent() {
return blogContent;
}
@FindBy(xpath = ".//a[contains(text(),'release')]/ancestor::article")
private List<WebElement> releaseBlogPosts;

@FindBy(xpath = ".//a[contains(text(),'nonrelease')]/ancestor::article")
private List<WebElement> nonReleaseBlogPosts;

public SideBarFragment sidebar() {
return sidebar;
Expand All @@ -41,4 +46,12 @@ public PageVerifier verify() {
public BlogFragment newAnnouncementBanner() {
return blogContent;
}

public List<WebElement> releaseBlogs() {
return releaseBlogPosts;
}

public List<WebElement> nonReleaseBlogs() {
return nonReleaseBlogPosts;
}
}
71 changes: 71 additions & 0 deletions src/test/java/org/arquillian/tests/utilities/BlogVerifier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package org.arquillian.tests.utilities;

import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

public class BlogVerifier {

public static void hasTitle(WebElement blog) {
WebElement blogTitle = getBlogTitle(blog);
assertThat(blogTitle.isDisplayed()).isTrue();
}

public static void hasReleaseNotes(WebElement item) {
if (hasTypeRelease(item)) {
try {
WebElement releaseNoteTitle =
item.findElement(By.xpath(".//h3[contains(text(),'Release notes and resolved issues')]"));
List<WebElement> releaseNoteContents = item.findElements(By.xpath(".//dl"));

assertThat(releaseNoteTitle.isDisplayed() && releaseNoteContents.stream()
.allMatch(WebElement::isDisplayed)).isTrue();

} catch (NoSuchElementException e) {
throw new NoSuchElementException(
"Missing release notes for blog post titled: " + getBlogTitle(item).getText() + ".\n" +
"If the release was performed manually, this happen because we forgot to: \n" +
"- close the milestone on GitHub or release version on JIRA\n" +
"- push tag to the upstream repo after releasing to Maven Central (git push origin --tags)");
}
}
}

public static void haveAnnouncementBanner(WebElement item) {
try {
WebElement announcementBanner = item.findElement(By.partialLinkText("Check our latest announcement"));
assertThat(announcementBanner.isDisplayed()).isTrue();
} catch (NoSuchElementException e) {
// Ignore if no announcement banner
}
}

public static void doesNotHaveAnnouncementBanner(WebElement item) {
WebElement announcementBanner = null;
try {
announcementBanner = item.findElement(By.partialLinkText("Check our latest announcement"));
assertThat(announcementBanner.isDisplayed()).isFalse();
} catch (NoSuchElementException e) {
assertThat(announcementBanner).isNull();
}
}

private static boolean hasTypeRelease(WebElement item) {
try {
item.findElement(By.linkText("release"));
return true;
} catch (NoSuchElementException e) {
return false;
}
}

private static WebElement getBlogTitle(WebElement blog) {
return blog.findElement(By.cssSelector("[class='title'] a"));
}
}


0 comments on commit e792799

Please sign in to comment.