Added StartInstaller -- installation complete not detected yet.

This commit is contained in:
Dirk Jahnke 2019-07-26 20:58:00 +02:00
parent 7ee66246c4
commit 31b64737c2
4 changed files with 99 additions and 19 deletions

View File

@ -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));
}
}

View File

@ -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;
}
}

View File

@ -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")));
}
}

View File

@ -3,6 +3,7 @@
<suite name="Suite" parallel="none">
<test name="Test">
<classes>
<class name="org.fremo.fredl.test.StartInstaller"/>
<class name="org.fremo.fredl.test.BasicTest"/>
</classes>
</test> <!-- Test -->