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

test: upgrade to selenium v4 #1855

Merged
merged 4 commits into from
Aug 25, 2024
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Maven Regression Test
name: Maven Regression Test (REST)

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

jobs:
regression_test_ENG:
test_ENG:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -19,8 +19,8 @@ jobs:
- run: mvn clean
- run: mvn verify -P regression-testing-rest -D base.url=http://eng.elimu.ai

regression_test_TGL:
needs: regression_test_ENG
test_TGL:
needs: test_ENG
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -32,8 +32,8 @@ jobs:
- run: mvn clean
- run: mvn verify -P regression-testing-rest -D base.url=http://tgl.elimu.ai

regression_test_HIN:
needs: regression_test_TGL
test_HIN:
needs: test_TGL
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/maven-regression-test-ui.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Maven Regression Test (UI)

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
test_ENG:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
cache: maven
- run: mvn clean
- run: mvn verify -P regression-testing-ui -D headless=true -D base.url=http://eng.elimu.ai

test_TGL:
needs: test_ENG
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
cache: maven
- run: mvn clean
- run: mvn verify -P regression-testing-ui -D headless=true -D base.url=http://tgl.elimu.ai

test_HIN:
needs: test_TGL
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
cache: maven
- run: mvn clean
- run: mvn verify -P regression-testing-ui -D headless=true -D base.url=http://hin.elimu.ai
19 changes: 1 addition & 18 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,7 @@ Next, to access the application in your browser, go to [http://localhost:8080/we

## Test 🚨

### Unit testing

Run all tests:

mvn clean test

Run individual tests:

mvn clean test -D test=WordDaoTest

### Code coverage

[![codecov](https://codecov.io/gh/elimu-ai/webapp/branch/main/graph/badge.svg?token=T1F9OTQVOH)](https://codecov.io/gh/elimu-ai/webapp)

[![](https://codecov.io/gh/elimu-ai/webapp/branch/main/graphs/tree.svg?token=T1F9OTQVOH)](https://codecov.io/gh/elimu-ai/webapp)

mvn test
open target/site/jacoco/index.html
See [`TEST.md`](./TEST.md)

## Test server

Expand Down
83 changes: 83 additions & 0 deletions TEST.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
## Test Instructions

### Unit testing ☑️

Run all tests:

mvn clean test

Run individual tests:

mvn clean test -D test=WordDaoTest

#### Code coverage 📊

[![codecov](https://codecov.io/gh/elimu-ai/webapp/branch/main/graph/badge.svg?token=T1F9OTQVOH)](https://codecov.io/gh/elimu-ai/webapp)

[![](https://codecov.io/gh/elimu-ai/webapp/branch/main/graphs/tree.svg?token=T1F9OTQVOH)](https://codecov.io/gh/elimu-ai/webapp)
jo-elimu marked this conversation as resolved.
Show resolved Hide resolved

mvn test
open target/site/jacoco/index.html

### Regression testing

#### REST API

First, launch the webapp on localhost:

mvn jetty:run

Then, in another terminal window run all the regression tests against the REST API:

mvn verify -P regression-testing-rest

> [!TIP]
> If you want to run the tests against another URL, set the `base.url` system property:
>
> mvn verify -P regression-testing-rest -D base.url=https://eng.elimu.ai

#### UI

First, launch the webapp on localhost:

mvn jetty:run

Then, in another terminal window run all the regression tests against the UI:

mvn verify -P regression-testing-ui

> [!TIP]
> If you want to run the tests against another URL, set the `base.url` system property:
>
> mvn verify -P regression-testing-ui -D base.url=https://eng.elimu.ai

##### Headless 😶‍🌫️

If you don't want the automated test software to open browser windows, you can disable that by setting the `headless` system property:

mvn verify -P regression-testing-ui -D headless=true

![](https://private-user-images.githubusercontent.com/1451036/361187317-35e99a19-f42d-4934-a0ba-f3d1e06ed6f6.png)

---

<p align="center">
<img src="https://github.com/elimu-ai/webapp/blob/main/src/main/webapp/static/img/logo-text-256x78.png" />
</p>
<p align="center">
elimu.ai - Free open-source learning software for out-of-school children 🚀✨
</p>
<p align="center">
<a href="https://elimu.ai">Website 🌐</a>
&nbsp;•&nbsp;
<a href="https://github.com/elimu-ai/wiki#readme">Wiki 📃</a>
&nbsp;•&nbsp;
<a href="https://github.com/orgs/elimu-ai/projects?query=is%3Aopen">Projects 👩🏽‍💻</a>
&nbsp;•&nbsp;
<a href="https://github.com/elimu-ai/wiki/milestones">Milestones 🎯</a>
&nbsp;•&nbsp;
<a href="https://github.com/elimu-ai/wiki#open-source-community">Community 👋🏽</a>
&nbsp;•&nbsp;
<a href="https://www.drips.network/app/drip-lists/41305178594442616889778610143373288091511468151140966646158126636698">Support 💜</a>
</p>

51 changes: 0 additions & 51 deletions Test.md

This file was deleted.

4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,8 @@
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.141.59</version>
<artifactId>selenium-java</artifactId>
<version>4.23.1</version>
</dependency>
</dependencies>
</project>
27 changes: 5 additions & 22 deletions src/test/java/selenium/DomainHelper.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package selenium;

import ai.elimu.model.v2.enums.Language;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -13,27 +9,14 @@ public class DomainHelper {
private static final Logger logger = LogManager.getLogger();

public static String getBaseUrl() {
// Read property set on the command line:
String baseUrl = "http://localhost:8080/webapp";

// Read "base.url" property set on the command line:
// mvn clean verify -P regression-testing-rest -D base.url=https://eng.test.elimu.ai
String baseUrlSystemProperty = System.getProperty("base.url");
logger.info("baseUrlSystemProperty: \"" + baseUrlSystemProperty + "\"");

String baseUrl = baseUrlSystemProperty;

if (StringUtils.isBlank(baseUrl)) {
// Read property set in the "config.properties" file
// This will trigger if no "base.url" property is set on the command line
InputStream inputStream = DomainHelper.class.getClassLoader().getResourceAsStream("config.properties");
Properties properties = new Properties();
try {
properties.load(inputStream);
String contentLanguageProperty = properties.getProperty("content.language");
logger.info("contentLanguageProperty: \"" + contentLanguageProperty + "\"");
Language language = Language.valueOf(contentLanguageProperty);
baseUrl = "https://" + language.toString().toLowerCase() + ".test.elimu.ai";
} catch (IOException ex) {
logger.error(ex);
}
if (StringUtils.isNotBlank(baseUrlSystemProperty)) {
baseUrl = baseUrlSystemProperty;
}

logger.info("baseUrl: \"" + baseUrl + "\"");
Expand Down
1 change: 0 additions & 1 deletion src/test/java/selenium/ErrorHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ public class ErrorHelper {
public static void verifyNoScriptOrMarkupError(WebDriver driver) {
JavaScriptHelper.verifyNoJavaScriptError(driver);
// MarkupValidationHelper.verifyNoMarkupError(driver.getPageSource());
// TODO: verify no missing translations in page source ("???...???")
}
}
2 changes: 1 addition & 1 deletion src/test/java/selenium/web/WelcomePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class WelcomePage {
public WelcomePage(WebDriver driver) {
this.driver = driver;

driver.findElement(By.id("welcomePageTEST"));
driver.findElement(By.id("welcomePage"));

ErrorHelper.verifyNoScriptOrMarkupError(driver);
}
Expand Down
25 changes: 22 additions & 3 deletions src/test/java/selenium/web/WelcomePageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

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.DomainHelper;

public class WelcomePageTest {
Expand All @@ -17,13 +20,29 @@ public class WelcomePageTest {
@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 -D base.url=https://eng.test.elimu.ai
String headlessSystemProperty = System.getProperty("headless");
logger.info("headlessSystemProperty: \"" + headlessSystemProperty + "\"");
if ("true".equals(headlessSystemProperty)) {
chromeOptions.addArguments("headless");
}

// See https://www.selenium.dev/documentation/en/webdriver/driver_requirements/#chromium-chrome
System.setProperty("webdriver.chrome.driver", "src/test/resources/selenium/chrome_80.0.3987.106/chromedriver_mac64/chromedriver");
driver = new ChromeDriver();
driver = new ChromeDriver(chromeOptions);

driver.get(DomainHelper.getBaseUrl());
}

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

driver.quit();
}

@Test
public void testWelcomePage() {
logger.info("testWelcomePage");
Expand Down
Binary file not shown.