Skip to content
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
2 changes: 0 additions & 2 deletions .github/workflows/maven-regression-tests-ENG.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ jobs:
distribution: 'temurin'
java-version: 17
cache: maven
- run: mvn clean
- run: mvn verify -P regression-test-rest -D base.url=http://eng.elimu.ai

test_ui:
Expand All @@ -29,5 +28,4 @@ jobs:
distribution: 'temurin'
java-version: 17
cache: maven
- run: mvn clean
- run: mvn verify -P regression-test-ui -D base.url=http://eng.elimu.ai -D headless=true
2 changes: 0 additions & 2 deletions .github/workflows/maven-regression-tests-HIN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ jobs:
distribution: 'temurin'
java-version: 17
cache: maven
- run: mvn clean
- run: mvn verify -P regression-test-rest -D base.url=http://hin.elimu.ai

test_ui:
Expand All @@ -29,5 +28,4 @@ jobs:
distribution: 'temurin'
java-version: 17
cache: maven
- run: mvn clean
- run: mvn verify -P regression-test-ui -D base.url=http://hin.elimu.ai -D headless=true
2 changes: 0 additions & 2 deletions .github/workflows/maven-regression-tests-TGL.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ jobs:
distribution: 'temurin'
java-version: 17
cache: maven
- run: mvn clean
- run: mvn verify -P regression-test-rest -D base.url=http://tgl.elimu.ai

test_ui:
Expand All @@ -29,5 +28,4 @@ jobs:
distribution: 'temurin'
java-version: 17
cache: maven
- run: mvn clean
- run: mvn verify -P regression-test-ui -D base.url=http://tgl.elimu.ai -D headless=true
2 changes: 0 additions & 2 deletions .github/workflows/maven-regression-tests-THA.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ jobs:
distribution: 'temurin'
java-version: 17
cache: maven
- run: mvn clean
- run: mvn verify -P regression-test-rest -D base.url=http://tha.elimu.ai

test_ui:
Expand All @@ -29,5 +28,4 @@ jobs:
distribution: 'temurin'
java-version: 17
cache: maven
- run: mvn clean
- run: mvn verify -P regression-test-ui -D base.url=http://tha.elimu.ai -D headless=true
8 changes: 4 additions & 4 deletions .github/workflows/maven-regression-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Maven Regression Tests
name: Maven Regression Tests (localhost)

on:
push:
Expand All @@ -7,7 +7,7 @@ on:
branches: [ "main" ]

jobs:
test_rest_localhost:
test_rest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -22,8 +22,8 @@ jobs:
- run: sleep 30
- run: mvn verify -P regression-test-rest

test_ui_localhost:
needs: test_rest_localhost
test_ui:
needs: test_rest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion pom-dependency-tree.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ai.elimu:webapp:war:2.5.102-SNAPSHOT
ai.elimu:webapp:war:2.5.103-SNAPSHOT
+- ai.elimu:model:jar:model-2.0.97:compile
| \- com.google.code.gson:gson:jar:2.13.0:compile
| \- com.google.errorprone:error_prone_annotations:jar:2.37.0:compile
Expand Down
4 changes: 2 additions & 2 deletions src/main/webapp/WEB-INF/jsp/content/main.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<span class="card-title"><i class="material-icons">image</i> Images</span>
</div>
<div class="card-action">
<a href="<spring:url value='/content/multimedia/image/list' />">View list (${imageCount})</a>
<a id="imageListLink" href="<spring:url value='/content/multimedia/image/list' />">View list (${imageCount})</a>
</div>
</div>
</div>
Expand All @@ -106,7 +106,7 @@
<span class="card-title"><i class="material-icons">book</i> Storybooks</span>
</div>
<div class="card-action">
<a href="<spring:url value='/content/storybook/list' />">View list (${storyBookCount})</a>
<a id="storyBookListLink" href="<spring:url value='/content/storybook/list' />">View list (${storyBookCount})</a>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@
</div>

<div class="fixed-action-btn" style="bottom: 2em; right: 2em;">
<a href="<spring:url value='/content/multimedia/image/create' />" class="btn-floating btn-large tooltipped" data-position="left" data-delay="50" data-tooltip="Add image"><i class="material-icons">add</i></a>
<a id="createButton" href="<spring:url value='/content/multimedia/image/create' />" class="btn-floating btn-large tooltipped" data-position="left" data-delay="50" data-tooltip="Add image"><i class="material-icons">add</i></a>
</div>
</content:section>
12 changes: 6 additions & 6 deletions src/main/webapp/WEB-INF/jsp/content/storybook/list.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<c:if test="${not empty storyBook.coverImage}">
<c:set var="coverImageUrl" value="${storyBook.coverImage.url}" />
</c:if>
<a href="<spring:url value='/content/storybook/edit/${storyBook.id}' />">
<a class="editLink" href="<spring:url value='/content/storybook/edit/${storyBook.id}' />">
<div class="card-image checksumGitHub-${storyBook.coverImage.checksumGitHub != null}" style="background-image: url(<spring:url value='${coverImageUrl}' />); background-color: #DDD;">
<span class="card-title"><c:out value="${storyBook.title}" /></span>
</div>
Expand Down Expand Up @@ -84,7 +84,7 @@
<c:if test="${not empty storyBook.coverImage}">
<c:set var="coverImageUrl" value="${storyBook.coverImage.url}" />
</c:if>
<a href="<spring:url value='/content/storybook/edit/${storyBook.id}' />">
<a class="editLink" href="<spring:url value='/content/storybook/edit/${storyBook.id}' />">
<div class="card-image checksumGitHub-${storyBook.coverImage.checksumGitHub != null}" style="background-image: url(<spring:url value='${coverImageUrl}' />); background-color: #DDD;">
<span class="card-title"><c:out value="${storyBook.title}" /></span>
</div>
Expand Down Expand Up @@ -132,7 +132,7 @@
<c:if test="${not empty storyBook.coverImage}">
<c:set var="coverImageUrl" value="${storyBook.coverImage.url}" />
</c:if>
<a href="<spring:url value='/content/storybook/edit/${storyBook.id}' />">
<a class="editLink" href="<spring:url value='/content/storybook/edit/${storyBook.id}' />">
<div class="card-image checksumGitHub-${storyBook.coverImage.checksumGitHub != null}" style="background-image: url(<spring:url value='${coverImageUrl}' />); background-color: #DDD;">
<span class="card-title"><c:out value="${storyBook.title}" /></span>
</div>
Expand Down Expand Up @@ -180,7 +180,7 @@
<c:if test="${not empty storyBook.coverImage}">
<c:set var="coverImageUrl" value="${storyBook.coverImage.url}" />
</c:if>
<a href="<spring:url value='/content/storybook/edit/${storyBook.id}' />">
<a class="editLink" href="<spring:url value='/content/storybook/edit/${storyBook.id}' />">
<div class="card-image checksumGitHub-${storyBook.coverImage.checksumGitHub != null}" style="background-image: url(<spring:url value='${coverImageUrl}' />); background-color: #DDD;">
<span class="card-title"><c:out value="${storyBook.title}" /></span>
</div>
Expand Down Expand Up @@ -226,7 +226,7 @@
<c:if test="${not empty storyBook.coverImage}">
<c:set var="coverImageUrl" value="${storyBook.coverImage.url}" />
</c:if>
<a href="<spring:url value='/content/storybook/edit/${storyBook.id}' />">
<a class="editLink" href="<spring:url value='/content/storybook/edit/${storyBook.id}' />">
<div class="card-image checksumGitHub-${storyBook.coverImage.checksumGitHub != null}" style="background-image: url(<spring:url value='${coverImageUrl}' />); background-color: #DDD;">
<span class="card-title"><c:out value="${storyBook.title}" /></span>
</div>
Expand Down Expand Up @@ -261,7 +261,7 @@
</c:if>

<div class="fixed-action-btn" style="bottom: 2em; right: 2em;">
<a href="<spring:url value='/content/storybook/create' />" class="btn-floating btn-large tooltipped" data-position="left" data-delay="50" data-tooltip="Add storybook"><i class="material-icons">add</i></a>
<a id="createButton" href="<spring:url value='/content/storybook/create' />" class="btn-floating btn-large tooltipped" data-position="left" data-delay="50" data-tooltip="Add storybook"><i class="material-icons">add</i></a>
<ul>
<li><a href="<spring:url value='/content/storybook/create-from-epub' />" class="btn-floating btn-large tooltipped" data-position="left" data-tooltip="Upload ePUB file"><i class="material-icons">cloud_upload</i></a></li>
</ul>
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/selenium/content/MainContentPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,14 @@ public void pressEmojiListLink() {
WebElement link = driver.findElement(By.id("emojiListLink"));
link.click();
}

public void pressImageListLink() {
WebElement link = driver.findElement(By.id("imageListLink"));
link.click();
}

public void pressStoryBookListLink() {
WebElement link = driver.findElement(By.id("storyBookListLink"));
link.click();
}
}
15 changes: 15 additions & 0 deletions src/test/java/selenium/content/image/ImageCreatePage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package selenium.content.image;

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

public class ImageCreatePage {

private WebDriver driver;

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

driver.findElement(By.id("imageCreatePage"));
}
}
15 changes: 15 additions & 0 deletions src/test/java/selenium/content/image/ImageEditPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package selenium.content.image;

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

public class ImageEditPage {

private WebDriver driver;

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

driver.findElement(By.id("imageEditPage"));
}
}
30 changes: 30 additions & 0 deletions src/test/java/selenium/content/image/ImageListPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package selenium.content.image;

import java.util.List;

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

public class ImageListPage {

private WebDriver driver;

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

driver.findElement(By.id("imageListPage"));
}

public void pressRandomImage() {
List<WebElement> links = driver.findElements(By.className("editLink"));
int randomIndex = (int) (Math.random() * links.size());
WebElement randomLink = links.get(randomIndex);
randomLink.click();
}
Comment on lines +19 to +24
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling for empty lists.

The pressRandomImage() method assumes that there's at least one edit link on the page. Add error handling for the case when no edit links are found to prevent test failures in unexpected ways.

+/**
+ * Clicks on a random image's edit link.
+ * 
+ * @throws IllegalStateException if no edit links are found on the page
+ */
 public void pressRandomImage() {
     List<WebElement> links = driver.findElements(By.className("editLink"));
+    if (links.isEmpty()) {
+        throw new IllegalStateException("No edit links found on the page. The page might be empty or the selector might be incorrect.");
+    }
     int randomIndex = (int) (Math.random() * links.size());
     WebElement randomLink = links.get(randomIndex);
     randomLink.click();
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public void pressRandomImage() {
List<WebElement> links = driver.findElements(By.className("editLink"));
int randomIndex = (int) (Math.random() * links.size());
WebElement randomLink = links.get(randomIndex);
randomLink.click();
}
/**
* Clicks on a random image's edit link.
*
* @throws IllegalStateException if no edit links are found on the page
*/
public void pressRandomImage() {
List<WebElement> links = driver.findElements(By.className("editLink"));
if (links.isEmpty()) {
throw new IllegalStateException("No edit links found on the page. The page might be empty or the selector might be incorrect.");
}
int randomIndex = (int) (Math.random() * links.size());
WebElement randomLink = links.get(randomIndex);
randomLink.click();
}


public void pressCreateButton() {
WebElement button = driver.findElement(By.id("createButton"));
button.click();
}
}
71 changes: 71 additions & 0 deletions src/test/java/selenium/content/image/ImageTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package selenium.content.image;

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 lombok.extern.slf4j.Slf4j;
import selenium.content.MainContentPage;
import selenium.util.DomainHelper;

@Slf4j
public class ImageTest {

private WebDriver driver;

@BeforeEach
public void setUp() {
log.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");
log.info("headlessSystemProperty: \"" + headlessSystemProperty + "\"");
if ("true".equals(headlessSystemProperty)) {
chromeOptions.addArguments("headless");
}

driver = new ChromeDriver(chromeOptions);

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

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

driver.quit();
}

@Test
public void testRandomImageEditPage() {
log.info("testRandomImageEditPage");

MainContentPage mainContentPage = new MainContentPage(driver);
mainContentPage.pressImageListLink();

ImageListPage imageListPage = new ImageListPage(driver);
imageListPage.pressRandomImage();
log.info("driver.getCurrentUrl(): " + driver.getCurrentUrl());

ImageEditPage imageEditPage = new ImageEditPage(driver);
}
Comment thread
jo-elimu marked this conversation as resolved.

@Test
public void testImageCreatePage() {
log.info("testImageCreatePage");

MainContentPage mainContentPage = new MainContentPage(driver);
mainContentPage.pressImageListLink();

ImageListPage imageListPage = new ImageListPage(driver);
imageListPage.pressCreateButton();

ImageCreatePage imageCreatePage = new ImageCreatePage(driver);
}
Comment thread
jo-elimu marked this conversation as resolved.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package selenium.content.storybook;

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

public class StoryBookCreatePage {

private WebDriver driver;

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

driver.findElement(By.id("storyBookCreatePage"));
}
}
15 changes: 15 additions & 0 deletions src/test/java/selenium/content/storybook/StoryBookEditPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package selenium.content.storybook;

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

public class StoryBookEditPage {

private WebDriver driver;

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

driver.findElement(By.id("storyBookEditPage"));
}
}
30 changes: 30 additions & 0 deletions src/test/java/selenium/content/storybook/StoryBookListPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package selenium.content.storybook;

import java.util.List;

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

public class StoryBookListPage {

private WebDriver driver;

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

driver.findElement(By.id("storyBookListPage"));
}

public void pressRandomStoryBook() {
List<WebElement> links = driver.findElements(By.className("editLink"));
int randomIndex = (int) (Math.random() * links.size());
WebElement randomLink = links.get(randomIndex);
randomLink.click();
}

public void pressCreateButton() {
WebElement button = driver.findElement(By.id("createButton"));
button.click();
}
}
Loading
Loading