diff --git a/src/test/java/org/fremo/fredl/test/BasicTest.java b/src/test/java/org/fremo/fredl/test/BasicTest.java index 92772b1..ace576c 100644 --- a/src/test/java/org/fremo/fredl/test/BasicTest.java +++ b/src/test/java/org/fremo/fredl/test/BasicTest.java @@ -16,16 +16,14 @@ 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); + FredlTestHelper.setUp(driver); } @AfterClass @@ -33,20 +31,6 @@ public class BasicTest { 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); @@ -60,7 +44,7 @@ public class BasicTest { driver.navigate().to(URL); System.out.println("Navigate to: " + URL); - if (elementExistsById("privacy-cookie-statement")) { + if (FredlTestHelper.elementExistsById("privacy-cookie-statement")) { System.out.println("Cookies consent page is shown"); WebElement consentButton = driver.findElement(By.id("opt-in-button-allow")); consentButton.click(); @@ -102,5 +86,18 @@ public class BasicTest { String expectedWelcomeMessage = "Willkommen bei FreDL"; System.out.println("Welcome message is: " + welcomeMessage); Assert.assertEquals(welcomeMessage, expectedWelcomeMessage); + + // we leave our tests always with having the driver located to the top frame + driver.switchTo().parentFrame(); + } + + @Test + public void verifyLogout() { + WebElement logoutButton = wait.until(ExpectedConditions.elementToBeClickable(By.name("doLogin"))); + + String frameObenName = "oben"; + wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(frameObenName)); + + } } diff --git a/src/test/java/org/fremo/fredl/test/FredlTestHelper.java b/src/test/java/org/fremo/fredl/test/FredlTestHelper.java index 94eb7fa..1e5b21f 100644 --- a/src/test/java/org/fremo/fredl/test/FredlTestHelper.java +++ b/src/test/java/org/fremo/fredl/test/FredlTestHelper.java @@ -1,11 +1,36 @@ package org.fremo.fredl.test; +import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; +import java.util.concurrent.TimeUnit; + public class FredlTestHelper { - public static void printPageSource(WebDriver driver) { + private static int implicitTimeoutMilliseconds = 3000; + private static WebDriver driver; + + public static void setUp(WebDriver _driver) { + driver = _driver; + driver.manage().timeouts().implicitlyWait(implicitTimeoutMilliseconds, TimeUnit.MILLISECONDS); + } + public static void printPageSource() { String body; // used for debugging purposes only body = driver.getPageSource(); System.out.println("HTML: " + body); } + + public static 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; + } + + public static 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; + } + } diff --git a/src/test/java/org/fremo/fredl/test/StartInstaller.java b/src/test/java/org/fremo/fredl/test/StartInstaller.java new file mode 100644 index 0000000..8854a6d --- /dev/null +++ b/src/test/java/org/fremo/fredl/test/StartInstaller.java @@ -0,0 +1,57 @@ +package org.fremo.fredl.test; + +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.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.concurrent.TimeUnit; + +public class StartInstaller { + 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(); + } + + @Test + public void startInstaller() { + driver.navigate().to(URL); + String getTitle = driver.getTitle(); + System.out.println("Page title: " + getTitle); + + if (FredlTestHelper.elementExistsByXpath("//table[@class='loginall']")) { + // Login page shown, thus we do not need to start the installer + return; + } + Assert.assertEquals(getTitle, "FreDL"); + WebElement installerLink = driver.findElement(By.xpath("//a[@href='install.php']")); + String expectedInstallerLinkText = "start the installer"; + Assert.assertEquals(installerLink.getText(), expectedInstallerLinkText); + installerLink.click(); + + FredlTestHelper.printPageSource(); + + //WebElement appLink = wait.until(ExpectedConditions.elementToBeClickable(By.name("doLogin"))); + } + +} diff --git a/testng.xml b/testng.xml index dba50ce..417d4cd 100644 --- a/testng.xml +++ b/testng.xml @@ -3,6 +3,7 @@ +