mirror of
https://dev.azure.com/Foster-X/CMP329%20CW2/_git/CMP329%20CW2
synced 2025-07-27 04:33:31 +00:00
Refined user field for configuring driver, testlogin should now work
This commit is contained in:
parent
a60abd6fc3
commit
58aca1e828
3 changed files with 41 additions and 19 deletions
0
filename.txt
Normal file
0
filename.txt
Normal file
|
@ -1,6 +1,7 @@
|
|||
package main;
|
||||
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.chrome.ChromeDriver;
|
||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||
import org.openqa.selenium.firefox.FirefoxOptions;
|
||||
import java.io.IOException;
|
||||
|
@ -8,17 +9,18 @@ import java.nio.file.Files;
|
|||
import java.nio.file.Paths;
|
||||
|
||||
public class ConfigureDriver {
|
||||
public static WebDriver ConfigureDriver() {
|
||||
public static WebDriver configureDriver() {
|
||||
WebDriver driver;
|
||||
String filePath = ".user"; // Ensure the file exists in the working directory
|
||||
String filePath = ".git/user"; // Ensure the file exists in the working directory
|
||||
String user = "";
|
||||
System.out.println("YOU MUST HAVE YOUR NAME PUT IN A FILE! In this repo's route, make .git/user (no extension) contain only your name.");
|
||||
try {
|
||||
user = Files.readString(Paths.get(filePath)).trim();;
|
||||
System.out.println("User read: " + user);
|
||||
System.out.println("User read: " + user + " in file");
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error reading user file: " + e.getMessage());
|
||||
}
|
||||
if (user == "xander") {
|
||||
if (user.equals("xander")) {
|
||||
System.setProperty("webdriver.gecko.driver", "/usr/local/bin/geckodriver");
|
||||
FirefoxOptions options = new FirefoxOptions();
|
||||
options.setBinary("/usr/bin/firefox"); // Explicitly set Firefox binary
|
||||
|
@ -26,7 +28,10 @@ public class ConfigureDriver {
|
|||
}
|
||||
else {
|
||||
/// DREW ADD YOUR WEB DRIVER CODE PLEASE
|
||||
|
||||
System.setProperty("webdriver.chrome.driver","C:\\Users\\Matias\\Downloads\\chromedriver-win64\\chromedriver.exe");
|
||||
driver = new ChromeDriver();
|
||||
driver.get("https://www.google.co.uk/");
|
||||
driver.manage().window().maximize();
|
||||
}
|
||||
|
||||
return driver;
|
||||
|
|
|
@ -1,34 +1,51 @@
|
|||
package test;
|
||||
|
||||
import main.ConfigureDriver;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.By;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.io.File; // Import the File class
|
||||
import java.io.IOException; // Import the IOException class to handle errors
|
||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||
import org.openqa.selenium.firefox.FirefoxOptions;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
public class testlogin {
|
||||
String usernameText = "testuser";
|
||||
String passwordText = "QUBsucks&UUisBetter";
|
||||
String loginPage = "https://test.fusil.uk/wp-login.php";
|
||||
String usernameBoxID = "user_login";
|
||||
String passwordBoxID = "user_pass";
|
||||
String loginButtonID = "wp-submit";
|
||||
String expectedUrl = "https://test.fusil.uk/wp-admin/";
|
||||
@Test
|
||||
void testLogin() {
|
||||
//begin chromedriver code
|
||||
System.setProperty("webdriver.gecko.driver", "/usr/local/bin/geckodriver");
|
||||
FirefoxOptions options = new FirefoxOptions();
|
||||
options.setBinary("/usr/bin/firefox"); // Explicitly set Firefox binary
|
||||
WebDriver driver = new FirefoxDriver(options);
|
||||
|
||||
WebDriver driver = ConfigureDriver.configureDriver();
|
||||
|
||||
//end chromedriver code
|
||||
driver.manage().window().maximize();
|
||||
driver.get("https://practicetestautomation.com/practice-test-login/");
|
||||
WebElement username = driver.findElement(By.id("username"));
|
||||
WebElement password = driver.findElement(By.id("password"));
|
||||
WebElement login = driver.findElement(By.id("submit"));
|
||||
username.sendKeys("student");
|
||||
password.sendKeys("Password123");
|
||||
driver.get(loginPage);
|
||||
WebElement username = driver.findElement(By.id(usernameBoxID));
|
||||
WebElement password = driver.findElement(By.id(passwordBoxID));
|
||||
WebElement login = driver.findElement(By.id(loginButtonID));
|
||||
username.sendKeys(usernameText);
|
||||
password.sendKeys(passwordText);
|
||||
login.click();
|
||||
String expectedUrl = "https://practicetestautomation.com/logged-in-successfully/";
|
||||
assertEquals(expectedUrl, driver.getCurrentUrl());
|
||||
driver.quit();
|
||||
}
|
||||
}
|
||||
// public static void main(String[] args) {
|
||||
// try {
|
||||
// File myObj = new File("filename.txt");
|
||||
// if (myObj.createNewFile()) {
|
||||
// System.out.println("File created: " + myObj.getName());
|
||||
// } else {
|
||||
// System.out.println("File already exists.");
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// System.out.println("An error occurred.");
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue