diff --git a/ToolsQA_Project/.classpath b/Formy_Project/.classpath similarity index 100% rename from ToolsQA_Project/.classpath rename to Formy_Project/.classpath diff --git a/ToolsQA_Project/.project b/Formy_Project/.project similarity index 91% rename from ToolsQA_Project/.project rename to Formy_Project/.project index 7cf210a..925f8b1 100644 --- a/ToolsQA_Project/.project +++ b/Formy_Project/.project @@ -1,6 +1,6 @@ - ToolsQA_Project + Formy_Project diff --git a/ToolsQA_Project/.settings/org.eclipse.core.resources.prefs b/Formy_Project/.settings/org.eclipse.core.resources.prefs similarity index 100% rename from ToolsQA_Project/.settings/org.eclipse.core.resources.prefs rename to Formy_Project/.settings/org.eclipse.core.resources.prefs diff --git a/ToolsQA_Project/.settings/org.eclipse.jdt.core.prefs b/Formy_Project/.settings/org.eclipse.jdt.core.prefs similarity index 100% rename from ToolsQA_Project/.settings/org.eclipse.jdt.core.prefs rename to Formy_Project/.settings/org.eclipse.jdt.core.prefs diff --git a/Formy_Project/bin/formy_project/Web_Form.class b/Formy_Project/bin/formy_project/Web_Form.class new file mode 100644 index 0000000..264d74a Binary files /dev/null and b/Formy_Project/bin/formy_project/Web_Form.class differ diff --git a/Formy_Project/src/formy_project/Web_Form.java b/Formy_Project/src/formy_project/Web_Form.java new file mode 100644 index 0000000..ecb4ee7 --- /dev/null +++ b/Formy_Project/src/formy_project/Web_Form.java @@ -0,0 +1,79 @@ +package formy_project; + +import java.time.Duration; +import org.openqa.selenium.By; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.Select; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class Web_Form { + + public static void main(String[] args) { + WebDriver driver = new ChromeDriver(); + driver.manage().window().maximize(); + + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + driver.get("https://formy-project.herokuapp.com/form"); + waitForTheUser(); + + WebElement firstName = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='first-name']"))); + firstName.click(); + firstName.sendKeys("Chris"); + waitForTheUser(); + + WebElement lastName = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='last-name']"))); + lastName.click(); + lastName.sendKeys("Redfield"); + waitForTheUser(); + + WebElement jobTitle = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='job-title']"))); + jobTitle.click(); + jobTitle.sendKeys("QA Engineer"); + waitForTheUser(); + + WebElement highLevelEducation = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='radio-button-3']"))); + highLevelEducation.click(); + waitForTheUser(); + + JavascriptExecutor scrollDown = (JavascriptExecutor) driver; + scrollDown.executeScript("window.scrollBy(0,400)"); + waitForTheUser(); + + WebElement genderField = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='checkbox-2']"))); + genderField.click(); + waitForTheUser(); + + WebElement yearOfExperience = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//select[@id='select-menu']"))); + Select object = new Select (yearOfExperience); + object.selectByVisibleText("2-4"); + waitForTheUser(); + + WebElement datePicker = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='datepicker']"))); + datePicker.click(); + datePicker.sendKeys("07/12/2022"); + waitForTheUser(); + + WebElement submitButton = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@role='button']"))); + submitButton.click(); + waitForTheUser(); + + WebElement successMessage = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h1[@align='center']"))); + System.out.println("Login Message: " + successMessage.getText()); + System.out.println("The form was successfully submitted!"); + waitForTheUser(); + + driver.quit(); + } + + public static void waitForTheUser() { + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } +} diff --git a/README.md b/README.md index b50cf48..165e003 100644 --- a/README.md +++ b/README.md @@ -1,40 +1,23 @@ -# ToolsQA Automation Using Selenium - -### Description -This project demonstrates an automation script for user registration, login and logout on the ToolsQA demo application. The script interacts with the web elements on the registration and login pages to simulate a user performing the following tasks: -1. Registering a new account. -2. Logging in with the registered account. -3. Logging out of the account. - -The script uses Selenium WebDriver with Java and incorporates manual handling for CAPTCHA verification. - - -### Features -- Automates the registration process by filling in user details. -- Handles manual CAPTCHA solving with a pause in the script. -- Automates login and logout functionalities after successful registration. -- Alerts and confirmations are managed effectively in the script. -- Uses dynamic waits to handle varying page load times. - - -### Prerequisites -Before running the project, ensure the following are installed and set up: - -1. **Java Development Kit (JDK)**: Install JDK 8 or later and set up the environment variables. -2. **Selenium WebDriver**: Include the Selenium library in your project. You can add it using a dependency manager like Maven/Gradle or manually download it. -3. **WebDriver Binary**: Ensure the ChromeDriver binary is installed and matches your Chrome browser version. Place it in a directory included in your system's PATH or provide the path explicitly in the code. -4. **Browser**: Google Chrome browser installed on the system. -5. **IDE**: Use an Integrated Development Environment like IntelliJ IDEA or Eclipse to run the script. - - -### **Technologies Used** -- **Programming Language**: Java -- **Automation Framework**: Selenium WebDriver -- **Browser**: Google Chrome -- **Testing Environment**: ToolsQA Demo Page -- **Java Libraries**: - - Selenium Support Libraries (`org.openqa.selenium.*`) - - WebDriverWait and ExpectedConditions for dynamic waits - - Java Utilities like `Scanner` for user input - - JavaScript Executor for smooth scrolling - +# Web Form Automation with Selenium + +This project demonstrates an automated script for filling out a web form using Selenium WebDriver. The script interacts with the website, which is designed to practice and master Selenium WebDriver automation. + +## Features +- Opens the Formy web form page. +- Fills out user details including name, job title, education level, gender, and years of experience. +- Inputs a specified date using a date picker. +- Submits the form and retrieves a success message. +- Incorporates best practices like explicit waits and JavaScript execution for enhanced performance. + +## Prerequisites +Before running this project, ensure you have the following installed: +1. **Java Development Kit (JDK)** - Version 8 or above. +2. **Google Chrome** - Latest stable version. +3. **ChromeDriver** - Version compatible with your Google Chrome browser. +4. **Selenium WebDriver** - Included in the project dependencies. + +## Technologies Used +- **Java** - The programming language for automation. +- **Selenium WebDriver** - For interacting with web elements and automating browser actions. +- **Google Chrome & ChromeDriver** - For browser automation. +- **JavaScript Executor** - For scrolling and handling advanced browser interactions. diff --git a/ToolsQA_Project/bin/tools_qa_page/Registeration_Form.class b/ToolsQA_Project/bin/tools_qa_page/Registeration_Form.class deleted file mode 100644 index e93963c..0000000 Binary files a/ToolsQA_Project/bin/tools_qa_page/Registeration_Form.class and /dev/null differ diff --git a/ToolsQA_Project/src/tools_qa_page/Registeration_Form.java b/ToolsQA_Project/src/tools_qa_page/Registeration_Form.java deleted file mode 100644 index 15766f2..0000000 --- a/ToolsQA_Project/src/tools_qa_page/Registeration_Form.java +++ /dev/null @@ -1,99 +0,0 @@ -package tools_qa_page; - -import java.time.Duration; -import java.util.Scanner; - -import org.openqa.selenium.Alert; -import org.openqa.selenium.By; -import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; - -public class Registeration_Form { - - public static void main(String[] args) { - WebDriver driver = new ChromeDriver(); - driver.manage().window().maximize(); - - WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); - driver.get("https://demoqa.com/login"); - - WebElement newUser = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@id='newUser']"))); - newUser.click(); - waitForTheUser(); - - JavascriptExecutor scrollDownTwo = (JavascriptExecutor) driver; - scrollDownTwo.executeScript("window.scrollBy(0,200)"); - waitForTheUser(); - - WebElement firstName = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='firstname']"))); - firstName.click(); - firstName.sendKeys("Mia"); - waitForTheUser(); - - WebElement lastName = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='lastname']"))); - lastName.click(); - lastName.sendKeys("Winters"); - waitForTheUser(); - - WebElement userName = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='userName']"))); - userName.click(); - userName.sendKeys("mia@22"); - waitForTheUser(); - - WebElement passWord = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='password']"))); - passWord.click(); - passWord.sendKeys("MiaWinters@22!"); - waitForTheUser(); - - // Pause the script for manual CAPTCHA solving - System.out.println("Please solve the CAPTCHA manually and press Enter to continue..."); - Scanner scanner = new Scanner(System.in); - scanner.nextLine(); // Waits for user input - scanner.close(); // Close the Scanner to avoid resource leak - - WebElement registerButon = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@id='register']"))); - registerButon.click(); - waitForTheUser(); - - Alert simpleAlert = driver.switchTo().alert(); - simpleAlert.accept(); - System.out.println("Alert accepted successfully."); - waitForTheUser(); - - WebElement backButon = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("(//button[@type='button'])[3]"))); - backButon.click(); - waitForTheUser(); - - WebElement uName = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='userName']"))); - uName.click(); - uName.sendKeys("mia@22"); - waitForTheUser(); - - WebElement pWord = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='password']"))); - pWord.click(); - pWord.sendKeys("MiaWinters@22!"); - waitForTheUser(); - - WebElement loginButton = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@id='login']"))); - loginButton.click(); - waitForTheUser(); - - WebElement logoutButton = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("(//button[@type='button'])[2]"))); - logoutButton.click(); - waitForTheUser(); - - driver.close(); - } - - public static void waitForTheUser() { - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } -}