From d3343521944c5c17a25c2409099113ca30aeaa6f Mon Sep 17 00:00:00 2001 From: Hemani Date: Fri, 3 Nov 2017 18:55:48 +0530 Subject: [PATCH] chore: Additional tests for the new banner and version verification. (#400) --- .../tests/pagetests/BlogPageTest.java | 20 +++++++++ .../tests/pagetests/ModulesPageTest.java | 21 +++++++++ .../pom/fragmentObjects/BlogFragment.java | 17 +++++++ .../NavigationListFragment.java | 45 ++++++++++++++++--- .../tests/pom/pageObjects/BlogPage.java | 4 ++ .../pom/pageObjects/StandaloneModulePage.java | 12 +++++ .../GitHubProjectVersionExtractor.java | 39 ++++++++++++++++ .../tests/utilities/PageNavigator.java | 2 - 8 files changed, 151 insertions(+), 9 deletions(-) create mode 100644 src/test/java/org/arquillian/tests/utilities/GitHubProjectVersionExtractor.java diff --git a/src/test/java/org/arquillian/tests/pagetests/BlogPageTest.java b/src/test/java/org/arquillian/tests/pagetests/BlogPageTest.java index 38696409092..f012283e927 100644 --- a/src/test/java/org/arquillian/tests/pagetests/BlogPageTest.java +++ b/src/test/java/org/arquillian/tests/pagetests/BlogPageTest.java @@ -72,4 +72,24 @@ public void should_be_able_to_go_to_jacoco_blog_from_cloud_tag() { .hasTitle() .hasReleaseNotes(); } + + @Test + public void should_redirect_to_new_announcement_if_banner_is_present() throws Exception { + mainPage.menu() + .navigate().to("Blog"); + + blogPage.cloudTag() + .navigate().to("drone"); + + blogPage.blogContent() + .verify() + .hasAnnouncementBanner(true); + + blogPage.newAnnouncementBanner() + .navigate().to("Check our latest announcement"); + + blogPage.blogContent() + .verify() + .hasAnnouncementBanner(false); + } } diff --git a/src/test/java/org/arquillian/tests/pagetests/ModulesPageTest.java b/src/test/java/org/arquillian/tests/pagetests/ModulesPageTest.java index f23fc021046..167a6d82a80 100644 --- a/src/test/java/org/arquillian/tests/pagetests/ModulesPageTest.java +++ b/src/test/java/org/arquillian/tests/pagetests/ModulesPageTest.java @@ -100,4 +100,25 @@ public void should_navigate_to_documentation_page_if_present() throws Exception .hasTitle("Arquillian - So you can rule your code. Not the bugs.") .hasContent();*/ } + + @Test + public void should_verify_individual_module_page_lists_the_latest_project_version() throws Exception { + mainPage.menu() + .navigate().to("Modules"); + + modulesPage.navigationList() + .navigate().to("Core"); + + fetchedModulePage.verify().hasLatestRelease(); + } + + @Test + public void should_verify_modules_page_lists_modules_with_latest_project_version() throws Exception { + mainPage.menu() + .navigate().to("Modules"); + + modulesPage.navigationList() + .verify() + .containsEntriesWithLatestVersion("Core", "Smart Testing"); + } } diff --git a/src/test/java/org/arquillian/tests/pom/fragmentObjects/BlogFragment.java b/src/test/java/org/arquillian/tests/pom/fragmentObjects/BlogFragment.java index 5456bf6bb25..081c02bd40c 100644 --- a/src/test/java/org/arquillian/tests/pom/fragmentObjects/BlogFragment.java +++ b/src/test/java/org/arquillian/tests/pom/fragmentObjects/BlogFragment.java @@ -1,6 +1,7 @@ package org.arquillian.tests.pom.fragmentObjects; import java.util.List; +import org.arquillian.tests.utilities.PageNavigator; import org.jboss.arquillian.graphene.fragment.Root; import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; @@ -47,8 +48,24 @@ public BlogVerifier hasReleaseNotes() { 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); + } } diff --git a/src/test/java/org/arquillian/tests/pom/fragmentObjects/NavigationListFragment.java b/src/test/java/org/arquillian/tests/pom/fragmentObjects/NavigationListFragment.java index 644739a9977..e132fdbedf4 100644 --- a/src/test/java/org/arquillian/tests/pom/fragmentObjects/NavigationListFragment.java +++ b/src/test/java/org/arquillian/tests/pom/fragmentObjects/NavigationListFragment.java @@ -1,16 +1,24 @@ package org.arquillian.tests.pom.fragmentObjects; +import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; +import org.arquillian.tests.utilities.GitHubProjectVersionExtractor; import org.arquillian.tests.utilities.PageNavigator; +import org.jboss.arquillian.drone.api.annotation.Drone; +import org.jboss.arquillian.graphene.Graphene; import org.jboss.arquillian.graphene.fragment.Root; import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import static org.assertj.core.api.Assertions.assertThat; public class NavigationListFragment { + @Drone + private WebDriver driver; + @Root private WebElement navListRoot; @@ -23,20 +31,43 @@ public class NavigationListVerifier { public NavigationListVerifier containsEntries(String... expectedItems) { final List fragmentItems = navListRoot.findElements(By.cssSelector("li a")); List fragmentItemsTitles = - fragmentItems.stream().map(list -> formatTitle(list.getText())).collect(Collectors.toList()); + fragmentItems.stream().map(list -> formatTitle(list.getText())[0].trim()).collect(Collectors.toList()); assertThat(fragmentItemsTitles).contains(expectedItems); return this; } - private String formatTitle(String title) { - String version = "SNAPSHOT"; - if (title.contains(version)) { - String[] titleArray = title.split(version); - return titleArray[0].trim(); + public NavigationListVerifier containsEntriesWithLatestVersion(String... expectedItems) { + Arrays.stream(expectedItems).forEach(expectedItem -> { + List fragmentItems = navListRoot.findElements(By.cssSelector("li a")); + fragmentItems.stream() + .filter(list -> formatTitle(list.getText())[0].trim().contains(expectedItem)) + .forEach(list -> { + String latestVersion = formatTitle(list.getText())[1].trim(); + String project = getProjectRepo(list); + assertThat(latestVersion) + .isEqualTo(new GitHubProjectVersionExtractor(project).getLatestReleaseFromGitHub()); + }); + } + ); + return this; + } + + private String getProjectRepo(WebElement list) { + final By xpath = By.xpath(".//dt[contains(text(),'Web URL')]/following-sibling::dd[1]"); + list.click(); + Graphene.waitModel().until().element(xpath).is().visible(); + String project = driver.findElement(xpath).getText(); + driver.navigate().to("http://arquillian.org/modules/"); + return project; + } + + private String[] formatTitle(String title) { + if (title.contains("SNAPSHOT")) { + return title.split("((?<=SNAPSHOT)|(?=SNAPSHOT))"); } - return title.substring(0, (title.indexOf("–") - 1)); + return title.split("–"); } } diff --git a/src/test/java/org/arquillian/tests/pom/pageObjects/BlogPage.java b/src/test/java/org/arquillian/tests/pom/pageObjects/BlogPage.java index 92cbe900f44..7f47d2cc5b2 100644 --- a/src/test/java/org/arquillian/tests/pom/pageObjects/BlogPage.java +++ b/src/test/java/org/arquillian/tests/pom/pageObjects/BlogPage.java @@ -37,4 +37,8 @@ public CloudTagFragment cloudTag() { public PageVerifier verify() { return new PageVerifier(driver); } + + public BlogFragment newAnnouncementBanner() { + return blogContent; + } } diff --git a/src/test/java/org/arquillian/tests/pom/pageObjects/StandaloneModulePage.java b/src/test/java/org/arquillian/tests/pom/pageObjects/StandaloneModulePage.java index d262a65b9fe..fb558527730 100644 --- a/src/test/java/org/arquillian/tests/pom/pageObjects/StandaloneModulePage.java +++ b/src/test/java/org/arquillian/tests/pom/pageObjects/StandaloneModulePage.java @@ -1,5 +1,6 @@ package org.arquillian.tests.pom.pageObjects; +import org.arquillian.tests.utilities.GitHubProjectVersionExtractor; import org.arquillian.tests.utilities.PageNavigator; import org.jboss.arquillian.drone.api.annotation.Drone; import org.jboss.arquillian.graphene.Graphene; @@ -65,6 +66,17 @@ public IndividualModulePageVerifier hasDocumentation(Boolean value) { } return this; } + + public IndividualModulePageVerifier hasLatestRelease() { + String latestRelease = contentRoot.findElement(By.className("label")).getText(); + String project = contentRoot + .findElement(By.xpath(".//dt[contains(text(),'Web URL')]/following-sibling::dd[1]")).getText(); + + assertThat(latestRelease) + .isEqualTo(new GitHubProjectVersionExtractor(project).getLatestReleaseFromGitHub()); + + return this; + } } } diff --git a/src/test/java/org/arquillian/tests/utilities/GitHubProjectVersionExtractor.java b/src/test/java/org/arquillian/tests/utilities/GitHubProjectVersionExtractor.java new file mode 100644 index 00000000000..4013cd02465 --- /dev/null +++ b/src/test/java/org/arquillian/tests/utilities/GitHubProjectVersionExtractor.java @@ -0,0 +1,39 @@ +package org.arquillian.tests.utilities; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import org.apache.http.client.utils.URIBuilder; +import org.jboss.arquillian.drone.webdriver.utils.HttpClient; + +public class GitHubProjectVersionExtractor { + + private String TAGS_URL = "/tags"; + private String TAG_NAME = "name"; + private String project; + + public GitHubProjectVersionExtractor(String project) { + this.project = String.format("https://api.github.com/repos/arquillian/%s", project); + } + + public String getLatestReleaseFromGitHub() { + try { + final HttpClient.Response response = sentGetRequestWithPagination(project + TAGS_URL, 1); + JsonArray releaseTags = new Gson().fromJson(response.getPayload(), JsonElement.class).getAsJsonArray(); + if (releaseTags.size() == 0) { + return null; + } + return releaseTags.get(0).getAsJsonObject().get(TAG_NAME).getAsString(); + } catch (Exception e) { + throw new RuntimeException("Failed to fetch latest release from GitHub.", e); + } + } + + private HttpClient.Response sentGetRequestWithPagination(String url, int pageNumber) throws Exception { + final URIBuilder uriBuilder = new URIBuilder(url); + if (pageNumber != 1) { + uriBuilder.setParameter("page", String.valueOf(pageNumber)); + } + return new HttpClient().get(uriBuilder.build().toString()); + } +} diff --git a/src/test/java/org/arquillian/tests/utilities/PageNavigator.java b/src/test/java/org/arquillian/tests/utilities/PageNavigator.java index 92d3126696f..d5ebcf07f9f 100644 --- a/src/test/java/org/arquillian/tests/utilities/PageNavigator.java +++ b/src/test/java/org/arquillian/tests/utilities/PageNavigator.java @@ -4,8 +4,6 @@ import org.openqa.selenium.By; import org.openqa.selenium.WebElement; -import static org.jboss.arquillian.graphene.Graphene.waitGui; - public class PageNavigator { private WebElement fragmentRoot;