diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..21f7874 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +.tmp +.bak diff --git a/src/test/java/org/fremo/fredl/test/BasicTest.java b/src/test/java/org/fremo/fredl/test/BasicTest.java new file mode 100644 index 0000000..582159a --- /dev/null +++ b/src/test/java/org/fremo/fredl/test/BasicTest.java @@ -0,0 +1,107 @@ +package org.fremo.fredl.test; + +import java.util.concurrent.TimeUnit; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.htmlunit.HtmlUnitDriver; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class BasicTest { + private WebDriver driver; + private WebDriverWait wait; + private int implicitTimeoutMilliseconds = 3000; + private int timeoutInSeconds = 20; + String URL = "https://0.fredldev.fremo-net.eu"; + + @BeforeClass + public void testSetUp() { + + driver = new HtmlUnitDriver(true); + wait = new WebDriverWait(driver, timeoutInSeconds); + driver.manage().timeouts().implicitlyWait(implicitTimeoutMilliseconds, TimeUnit.MILLISECONDS); + } + + @AfterClass + public void tearDown() { + driver.quit(); + } + + private boolean elementExistsByXpath(String xpath) { + driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS); + boolean exists = driver.findElements(By.xpath(xpath)).size() != 0; + driver.manage().timeouts().implicitlyWait(implicitTimeoutMilliseconds, TimeUnit.MILLISECONDS); + return exists; + } + + private boolean elementExistsById(String id) { + driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS); + boolean exists = driver.findElements(By.id(id)).size() != 0; + driver.manage().timeouts().implicitlyWait(implicitTimeoutMilliseconds, TimeUnit.MILLISECONDS); + return exists; + } + + @Test + public void verifyFredlPageTitle() { + driver.navigate().to(URL); + String getTitle = driver.getTitle(); + System.out.println("Page title: " + getTitle); + Assert.assertEquals(getTitle, "FREDL"); + } + + @Test + public void verifyLoginAsSystemUser() { + driver.navigate().to(URL); + System.out.println("Navigate to: " + URL); + + if (elementExistsById("privacy-cookie-statement")) { + System.out.println("Cookies consent page is shown"); + WebElement consentButton = driver.findElement(By.id("opt-in-button-allow")); + consentButton.click(); + } + + WebElement loginButton = wait.until(ExpectedConditions.elementToBeClickable(By.name("doLogin"))); + + String scaleInfo = driver.findElement(By.xpath("//table[@class='loginall']/tbody/tr/td/div")).getText(); + System.out.println("Scale: " + scaleInfo); + + driver.findElement(By.xpath("//input[@name='login']")).sendKeys("system"); + driver.findElement(By.xpath("//input[@name='password']")).sendKeys("system"); + loginButton.click(); + + String expectedTitle = "FreDL"; + wait.until(ExpectedConditions.titleIs(expectedTitle)); + + FredlTestHelper.printPageSource(driver); + + //driver.switchTo().frame("oben"); + String frameObenName = "oben"; + wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(frameObenName)); + + FredlTestHelper.printPageSource(driver); + + String versionInfo = driver.findElement(By.xpath("//table[1]/tbody/tr/td[1]/b")).getText(); + String userInfo = driver.findElement(By.xpath("//table[1]/tbody/tr/td[3]")).getText(); + String expectedUserInfo = "Benutzer: FREDL System (Syste)"; + System.out.println("Version info found: " + versionInfo); + System.out.println("User info found: " + userInfo); + Assert.assertEquals(userInfo, expectedUserInfo); + + driver.switchTo().parentFrame(); + String frameRechtsName = "rechts"; + driver.switchTo().frame(frameRechtsName); + + FredlTestHelper.printPageSource(driver); + + String welcomeMessage = driver.findElement(By.xpath("//body/h1")).getText(); + String expectedWelcomeMessage = "Willkommen bei FreDL"; + System.out.println("Welcome message is: " + welcomeMessage); + Assert.assertEquals(welcomeMessage, expectedWelcomeMessage); + } +} diff --git a/src/test/java/org/fremo/fredl/test/FredlTestHelper.java b/src/test/java/org/fremo/fredl/test/FredlTestHelper.java new file mode 100644 index 0000000..94eb7fa --- /dev/null +++ b/src/test/java/org/fremo/fredl/test/FredlTestHelper.java @@ -0,0 +1,11 @@ +package org.fremo.fredl.test; +import org.openqa.selenium.WebDriver; + +public class FredlTestHelper { + public static void printPageSource(WebDriver driver) { + String body; // used for debugging purposes only + + body = driver.getPageSource(); + System.out.println("HTML: " + body); + } +}