Skip to content

Commit

Permalink
test: contributor page (#1900)
Browse files Browse the repository at this point in the history
  • Loading branch information
nya-elimu authored Sep 29, 2024
2 parents 8500dea + eb10c8f commit 1fefa7d
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/jsp/contributor/contributor.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</c:choose>
</content:title>

<content:section cssId="contributorStoryBooksPage">
<content:section cssId="contributorPage">
<%@ include file="/WEB-INF/jsp/contributor/contributor-summarized.jsp" %>

<ul class="tabs tabs-transparent deep-purple lighten-1 z-depth-1" style="border-radius: 8px;">
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/jsp/contributor/list.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<c:forEach var="contributor" items="${contributors}">
<div class="col s6 m4 l3">
<div class="card contributor">
<a href="<spring:url value='/contributor/${contributor.id}' />">
<a class="contributorCardImageLink" href="<spring:url value='/contributor/${contributor.id}' />">
<div class="card-image">
<c:choose>
<c:when test="${not empty contributor.imageUrl}">
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/selenium/contributor/ContributorListPage.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package selenium.contributor;

import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import selenium.util.ErrorHelper;

public class ContributorListPage {

private Logger logger = LogManager.getLogger();

private WebDriver driver;

public ContributorListPage(WebDriver driver) {
Expand All @@ -16,4 +23,13 @@ public ContributorListPage(WebDriver driver) {

ErrorHelper.verifyNoScriptOrMarkupError(driver);
}

public void pressRandomContributor() {
List<WebElement> contributorLinks = driver.findElements(By.className("contributorCardImageLink"));
logger.info("contributorLinks.size(): " + contributorLinks.size());
int randomIndex = (int) (Math.random() * contributorLinks.size());
logger.info("randomIndex: " + randomIndex);
WebElement contributorLink = contributorLinks.get(randomIndex);
contributorLink.click();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,8 @@ public void testContributorListPage() {
logger.info("testContributorListPage");

ContributorListPage contributorListPage = new ContributorListPage(driver);
contributorListPage.pressRandomContributor();

ContributorPage contributorPage = new ContributorPage(driver);
}
}
18 changes: 18 additions & 0 deletions src/test/java/selenium/contributor/ContributorPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package selenium.contributor;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import selenium.util.ErrorHelper;

public class ContributorPage {

private WebDriver driver;

public ContributorPage(WebDriver driver) {
this.driver = driver;

driver.findElement(By.id("contributorPage"));

ErrorHelper.verifyNoScriptOrMarkupError(driver);
}
}
55 changes: 55 additions & 0 deletions src/test/java/selenium/contributor/ContributorPageTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package selenium.contributor;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import selenium.util.DomainHelper;

public class ContributorPageTest {

private final Logger logger = LogManager.getLogger();

private WebDriver driver;

@BeforeEach
public void setUp() {
logger.info("setUp");

ChromeOptions chromeOptions = new ChromeOptions();

// Read "headless" property set on the command line:
// mvn clean verify -P regression-test-ui -D headless=true
String headlessSystemProperty = System.getProperty("headless");
logger.info("headlessSystemProperty: \"" + headlessSystemProperty + "\"");
if ("true".equals(headlessSystemProperty)) {
chromeOptions.addArguments("headless");
}

driver = new ChromeDriver(chromeOptions);

driver.get(DomainHelper.getBaseUrl() + "/contributor/list");
}

@AfterEach
public void tearDown() {
logger.info("tearDown");

driver.quit();
}

@Test
public void testContributorPage() {
logger.info("testContributorPage");

ContributorListPage contributorListPage = new ContributorListPage(driver);
contributorListPage.pressRandomContributor();

ContributorPage contributorPage = new ContributorPage(driver);
}
}

0 comments on commit 1fefa7d

Please sign in to comment.