1+ /*
2+ * The contents of this file are subject to the terms of the Common Development and
3+ * Distribution License (the License). You may not use this file except in compliance with the
4+ * License.
5+ *
6+ * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7+ * specific language governing permission and limitations under the License.
8+ *
9+ * When distributing Covered Software, include this CDDL Header Notice in each file and include
10+ * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11+ * Header, with the fields enclosed by brackets [] replaced by your own identifying
12+ * information: "Portions copyright [year] [name of copyright owner]".
13+ *
14+ * Copyright 2022-2025 3A Systems LLC.
15+ */
16+
117package org .openidentityplatform .openam .test .integration ;
218
319import org .openqa .selenium .Alert ;
420import org .openqa .selenium .By ;
5- import org .openqa .selenium .StaleElementReferenceException ;
6- import org .openqa .selenium .WebDriver ;
21+ import org .openqa .selenium .TimeoutException ;
722import org .openqa .selenium .WebElement ;
8- import org .openqa .selenium .chrome .ChromeDriver ;
9- import org .openqa .selenium .chrome .ChromeOptions ;
1023import org .openqa .selenium .interactions .Actions ;
11- import org .openqa .selenium .support .ui .ExpectedCondition ;
1224import org .openqa .selenium .support .ui .ExpectedConditions ;
1325import org .openqa .selenium .support .ui .WebDriverWait ;
14- import org .testng .annotations .AfterTest ;
15- import org .testng .annotations .BeforeTest ;
1626import org .testng .annotations .Test ;
1727
1828import java .time .Duration ;
19- import java .util .List ;
2029
2130import static org .testng .Assert .assertTrue ;
2231
23- public class IT_Setup {
32+ public class IT_Setup extends BaseTest {
2433
25- WebDriver driver ;
26- WebDriverWait wait ;
34+ @ Test
35+ public void testSetup () {
2736
28- final static String OPENAM_URL = "http://openam.local:8207/openam" ;
29- final static String AM_PASSWORD = "AMp@ssw0rd" ;
30- final static String PA_PASSWORD = "PAp@ssw0rd" ;
3137
32- @ BeforeTest
33- public void webdriverSetup () {
34- ChromeOptions options = new ChromeOptions ();
35- options .addArguments ("--remote-allow-origins=*" ,"--headless" , "--disable-dev-shm-usage" , "--no-sandbox" , "--verbose" );
36- driver = new ChromeDriver (options );
37- wait = new WebDriverWait (driver , Duration .ofSeconds (10 ));
38- }
3938
40- @ Test
41- public void testSetup () {
42- driver .get (OPENAM_URL );
39+ final String openamUrl = "http://openam.local:8207/openam" ;
40+
41+ driver .get (openamUrl );
4342
4443 //wait for setup page is loaded
4544 waitForElement (By .id ("pushConfigDialog_c" ));
@@ -65,8 +64,19 @@ public void testSetup() {
6564
6665 //wait for setup complete
6766 WebDriverWait waitComplete = new WebDriverWait (driver , Duration .ofSeconds (300 ));
68- WebElement proceedToConsole = waitComplete .until (visibilityOfAnyElement (By .cssSelector ("#confComplete a" )));
69- proceedToConsole .click ();
67+ try {
68+ WebElement proceedToConsole = waitComplete .until (visibilityOfAnyElement (By .cssSelector ("#confComplete a" )));
69+ proceedToConsole .click ();
70+ } catch (TimeoutException e ) {
71+ System .err .println ("error occurred during install: " + e );
72+ WebElement progressIframe = waitForElement (By .id ("progressIframe" ));
73+ driver .switchTo ().frame (progressIframe );
74+ System .err .println ("output messages: " + waitForElement (By .id ("progressP" )).getText ());
75+ printInstallLogFile ();
76+ throw e ;
77+ } finally {
78+ driver .switchTo ().defaultContent ();
79+ }
7080
7181 waitForElement (By .id ("IDToken1" )).sendKeys ("amadmin" );
7282 waitForElement (By .id ("IDToken2" )).sendKeys (AM_PASSWORD );
@@ -79,7 +89,7 @@ public void testSetup() {
7989 assertTrue (isTextPresent ("You are logged out." ));
8090
8191 //check XUI
82- driver .get (OPENAM_URL .concat ("/XUI" ));
92+ driver .get (openamUrl .concat ("/XUI" ));
8393 waitForElement (By .id ("idToken1" )).sendKeys ("amadmin" );
8494 waitForElement (By .id ("idToken2" )).sendKeys (AM_PASSWORD );
8595 waitForElement (By .id ("loginButton_0" )).click ();
@@ -88,47 +98,5 @@ public void testSetup() {
8898 waitForElementVisible (By .id ("mainNavBar" ));
8999 }
90100
91- @ AfterTest
92- public void webDriverTearDown () {
93- if (driver != null ) {
94- driver .quit ();
95- }
96- }
97-
98- WebElement waitForElement (By by ) {
99- return wait .until (ExpectedConditions .presenceOfElementLocated (by ));
100- }
101-
102- WebElement waitForElementVisible (By by ) {
103- return wait .until (ExpectedConditions .visibilityOfElementLocated (by ));
104- }
105-
106- public static ExpectedCondition <WebElement > visibilityOfAnyElement (final By locator ) {
107- return new ExpectedCondition <WebElement >() {
108101
109- @ Override
110- public WebElement apply (WebDriver webDriver ) {
111- List <WebElement > elements = webDriver .findElements (locator );
112- return elements .stream ().filter (WebElement ::isDisplayed ).findFirst ().orElse (null );
113- }
114-
115- @ Override
116- public String toString () {
117- return "visibility of any element " + locator ;
118- }
119- };
120- }
121-
122- public boolean isTextPresent (String str ) {
123- Exception lastException = new Exception ();
124- for (int i = 0 ; i < 3 ; i ++) {
125- try {
126- WebElement bodyElement = new WebDriverWait (driver ,Duration .ofSeconds (20 )).until (ExpectedConditions .presenceOfElementLocated (By .tagName ("body" )));
127- return bodyElement .getText ().toLowerCase ().contains (str .toLowerCase ());
128- } catch (StaleElementReferenceException e ) {
129- lastException = e ;
130- }
131- }
132- throw new RuntimeException (lastException );
133- }
134102}
0 commit comments