Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional tests for the new banner and version verification. #400

Merged
merged 5 commits into from
Nov 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/test/java/org/arquillian/tests/pagetests/BlogPageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
21 changes: 21 additions & 0 deletions src/test/java/org/arquillian/tests/pagetests/ModulesPageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -23,20 +31,43 @@ public class NavigationListVerifier {
public NavigationListVerifier containsEntries(String... expectedItems) {
final List<WebElement> fragmentItems = navListRoot.findElements(By.cssSelector("li a"));
List<String> 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<WebElement> 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("–");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ public CloudTagFragment cloudTag() {
public PageVerifier verify() {
return new PageVerifier(driver);
}

public BlogFragment newAnnouncementBanner() {
return blogContent;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}
}
}

Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down