
| Current Path : /var/www/web-klick.de/dsh/90_akt/selenium/selenium_java/src/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/web-klick.de/dsh/90_akt/selenium/selenium_java/src/AutoTestLogin.java |
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class AutoTestLogin
{
public static void main(String[] args) throws InterruptedException
{
//System.setProperty("webdriver.chrome.driver", "C:/workspace/Selenium/chromedriver.exe");
String url = "http://localhost";
String username = "cgabriel";
String password = "geheim";
String falsch = "falsch";
long wait_time = 1000L;
WebDriver driver = new FirefoxDriver();
driver.get(url);
Thread.sleep(wait_time);
//********************************* User does not exist *********************************
// username = falsch
// password = falsch
System.out.println("Test1:");
driver.findElement(By.xpath("html/body/div[3]/div/div[2]/div[1]/div[2]/div/" +
"div[2]/div/div[3]/input")).sendKeys(falsch);
System.out.println("username: " + falsch);
Thread.sleep(wait_time);
driver.findElement(By.xpath("html/body/div[3]/div/div[2]/div[1]/div[2]/div/" +
"div[2]/div/div[5]/input")).sendKeys(falsch);
System.out.println("password: " + falsch);
Thread.sleep(wait_time);
driver.findElement(By.xpath("html/body/div[3]/div/div[2]/div[1]/div[2]/div/" +
"div[2]/div/div[6]/div/div")).click();
System.out.println("User does not exist !\n");
Thread.sleep(2*wait_time);
//Thread.sleep(wait_time);
//********************************* Wrong Password *********************************
// username = cgabriel
// password = falsch
System.out.println("Test2:");
driver.findElement(By.xpath("html/body/div[3]/div/div[2]/div[1]/div[2]/div/" +
"div[2]/div/div[3]/input")).clear();
driver.findElement(By.xpath("html/body/div[3]/div/div[2]/div[1]/div[2]/div/" +
"div[2]/div/div[3]/input")).sendKeys(username);
System.out.println("username: " + username);
Thread.sleep(wait_time);
driver.findElement(By.xpath("html/body/div[3]/div/div[2]/div[1]/div[2]/div/" +
"div[2]/div/div[5]/input")).clear();
driver.findElement(By.xpath("html/body/div[3]/div/div[2]/div[1]/div[2]/div/" +
"div[2]/div/div[5]/input")).sendKeys(falsch);
System.out.println("password: " + falsch);
Thread.sleep(wait_time);
driver.findElement(By.xpath("html/body/div[3]/div/div[2]/div[1]/div[2]/div/" +
"div[2]/div/div[6]/div/div")).click();
System.out.println("Wrong Password !\n");
Thread.sleep(2*wait_time);
//********************************* Login Successful *********************************
// username = cgabriel
// password = geheim
//driver.findElement(By.xpath("html/body/div[3]/div/div[2]/div[1]/div[2]/div/" +
// "div[2]/div/div[3]/input")).clear();
//driver.findElement(By.xpath("html/body/div[3]/div/div[2]/div[1]/div[2]/div/" +
// "div[2]/div/div[3]/input")).sendKeys(username);
//Thread.sleep(wait_time);
System.out.println("Test3:");
System.out.println("username: " + username);
driver.findElement(By.xpath("html/body/div[3]/div/div[2]/div[1]/div[2]/div/" +
"div[2]/div/div[5]/input")).clear();
driver.findElement(By.xpath("html/body/div[3]/div/div[2]/div[1]/div[2]/div/" +
"div[2]/div/div[5]/input")).sendKeys(password);
System.out.println("password: " + password);
Thread.sleep(wait_time);
driver.findElement(By.xpath("html/body/div[3]/div/div[2]/div[1]/div[2]/div/" +
"div[2]/div/div[6]/div/div")).click();
System.out.println("Login Successful !\n");
Thread.sleep(2*wait_time);
//************************************* Logout ****************************************
System.out.println("Logout...\n");
driver.findElement(By.xpath("html/body/div[3]/div/div[1]/div/div[1]/div/div/div/" +
"div[2]/div/div[2]/div[1]/div[2]/div/div[6]")).click();
Thread.sleep(2*wait_time);
System.out.println("Tests completed successfully without error !");
driver.close();
}
}