Skip to content

Commit

Permalink
add integration test for setup (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximthomas authored Feb 21, 2022
1 parent fc9d87c commit ce19422
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 2 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ jobs:
path: ~/.m2/repository
key: ${{ runner.os }}-m2-repository-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2-repository
- name: Set Integration Test Environment
if: matrix.os == 'ubuntu-latest'
run: >
echo '::set-output name=MAVEN_PROFILE_FLAG::-P integration-test'
&& echo '::set-output name=MAVEN_VERIFY_STAGE::verify'
&& echo "127.0.0.1 openam.local" | sudo tee -a /etc/hosts
id: maven-profile-flag
- name: Build with Maven
env:
MAVEN_OPTS: -Dhttps.protocols=TLSv1.2 -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 -Dmaven.wagon.http.retryHandler.requestSentEnabled=true -Dmaven.wagon.http.retryHandler.count=10
run: mvn --batch-mode --update-snapshots package --file pom.xml
run: mvn --batch-mode --update-snapshots package ${{ steps.maven-profile-flag.outputs.MAVEN_VERIFY_STAGE }} --file pom.xml ${{ steps.maven-profile-flag.outputs.MAVEN_PROFILE_FLAG }}
66 changes: 65 additions & 1 deletion openam-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
<build>
<finalName>OpenAM-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven3-plugin</artifactId>
Expand Down Expand Up @@ -103,7 +110,7 @@
<properties>
<cargo.rmi.port>8206</cargo.rmi.port>
<cargo.servlet.port>8207</cargo.servlet.port>
<!-- <cargo.jvmargs>-verbose:class</cargo.jvmargs> -->
<cargo.jvmargs>-Xms4g -Xmx4g</cargo.jvmargs>
</properties>
</configuration>
</configuration>
Expand Down Expand Up @@ -156,6 +163,25 @@
<artifactId>openam-console</artifactId>
<type>war</type>
</dependency>

<!--test dependencies-->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.0.3</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand All @@ -169,6 +195,44 @@
</dependency>
</dependencies>
</profile>
<profile>
<id>integration-test</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
<phase>integration-test</phase>
<id>integration-test</id>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<phase>pre-integration-test</phase>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>
</profile>
<profile>
<id>with-oem</id>
<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package org.openidentityplatform.openam.test.integration;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import java.time.Duration;
import java.util.List;

public class IT_Setup {

WebDriver driver;
WebDriverWait wait;

final static String OPENAM_URL = "http://openam.local:8207/openam";
final static String AM_PASSWORD = "AMp@ssw0rd";
final static String PA_PASSWORD = "PAp@ssw0rd";

@BeforeTest
public void webdriverSetup() {
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless", "--disable-dev-shm-usage", "--no-sandbox", "--verbose");
driver = new ChromeDriver(options);
wait = new WebDriverWait(driver, Duration.ofSeconds(10));
}

@Test
public void testSetup() throws Exception {
driver.get(OPENAM_URL);

//wait for setup page is loaded
waitForElement(By.id("pushConfigDialog_c"));
WebElement createDefaultLink = driver.findElement(By.id("DemoConfiguration"));
createDefaultLink.click();


//wait for licence check
waitForElementVisible(By.id("defaultSummary_c"));
WebElement acceptCheck = driver.findElement(By.id("accept-check"));
Actions actions = new Actions(driver);
actions.moveToElement(acceptCheck).perform();
acceptCheck.click();

driver.findElement(By.id("acceptLicenseButton")).click();

waitForElement(By.id("defaultAdminPassword")).sendKeys(AM_PASSWORD);
waitForElement(By.id("defaultAdminConfirm")).sendKeys(AM_PASSWORD);

waitForElement(By.id("defaultAgentPassword")).sendKeys(PA_PASSWORD);
waitForElement(By.id("defaultAgentConfirm")).sendKeys(PA_PASSWORD);

wait.until(ExpectedConditions.elementToBeClickable(By.id("createDefaultConfig"))).click();

//wait for setup complete
WebDriverWait waitComplete = new WebDriverWait(driver, Duration.ofSeconds(100));
WebElement proceedToConsole = waitComplete.until(visibilityOfAnyElement(By.cssSelector("#confComplete a")));
proceedToConsole.click();

//check login
waitForElement(By.id("idToken1")).sendKeys("amadmin");
waitForElement(By.id("idToken2")).sendKeys(AM_PASSWORD);
waitForElement(By.id("loginButton_0")).click();

//check console
waitForElementVisible(By.id("mainNavBar"));

}

@AfterTest
public void webDriverTearDown() {
if(driver != null) {
driver.quit();
}
}

WebElement waitForElement(By by) {
return wait.until(ExpectedConditions.presenceOfElementLocated(by));
}

WebElement waitForElementVisible(By by) {
return wait.until(ExpectedConditions.visibilityOfElementLocated(by));
}

public static ExpectedCondition<WebElement> visibilityOfAnyElement(final By locator) {
return new ExpectedCondition<WebElement>() {

@Override
public WebElement apply(WebDriver webDriver) {
List<WebElement> elements = webDriver.findElements(locator);
return elements.stream().filter(WebElement::isDisplayed).findFirst().orElse(null);
}

@Override
public String toString() {
return "visibility of any element " + locator;
}
};
}
}

0 comments on commit ce19422

Please sign in to comment.