This commit is contained in:
0nlineSam 2025-01-30 16:06:35 +01:00
parent 9929ae7808
commit aac01d998e
6 changed files with 150 additions and 37 deletions

View File

@ -0,0 +1,31 @@
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
public class DuckDuckGoPage extends Page {
private static final String URL = "https://html.duckduckgo.com/html";
private static final By SEARCH_BOX = By.id("search_form_input_homepage");
public DuckDuckGoPage(WebDriver driver) {
super(driver);
}
public void open() {
driver.get(URL);
}
public void performSearchAndClickResult(String searchTerm) {
driver.findElement(SEARCH_BOX).click();
driver.findElement(SEARCH_BOX).sendKeys(searchTerm);
driver.findElement(SEARCH_BOX).sendKeys(Keys.ENTER);
}
public UniMarburgDp12Page clickResultUniMarburgDp12(){
clickResult(UniMarburgDp12Page.DP_12_TITLE);
return new UniMarburgDp12Page(driver);
}
void clickResult(String desiredResultTitle){
driver.findElement(By.linkText(desiredResultTitle)).click();
}
}

View File

@ -0,0 +1,27 @@
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class ModuleHandbookPage extends UniMarburgPage {
public static final String SQ_MODULE_BASIC_INFO = "Lecture (4 SWS), recitation class (2 SWS),\n270 hours (90 h attendance, 180 h private study)";
public static final String SQ_MODULE_EXAM_INFO = "9 CP\nCourse requirement(s): Successful completion of at least 50 percent of the points from the weekly exercises as well as at least 2 presentations of the tasks.\nExamination type: Oral examination (individual examination) or written examination";
public static final By SQ_MODULE_BASIC_INFO_CSS_BLOCK = By.cssSelector("tr:nth-child(2) > td:nth-child(2)");
public static final By SQ_MODULE_EXAM_INFO_CSS_BLOCK = By.cssSelector("tr:nth-child(3) > td:nth-child(2)");
public static final By SQ_MODULE_NAME_CSS_BLOCK = By.cssSelector("h1 > b");
public static final By MS_COMPUTER_SCIENCE_PATH = By.xpath("(//a[text()=\'M.Sc. Computer Science\'])[2]");
public ModuleHandbookPage(WebDriver driver) {
super(driver);
}
public void verifyAndNavigateToSoftwareQualityModule() {
driver.findElement(MS_COMPUTER_SCIENCE_PATH).click();
driver.findElement(By.linkText("Alphabetical index of all modules in this course")).click();
driver.findElement(By.linkText("Software Quality")).click();
assertEquals("CS 661 — Software Quality", driver.findElement(SQ_MODULE_NAME_CSS_BLOCK).getText());
assertEquals(SQ_MODULE_BASIC_INFO, driver.findElement(SQ_MODULE_BASIC_INFO_CSS_BLOCK).getText());
assertEquals(SQ_MODULE_EXAM_INFO, driver.findElement(SQ_MODULE_EXAM_INFO_CSS_BLOCK).getText());
}
}

View File

@ -0,0 +1,9 @@
import org.openqa.selenium.WebDriver;
public abstract class Page {
protected final WebDriver driver;
public Page(WebDriver driver) {
this.driver = driver;
}
}

View File

@ -4,7 +4,6 @@ import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
@ -26,6 +25,7 @@ public class Ueb12Test {
vars = new HashMap<>();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
driver.manage().window().setSize(new Dimension(1337, 733));
}
@ -35,36 +35,24 @@ public class Ueb12Test {
}
@Test
public void untitled() {
public void testIfUsersCanSearchForAndFindSoftwareQualityModule() {
// Using Google Search is not possible as it asks us to solve captchas ...
//googleSearch();
// googleSearch();
// Let's use DuckDuckGo instead!
duckduckgoSearch();
DuckDuckGoPage duckDuckGoPage = new DuckDuckGoPage(driver);
duckDuckGoPage.open();
duckDuckGoPage.performSearchAndClickResult("uni marburg fb12");
UniMarburgDp12Page uniMarburgPage = duckDuckGoPage.clickResultUniMarburgDp12();
vars.put("lang", driver.findElement(By.cssSelector(".language > a")).getText());
if ((Boolean) js.executeScript("return (arguments[0] === \'ENGLISH\')", vars.get("lang"))) {
driver.findElement(By.cssSelector(".language > a")).click();
}
assertEquals(driver.findElement(By.xpath("//div[@id=\'section-navigation\']/div/ul/li[2]/a")).getText(), ("Department"));
assertEquals(driver.findElement(By.xpath("//div[@id=\'section-navigation\']/div/ul/li[3]/a")).getText(), ("Studying"));
assertEquals(driver.findElement(By.xpath("//div[@id=\'section-navigation\']/div/ul/li[4]/a")).getText(), ("Research"));
assertEquals(driver.findElement(By.xpath("//div[@id=\'section-navigation\']/div/ul/li[5]/a")).getText(), ("Research groups"));
driver.findElement(By.xpath("//div[@id=\'section-navigation\']/div/ul/li[3]/a")).click();
assertEquals(driver.findElement(By.cssSelector("li:nth-child(4) > a > div")).getText(), ("Modules & Courses\nModules and Courses"));
driver.findElement(By.cssSelector("li:nth-child(4) > a > div")).click();
assertEquals(driver.findElement(By.cssSelector(".link-text-list:nth-child(6) .diazoadded")).getText(), ("directly to the online module guide"));
driver.findElement(By.cssSelector(".link-text-list:nth-child(6) .diazoadded")).click();
vars.put("lang", driver.findElement(By.cssSelector(".language > a")).getText());
if ((Boolean) js.executeScript("return (arguments[0] === \'ENGLISH\')", vars.get("lang"))) {
driver.findElement(By.cssSelector(".language > a")).click();
}
driver.findElement(By.xpath("(//a[text()=\'M.Sc. Computer Science\'])[2]")).click();
driver.findElement(By.linkText("Alphabetical index of all modules in this course")).click();
driver.findElement(By.linkText("Software Quality")).click();
assertEquals(driver.findElement(By.cssSelector("h1 > b")).getText(), ("CS 661 — Software Quality"));
assertEquals(driver.findElement(By.cssSelector("tr:nth-child(2) > td:nth-child(2)")).getText(), ("Lecture (4 SWS), recitation class (2 SWS),\n270 hours (90 h attendance, 180 h private study)"));
assertEquals(driver.findElement(By.cssSelector("tr:nth-child(3) > td:nth-child(2)")).getText(), ("9 CP\nCourse requirement(s): Successful completion of at least 50 percent of the points from the weekly exercises as well as at least 2 presentations of the tasks.\nExamination type: Oral examination (individual examination) or written examination"));
uniMarburgPage.changeLanguageToEnglish();
uniMarburgPage.checkMenuItems();
uniMarburgPage.checkAndSelectModulesAndCourses();
ModuleHandbookPage moduleHandbookPage = uniMarburgPage.checkAndOpenModuleGuide();
moduleHandbookPage.changeLanguageToEnglish();
moduleHandbookPage.verifyAndNavigateToSoftwareQualityModule();
}
private void googleSearch() {
@ -75,14 +63,4 @@ public class Ueb12Test {
driver.findElement(By.xpath("(//input[@name=\'btnK\'])[2]")).click();
driver.findElement(By.xpath("//h3[contains(.,\'Mathematik und Informatik\')]")).click();
}
private void duckduckgoSearch() {
driver.get("https://html.duckduckgo.com/html");
driver.manage().window().setSize(new Dimension(1337, 733));
driver.findElement(By.id("search_form_input_homepage")).click();
driver.findElement(By.id("search_form_input_homepage")).sendKeys("uni marburg fb12");
driver.findElement(By.id("search_form_input_homepage")).sendKeys(Keys.ENTER);
driver.findElement(By.linkText("Philipps-Universität Marburg - Mathematik und Informatik")).click();
}
}

View File

@ -0,0 +1,45 @@
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class UniMarburgDp12Page extends UniMarburgPage {
public static final String DP_12_TITLE = "Philipps-Universität Marburg - Mathematik und Informatik";
private static final Map<String, By> topics = Map.of(
"Department",
By.xpath("//div[@id=\'section-navigation\']/div/ul/li[2]/a"),
"Studying",
By.xpath("//div[@id=\'section-navigation\']/div/ul/li[3]/a"),
"Research",
By.xpath("//div[@id=\'section-navigation\']/div/ul/li[4]/a"),
"Research groups",
By.xpath("//div[@id=\'section-navigation\']/div/ul/li[5]/a")
);
private static final By MODULES_AND_COURSES_SELECTOR = By.cssSelector("li:nth-child(4) > a > div");
private static final By MODULE_GUIDE_SELECTOR = By.cssSelector(".link-text-list:nth-child(6) .diazoadded");
public UniMarburgDp12Page(WebDriver driver) {
super(driver);
}
public void checkMenuItems() {
for (String item : topics.keySet()) {
assertEquals(item, driver.findElement(topics.get(item)).getText());
}
}
public void checkAndSelectModulesAndCourses() {
driver.findElement(topics.get("Studying")).click();
assertEquals("Modules & Courses\nModules and Courses", driver.findElement(MODULES_AND_COURSES_SELECTOR).getText());
driver.findElement(MODULES_AND_COURSES_SELECTOR).click();
}
public ModuleHandbookPage checkAndOpenModuleGuide() {
assertEquals(("directly to the online module guide"), driver.findElement(MODULE_GUIDE_SELECTOR).getText());
driver.findElement(MODULE_GUIDE_SELECTOR).click();
return new ModuleHandbookPage(driver);
}
}

View File

@ -0,0 +1,23 @@
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import java.util.HashMap;
public class UniMarburgPage extends Page {
private static final By LANGUAGE_SELECTOR = By.cssSelector(".language > a");
public UniMarburgPage(WebDriver driver) {
super(driver);
}
public void changeLanguageToEnglish() {
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, Object> vars = new HashMap<>();
vars.put("lang", driver.findElement(LANGUAGE_SELECTOR).getText());
if ((Boolean) js.executeScript("return (arguments[0] === \'ENGLISH\')", vars.get("lang"))) {
driver.findElement(LANGUAGE_SELECTOR).click();
}
}
}