Solved task 1

This commit is contained in:
0nlineSam 2025-01-30 14:40:39 +01:00
parent fa9c17c036
commit 9929ae7808
2 changed files with 370 additions and 30 deletions

View File

@ -1,13 +1,16 @@
// Generated by Selenium IDE
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.*;
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;
import java.time.Duration;
import java.util.*;
import java.util.HashMap;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -15,53 +18,71 @@ public class Ueb12Test {
private WebDriver driver;
private Map<String, Object> vars;
JavascriptExecutor js;
@BeforeEach
public void setUp() {
driver = new FirefoxDriver();
js = (JavascriptExecutor) driver;
vars = new HashMap<>();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
}
@AfterEach
public void tearDown() {
driver.quit();
}
@Test
public void ueb12() {
driver.get("https://duckduckgo.com/");
driver.manage().window().setSize(new Dimension(601, 683));
driver.findElement(By.id("searchbox_input")).sendKeys("uni marburg fb 12");
driver.findElement(By.cssSelector(".iconButton_size-20__O3lP5")).click();
driver.findElement(By.xpath("//span[contains(.,\'Philipps-Universität Marburg - Mathematik und Informatik\')]")).click();
public void untitled() {
// Using Google Search is not possible as it asks us to solve captchas ...
//googleSearch();
// Let's use DuckDuckGo instead!
duckduckgoSearch();
//driver.get("https://www.uni-marburg.de/de/fb12");
//driver.findElement(By.id("APjFqb")).sendKeys("fb12 uni marburg");
//driver.findElement(By.name("btnK")).click();
//driver.findElement(By.xpath("//h3[contains(.,\'Mathematik und Informatik\')]")).click();
vars.put("buttonText", driver.findElement(By.cssSelector(".language > a")).getText());
if ((Boolean) js.executeScript("return (arguments[0] == \'ENGLISH\')", vars.get("buttonText"))) {
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("Department", driver.findElement(By.linkText("Department")).getText());
assertEquals("Studying", driver.findElement(By.linkText("Studying")).getText());
assertEquals("Research", driver.findElement(By.linkText("Research")).getText());
assertEquals("Research groups", driver.findElement(By.linkText("Research groups")).getText());
driver.findElement(By.cssSelector("ul:nth-child(2) > .has-children:nth-child(3) > a")).click();
assertEquals("Modules & Courses\nModules and Courses", driver.findElement(By.cssSelector("li:nth-child(4) > a > div")).getText());
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("buttonText", driver.findElement(By.cssSelector(".language > a")).getText());
if ((Boolean) js.executeScript("return (arguments[0] == \'ENGLISH\')", vars.get("buttonText"))) {
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.cssSelector("ul > ul:nth-child(1) > li:nth-child(7) > 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();
driver.findElement(By.cssSelector(".cols1")).click();
assertEquals("CS 661 — Software Quality", driver.findElement(By.cssSelector("h1 > b")).getText());
assertEquals("Lecture (4 SWS), recitation class (2 SWS),\n270 hours (90 h attendance, 180 h private study)", driver.findElement(By.cssSelector("tr:nth-child(2) > td:nth-child(2)")).getText());
assertEquals("Lecture (4 SWS), recitation class (2 SWS),\n270 hours (90 h attendance, 180 h private study)", driver.findElement(By.cssSelector("tr:nth-child(2) > td:nth-child(2)")).getText());
assertEquals("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", driver.findElement(By.cssSelector("tr:nth-child(3) > td:nth-child(2)")).getText());
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"));
}
private void googleSearch() {
driver.get("https://www.google.de/");
driver.manage().window().setSize(new Dimension(1337, 733));
driver.findElement(By.name("q")).sendKeys("uni marburg fb12");
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();
}
}

319
Homework12/ueb12-test.side Normal file
View File

@ -0,0 +1,319 @@
{
"id": "eb04f4f9-5f11-4343-9336-dbe6b5a78af3",
"version": "2.0",
"name": "hw12",
"url": "https://www.google.de",
"tests": [{
"id": "8a49f466-f633-4340-9203-f86651654500",
"name": "Untitled",
"commands": [{
"id": "1626e190-3180-4c3a-8dcf-8abd372dc44b",
"comment": "",
"command": "open",
"target": "/",
"targets": [],
"value": ""
}, {
"id": "abfc43b8-4827-47ad-87ad-05cbc0181d62",
"comment": "",
"command": "setWindowSize",
"target": "1337x733",
"targets": [],
"value": ""
}, {
"id": "37565868-240d-49b8-913d-89177b740e51",
"comment": "",
"command": "type",
"target": "name=q",
"targets": [
["id=APjFqb", "id"],
["name=q", "name"],
["css=#APjFqb", "css:finder"],
["xpath=//textarea[@id='APjFqb']", "xpath:attributes"],
["xpath=//textarea", "xpath:position"]
],
"value": "uni marburg fb12"
}, {
"id": "afde340c-2c3d-4472-84f4-349f94fa20e1",
"comment": "",
"command": "click",
"target": "xpath=(//input[@name='btnK'])[2]",
"targets": [
["css=center:nth-child(1) > .gNO89b", "css:finder"],
["xpath=(//input[@name='btnK'])[2]", "xpath:attributes"],
["xpath=//div[3]/center/input", "xpath:position"]
],
"value": ""
}, {
"id": "796aa901-1076-48cb-b786-eae9ba6fdf40",
"comment": "",
"command": "click",
"target": "xpath=//h3[contains(.,'Mathematik und Informatik')]",
"targets": [
["css=.eKjLze .LC20lb", "css:finder"],
["xpath=//div[@id='rso']/div/div/div/div/div/div/div/div/div/div/div/span/a/h3", "xpath:idRelative"],
["xpath=//h3", "xpath:position"],
["xpath=//h3[contains(.,'Mathematik und Informatik')]", "xpath:innerText"]
],
"value": ""
}, {
"id": "f862ad37-a99d-44ec-8f50-9fb63899117a",
"comment": "",
"command": "storeText",
"target": "css=.language > a",
"targets": [
["css=.language > a", "css:finder"],
["xpath=//a[contains(text(),'English')]", "xpath:link"],
["xpath=//div[@id='service-navigation']/div[2]/ul/li[4]/a", "xpath:idRelative"],
["xpath=//a[contains(@href, 'https://www.uni-marburg.de/@@multilingual-selector/8d3dd0f85933453c9362b13354bb07b5/en?set_language=en')]", "xpath:href"],
["xpath=//div[2]/ul/li[4]/a", "xpath:position"]
],
"value": "lang"
}, {
"id": "29e943cb-4eb8-46df-9d8e-7fe2785ae4be",
"comment": "",
"command": "if",
"target": "${lang} === \"ENGLISH\"",
"targets": [],
"value": ""
}, {
"id": "3b426443-1e48-4890-912c-7638d2f3691d",
"comment": "",
"command": "click",
"target": "css=.language > a",
"targets": [
["css=.language > a", "css:finder"],
["xpath=//a[contains(text(),'English')]", "xpath:link"],
["xpath=//div[@id='service-navigation']/div[2]/ul/li[4]/a", "xpath:idRelative"],
["xpath=//a[contains(@href, 'https://www.uni-marburg.de/@@multilingual-selector/8d3dd0f85933453c9362b13354bb07b5/en?set_language=en')]", "xpath:href"],
["xpath=//div[2]/ul/li[4]/a", "xpath:position"]
],
"value": ""
}, {
"id": "0e03c4df-6910-4c93-9e3c-544a0d1b2b64",
"comment": "",
"command": "end",
"target": "",
"targets": [],
"value": ""
}, {
"id": "6c18fbce-b72f-4cb3-b4b3-6e22a9fba5e2",
"comment": "",
"command": "assertText",
"target": "xpath=//div[@id='section-navigation']/div/ul/li[2]/a",
"targets": [
["linkText=Department", "linkText"],
["css=.focused > a", "css:finder"],
["xpath=(//a[contains(text(),'Department')])[4]", "xpath:link"],
["xpath=//div[@id='section-navigation']/div/ul/li[2]/a", "xpath:idRelative"],
["xpath=//a[contains(@href, 'https://www.uni-marburg.de/en/fb12/department')]", "xpath:href"],
["xpath=//nav[4]/div/div/ul/li[2]/a", "xpath:position"]
],
"value": "Department"
}, {
"id": "3ca4a555-e71d-4d73-9b76-207d9d0cd6ad",
"comment": "",
"command": "assertText",
"target": "xpath=//div[@id='section-navigation']/div/ul/li[3]/a",
"targets": [],
"value": "Studying"
}, {
"id": "d33c6c12-8b20-4dc4-9361-f765c01b9ff5",
"comment": "",
"command": "assertText",
"target": "xpath=//div[@id='section-navigation']/div/ul/li[4]/a",
"targets": [
["css=.parent > a", "css:finder"],
["xpath=(//a[contains(text(),'Research')])[13]", "xpath:link"],
["xpath=//div[@id='section-navigation']/div/ul/li[4]/a", "xpath:idRelative"],
["xpath=//a[contains(@href, 'https://www.uni-marburg.de/en/fb12/research')]", "xpath:href"],
["xpath=//nav[4]/div/div/ul/li[4]/a", "xpath:position"]
],
"value": "Research"
}, {
"id": "5db74f46-b520-452a-b2e2-d2e66168bc51",
"comment": "",
"command": "assertText",
"target": "xpath=//div[@id='section-navigation']/div/ul/li[5]/a",
"targets": [
["linkText=Research groups", "linkText"],
["css=div > ul:nth-child(2) > li:nth-child(5) > a", "css:finder"],
["xpath=//a[contains(text(),'Research groups')]", "xpath:link"],
["xpath=//div[@id='section-navigation']/div/ul/li[5]/a", "xpath:idRelative"],
["xpath=//a[contains(@href, 'https://www.uni-marburg.de/en/fb12/research-groups')]", "xpath:href"],
["xpath=//nav[4]/div/div/ul/li[5]/a", "xpath:position"],
["xpath=//a[contains(.,'Research groups')]", "xpath:innerText"]
],
"value": "Research groups"
}, {
"id": "6ebfbd32-b7b5-4165-a22c-cacdf12a26d0",
"comment": "",
"command": "click",
"target": "xpath=//div[@id='section-navigation']/div/ul/li[3]/a",
"targets": [],
"value": ""
}, {
"id": "37fc82c3-52a0-4b72-b130-6df4521eec16",
"comment": "",
"command": "assertText",
"target": "css=li:nth-child(4) > a > div",
"targets": [
["css=li:nth-child(4) > a > div", "css:finder"],
["xpath=//section[@id='link-text-list-info']/div/ul/li[4]/a/div", "xpath:idRelative"],
["xpath=//li[4]/a/div", "xpath:position"]
],
"value": "Modules & Courses\\nModules and Courses"
}, {
"id": "6911e243-d2c5-435a-b525-485205d5e6da",
"comment": "",
"command": "click",
"target": "css=li:nth-child(4) > a > div",
"targets": [],
"value": ""
}, {
"id": "5a12117c-d549-487d-b840-8bd39b119431",
"comment": "",
"command": "verifyText",
"target": "css=.link-text-list:nth-child(6) .diazoadded",
"targets": [
["css=.link-text-list:nth-child(6) .diazoadded", "css:finder"],
["xpath=//div[@id='content']/section/div/ul[2]/li/a/div", "xpath:idRelative"],
["xpath=//div/ul[2]/li/a/div", "xpath:position"]
],
"value": "directly to the online module guide"
}, {
"id": "33f64c2d-6305-4e2b-a967-32e0327b126e",
"comment": "",
"command": "click",
"target": "css=.link-text-list:nth-child(6) .diazoadded",
"targets": [
["css=.link-text-list:nth-child(6) .diazoadded", "css:finder"],
["xpath=//div[@id='content']/section/div/ul[2]/li/a/div", "xpath:idRelative"],
["xpath=//div/ul[2]/li/a/div", "xpath:position"]
],
"value": ""
}, {
"id": "12d74fd3-1d17-4edd-92b7-41fc8beec0f8",
"comment": "",
"command": "storeText",
"target": "css=.language > a",
"targets": [
["css=.language > a", "css:finder"],
["xpath=(//a[contains(text(),'English')])[2]", "xpath:link"],
["xpath=//div[@id='service-navigation']/div/ul/li/a", "xpath:idRelative"],
["xpath=(//a[@href='http://www.mathematik.uni-marburg.de/modulhandbuch/20232/index_en.html'])[2]", "xpath:href"],
["xpath=//div/div/ul/li/a", "xpath:position"]
],
"value": "lang"
}, {
"id": "7fe0d220-c16b-40a2-b19f-e75455153e4b",
"comment": "",
"command": "if",
"target": "${lang} === \"ENGLISH\"",
"targets": [],
"value": ""
}, {
"id": "b218e2bb-1558-4cbd-864a-40dcb369fd61",
"comment": "",
"command": "click",
"target": "css=.language > a",
"targets": [
["css=.language > a", "css:finder"],
["xpath=(//a[contains(text(),'English')])[2]", "xpath:link"],
["xpath=//div[@id='service-navigation']/div/ul/li/a", "xpath:idRelative"],
["xpath=(//a[@href='http://www.mathematik.uni-marburg.de/modulhandbuch/20232/index_en.html'])[2]", "xpath:href"],
["xpath=//div/div/ul/li/a", "xpath:position"]
],
"value": ""
}, {
"id": "055f98d5-922f-4700-89f1-0c8784c9bf5d",
"comment": "",
"command": "end",
"target": "",
"targets": [],
"value": ""
}, {
"id": "28b8b697-3849-49ae-9811-70361b67f489",
"comment": "",
"command": "click",
"target": "xpath=(//a[text()='M.Sc. Computer Science'])[2]",
"targets": [
["css=ul > ul:nth-child(1) > li:nth-child(7) > a", "css:finder"],
["xpath=(//a[contains(text(),'M.Sc. Computer Science')])[2]", "xpath:link"],
["xpath=//div[@id='content']/section/div/ul/ul/li[7]/a", "xpath:idRelative"],
["xpath=(//a[@href='http://www.mathematik.uni-marburg.de/modulhandbuch/20232/MSc_Computer_Science/index.html'])[2]", "xpath:href"],
["xpath=//ul/ul/li[7]/a", "xpath:position"]
],
"value": ""
}, {
"id": "e0097e8b-8c39-412c-a5e5-990b867c26db",
"comment": "",
"command": "click",
"target": "linkText=Alphabetical index of all modules in this course",
"targets": [
["linkText=Alphabetical index of all modules in this course", "linkText"],
["css=p:nth-child(6) > a:nth-child(1)", "css:finder"],
["xpath=//a[contains(text(),'Alphabetical index of all modules in this course')]", "xpath:link"],
["xpath=//div[@id='content']/section/div/p[2]/a", "xpath:idRelative"],
["xpath=//a[@href='http://www.mathematik.uni-marburg.de/modulhandbuch/20232/MSc_Computer_Science/alphabetical.html']", "xpath:href"],
["xpath=//p[2]/a", "xpath:position"],
["xpath=//a[contains(.,'Alphabetical index of all modules in this course')]", "xpath:innerText"]
],
"value": ""
}, {
"id": "1dbbf4aa-cfef-4087-8c0a-1129855b6bcf",
"comment": "",
"command": "click",
"target": "linkText=Software Quality",
"targets": [
["linkText=Software Quality", "linkText"],
["css=li:nth-child(234) > a", "css:finder"],
["xpath=//a[contains(text(),'Software Quality')]", "xpath:link"],
["xpath=//div[@id='content']/section/div/ul/li[234]/a", "xpath:idRelative"],
["xpath=//a[@href='http://www.mathematik.uni-marburg.de/modulhandbuch/20232/MSc_Computer_Science/Compulsory_Elective_Modules_in_Computer_Science/Software_Quality.html']", "xpath:href"],
["xpath=//li[234]/a", "xpath:position"],
["xpath=//a[contains(.,'Software Quality')]", "xpath:innerText"]
],
"value": ""
}, {
"id": "6b7420ff-721a-43f2-8077-6046d8459eae",
"comment": "",
"command": "verifyText",
"target": "css=h1 > b",
"targets": [
["css=h1 > b", "css:finder"],
["xpath=//div[@id='content']/section/div/h1/b", "xpath:idRelative"],
["xpath=//h1/b", "xpath:position"]
],
"value": "CS 661 — Software Quality"
}, {
"id": "1322ec2c-b71d-4e8d-ae6f-2dd6190455cf",
"comment": "",
"command": "verifyText",
"target": "css=tr:nth-child(2) > td:nth-child(2)",
"targets": [],
"value": "Lecture (4 SWS), recitation class (2 SWS),\\n270 hours (90 h attendance, 180 h private study)"
}, {
"id": "3c74fc20-6526-4a7f-9cd5-72caa0e20c02",
"comment": "",
"command": "verifyText",
"target": "css=tr:nth-child(3) > td:nth-child(2)",
"targets": [
["css=tr:nth-child(3) > td:nth-child(2)", "css:finder"],
["xpath=//div[@id='content']/section/div/table/tbody/tr[3]/td[2]", "xpath:idRelative"],
["xpath=//tr[3]/td[2]", "xpath:position"]
],
"value": "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"
}]
}],
"suites": [{
"id": "8deb4f55-ae91-4e30-98b5-f255c71951d3",
"name": "Default Suite",
"persistSession": false,
"parallel": false,
"timeout": 300,
"tests": ["8a49f466-f633-4340-9203-f86651654500"]
}],
"urls": ["https://www.google.de/"],
"plugins": []
}