Skip to content

Commit

Permalink
Add example Selenium test classes
Browse files Browse the repository at this point in the history
  • Loading branch information
scroix committed Apr 7, 2024
1 parent dcd3acb commit e7099e7
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.nodel;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class ActiveNavItemSeleniumTest {

@Test
public void testActiveNavigationItem() {
WebDriver driver = WebDriverSingleton.getDriver();
driver.get("http://127.0.0.1:8085");
String activeNavItemText = driver.findElement(By.cssSelector(".nav.navbar-nav .active")).getText();
assertEquals("Locals", activeNavItemText, "Active navigation item should be 'Locals'");
}
}
18 changes: 18 additions & 0 deletions nodel-jyhost/src/test/java/org/nodel/NavigationSeleniumTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.nodel;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import static org.junit.jupiter.api.Assertions.assertNotNull;

public class NavigationSeleniumTest {

@Test
public void testNavigationBarPresence() {
WebDriver driver = WebDriverSingleton.getDriver();
driver.get("http://127.0.0.1:8085");
assertNotNull(driver.findElement(By.cssSelector(".navbar")), "Navigation bar should be present");
}
}
29 changes: 29 additions & 0 deletions nodel-jyhost/src/test/java/org/nodel/WebDriverSingleton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.nodel;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.util.concurrent.TimeUnit;

public class WebDriverSingleton {
private static WebDriver driver = null;

private WebDriverSingleton() {}

public static WebDriver getDriver() {
if (driver == null) {
ChromeOptions options = new ChromeOptions();
options.addArguments("--remote-allow-origins=*");
driver = new ChromeDriver(options);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
}
return driver;
}

public static void quitDriver() {
if (driver != null) {
driver.quit();
driver = null;
}
}
}

0 comments on commit e7099e7

Please sign in to comment.