Skip to content

Commit

Permalink
test(selenium): storybook learning events (#1861)
Browse files Browse the repository at this point in the history
  • Loading branch information
nya-elimu authored Aug 25, 2024
2 parents b8aaf76 + 1772d95 commit b88f4ad
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void handleRequest(
storyBookLearningEvent.getId(),
storyBookLearningEvent.getTimestamp().getTimeInMillis(),
storyBookLearningEvent.getAndroidId(),
storyBookLearningEvent.getApplication().getPackageName(),
storyBookLearningEvent.getPackageName(),
storyBookLearningEvent.getStoryBook().getId(),
storyBookLearningEvent.getStoryBookTitle(),
storyBookLearningEvent.getLearningEventType()
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/jsp/analytics/main.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<span class="card-title"><i class="material-icons">book</i> <fmt:message key="storybooks" /></span>
</div>
<div class="card-action">
<a href="<spring:url value='/analytics/storybook-learning-event/list' />"><fmt:message key="view.list" /> (${storyBookLearningEventCount})</a>
<a id="storyBookLearningEventsLink" href="<spring:url value='/analytics/storybook-learning-event/list' />"><fmt:message key="view.list" /> (${storyBookLearningEventCount})</a>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
<th><code>timestamp</code></th>
<th><code>android_id</code></th>
<th><code>package_name</code></th>
<th><code>storybook_id</code></th>
<th><code>storybook_title</code></th>
<th><code>learning_event_type</code></th>
</thead>
Expand All @@ -63,23 +62,20 @@
<fmt:formatDate value="${storyBookLearningEvent.timestamp.time}" pattern="yyyy-MM-dd" />
</td>
<td>
${storyBookLearningEvent.androidId}
<code>${storyBookLearningEvent.androidId}</code>
</td>
<td>
<c:choose>
<c:when test="${not empty storyBookLearningEvent.application}">
<a href="<spring:url value='/admin/application/edit/${storyBookLearningEvent.application.id}' />">
${storyBookLearningEvent.packageName}
<code>${storyBookLearningEvent.packageName}</code>
</a>
</c:when>
<c:otherwise>
${storyBookLearningEvent.packageName}
<code>${storyBookLearningEvent.packageName}</code>
</c:otherwise>
</c:choose>
</td>
<td>
${storyBookLearningEvent.storyBookId}
</td>
<td>
<c:choose>
<c:when test="${not empty storyBookLearningEvent.storyBook}">
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/selenium/analytics/MainAnalyticsPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public void pressWordLearningEventsLink() {
WebElement link = driver.findElement(By.id("wordLearningEventsLink"));
link.click();
}

public void pressStoryBookLearningEventsLink() {
WebElement link = driver.findElement(By.id("storyBookLearningEventsLink"));
link.click();
}
}
19 changes: 19 additions & 0 deletions src/test/java/selenium/analytics/StoryBookLearningEventsPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package selenium.analytics;

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

import selenium.util.ErrorHelper;

public class StoryBookLearningEventsPage {

private WebDriver driver;

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

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

ErrorHelper.verifyNoScriptOrMarkupError(driver);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package selenium.analytics;

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 StoryBookLearningEventsPageTest {

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-testing-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() + "/analytics");
}

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

driver.quit();
}

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

MainAnalyticsPage mainAnalyticsPage = new MainAnalyticsPage(driver);
mainAnalyticsPage.pressStoryBookLearningEventsLink();

StoryBookLearningEventsPage storyBookLearningEventsPage = new StoryBookLearningEventsPage(driver);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openjdk.tools.javac.main.Main;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
Expand Down

0 comments on commit b88f4ad

Please sign in to comment.