This project uses Selenium, Java, and Maven for automated testing. It searches Google for "ProQuest," saves the search result titles in a file, and takes a screenshot after looking up "QA" on the ProQuest website.
This project uses Selenium, Java, and Maven for automated testing. It searches Google for "ProQuest," saves the search result titles in a file, and takes a screenshot after looking up "QA" on the ProQuest website.
Before you started, ensure you have installed all the necessary automation components First one is
Download and install:
- Download the latest version from Download JDK from Oracle website
- I have downloaded JDK 21.0.3 and ensure that Java version should be 11 or higher.
- Set up the JAVA_HOME environment variable to point to your JDK installation.
- You can verify by running the following command in your terminal/command prompt: Java -version
Download Maven:
- We can download maven version from this link Download Maven
- I have downloaded Maven latest version for windows which is Binary zip archive and extracted it and i saved it in Program files by creating Maven folder.
- I have Set up environment variables (add Maven bin folder to PATH) and in System variables, created MAVEN_HOME as variable and provided value as path of the Maven.
- I have Downloaded IntelliJ IDEA from JetBrains and installed it.
- Selected the Community version as a free option.
- Create a GitHub account and set up Git locally
- Instructions for Git setup can be found here.
- Clone the repository: git clone https://github.com/yourusername/ProQuestAutomationProj.git
This document provides step-by-step instructions for setting up and executing the automation project using Selenium.
- Open IntelliJ IDEA.
- Create a New Project:
- Select New Project.
- choose your JDK version, and hit Next.
- Name your project, and specify a location.
- Click on "Create" to create the project.
- From Maven Repository Add Dependencies in pom.xml: Open the pom.xml file in your project and add the following dependencies: Seleniumhq which is the latest version 4.20.0 and add WebDriverManager dependency version is 5.8.0 and add Apache Common IO in repository version is 2.16.1, to run all the tests in TestNG add testng 7.4.0.
- Save the pom.xml file. IntelliJ will automatically download the specified dependencies.
- Go to Project you have created in IntelliJ, in the src/test/java folder, create package tests.
- Inside the package, create new class called "GoogleSearchTest".
In Created class, write the selenium code using java to perform automation,
- Setup WebDriver and initialize the chromeDriver
- Set an implicit wait (global wait) to wait for 5 seconds to load all the elements on the webpage.
- Maximize the browser and by using driver method it will navigate to google.com
- In Search field search for "ProQuest" and Enter it (Using WebDriver locators) locate the elements in the DOM.
- Loop through the
WebElementsto find the titles of all results on the first page and write them to a text file on the operating system. - Click on ProQuest, search for "QA", and take a screenshot of the search results using the
TakesScreenshotinterface.
- Test 1: Searches for "ProQuest" on Google and writes the titles of search results to a file called GoogleSearchResults.txt.
- Test 2: Opens the ProQuest website, searches for "QA" in the navigation bar, and takes a screenshot saved as ProQuestSearchQA.png.
To run tests via TestNG, you can create a testng.xml file in your project root:
- We can run the tests using Maven, TestNG or simply right-click on the project and run the tests.
- Open a terminal and navigate to the project directory: cd ProQuestAutomation
- Compile and run the tests using Maven: mvn clean test
- Open a terminal and navigate to the project directory: cd ProQuestAutomation and run mvn clean test -Dsurefire.suiteXmlFiles=testng.xml
- Right-click on the GoogleSearchTest class and select Run GoogleSearchTest.main()
- We can also run the tests using TestNG by adding TestNG dependency in pom.xml file and run the tests via testng.xml file in Intellij itself.
Ensure that messages indicating success appear, such as
- Titles written to file successfully.
- Screenshot saved successfully.
- We can also see the results whether testcases are pass or not while running as per execution using TestNG.
- A text file named search_results.txt will be generated in the project directory containing the titles of the search results.
- A screenshot of the ProQuest website after searching for "QA" will be saved as ProQuest_QA_search.png.
- Open the terminal in the project directory.
- Initialize Git using git init command
- Add files (staging) git add *
- git commit -m "Initial commit"
- git remote add origin "github url"
- git push -u origin main