Activity 1: Write a Simple Test Script Using Selenium WebDriver and
TestNG
We will:
Install Java
Install Eclipse IDE
Set up Selenium and TestNG
Write and run a test that:
o Opens Amazon and searches for "Nike shoes"
o Opens Facebook and attempts login
🧩 STEP 1: Install Java JDK (if not installed)
1. Go to: [Link]
2. Download the latest JDK (e.g., JDK 21 or 17).
3. Run the installer and complete installation.
4. Set Environment Variables:
o Open System Properties > Environment Variables.
o Under System Variables, click New:
Variable name: JAVA_HOME
Variable value: C:\Program Files\Java\jdk-XX (adjust path if
needed)
o Find Path in System Variables, click Edit, and add:
plaintext
CopyEdit
%JAVA_HOME%\bin
5. To confirm:
o Open Command Prompt
o Run: java -version → it should show installed version
🧩 STEP 2: Install Eclipse IDE
1. Go to: [Link]
2. Download "Eclipse IDE for Java Developers"
3. Install and launch Eclipse.
4. Choose a workspace directory (default is fine).
🧩 STEP 3: Create a Java Project in Eclipse
1. In Eclipse:
File > New > Java Project
2. Name it: SeleniumTest
3. Click Finish
🧩 STEP 4: Create a Package and Class
1. Right-click src > New > Package
Name it: SeleniumTests (exactly this case)
2. Right-click the new package > New > Class
Name it: JenkinsTest
3. Tick public static void main(String[] args) if you're testing initially without
TestNG
4. Click Finish
🧩 STEP 5: Download and Add Selenium JARs
1. Go to: [Link]
2. Under Selenium Java, click Download (e.g., version 4.x).
3. Unzip the downloaded file (you'll see .jar files and a /libs folder).
Add to Eclipse:
1. Right-click SeleniumTest project > Build Path > Configure Build Path
2. Go to Libraries tab > Add External JARs
o Add:
[Link]
All JARs inside the /libs folder
3. Click Apply and Close
🧩 STEP 6: Install TestNG in Eclipse
(Only if not already installed)
1. Go to:
Help > Eclipse Marketplace
2. Search: TestNG
3. Click Install next to "TestNG for Eclipse"
4. Restart Eclipse after installation
🧩 STEP 7: Add TestNG Library to Your Project
1. Right-click SeleniumTest project > Build Path > Add Libraries
2. Choose TestNG > Next > Finish
🧩 STEP 8: Download ChromeDriver
1. Go to: [Link]
2. Download the version that matches your Chrome browser version
3. Unzip and place [Link] somewhere accessible, e.g.:
4. Latest is available here: [Link]
STEP 9: Write the Selenium + TestNG Test Script
📄 1. In your [Link], paste the following code:
java
CopyEdit
package SeleniumTests;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class JenkinsTest {
@Test
public void testAutomation() {
// Set the path to your ChromeDriver executable
[Link]("[Link]", "C:\\Users\\areeb\\
Downloads\\chromedriver-win64\\[Link]");
// Launch Chrome
WebDriver driver = new ChromeDriver();
[Link]().timeouts().implicitlyWait(5, [Link]);
try {
// Step 1: Open Amazon and search "Nike shoes"
[Link]("[Link]
[Link]([Link]("twotabsearchtextbox")).sendKeys("Nike
shoes");
[Link]([Link]("nav-search-submit-button")).click();
[Link](3000); // wait for results to load
// Step 2: Open Facebook and login attempt
[Link]("[Link]
[Link]([Link]("email")).sendKeys("abcd@[Link]");
[Link]([Link]("pass")).sendKeys("1234");
[Link]([Link]("login")).click();
[Link](3000); // wait to observe result
} catch (Exception e) {
[Link]("Error occurred: " + [Link]());
} finally {
// Close browser
[Link]();
}
}
}
📌 2. Double-check a few things:
✅ Package name matches exactly: SeleniumTests (not seleniumTests)
✅ ChromeDriver path is correct and includes .exe
✅ You imported TestNG and Selenium jars as explained
▶️3. Run the Test
1. Right-click on [Link]
2. Click: Run As > TestNG Test
✅ Expected Outcome:
Chrome opens
Amazon loads and searches for Nike shoes
Then, Facebook opens and attempts to login
Browser closes automatically
ACTIVITY 2
Step 1: Generate [Link] from Eclipse
In Eclipse, right-click your test class ([Link]) →
TestNG →
Convert to TestNG →
It will show a preview with XML, for example:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "[Link]
<suite name="Suite">
<test name="Test">
<classes>
<class name="[Link]"/>
</classes>
</test>
</suite>
Save this file as [Link] inside your Eclipse project folder
(e.g., C:\Users\areeb\eclipse-workspace\SeleniumTest\[Link])
Step 2: Run from command line inside Eclipse workspace
Since TestNG is installed inside Eclipse, it means the required libraries are inside Eclipse's
build path, but NOT necessarily in your project folder on disk.
Run tests only inside Eclipse (recommended if you want to avoid manual JAR
handling)
Just right-click on [Link] or your test class →
Run As →
TestNG Suite
This will run your test with all dependencies managed by Eclipse automatically.
ACTIVITY 3
CREATE FILE IN PRIJECT
[Link]
and paste
java -cp "bin;lib/*" [Link] [Link]
and run
Activity 4
Step 1: Ensure Pre-requisites
Jenkins is installed and running at [Link]
You have Maven installed and configured in Jenkins:
o Go to Manage Jenkins → Global Tool Configuration
o Under Maven, click Add Maven
o Name it: Maven_3.9.6 (or whatever version you're using)
o Check Install automatically
🔹 Step 2: Create a Jenkins Job
1. Go to Jenkins dashboard → New Item
2. Name it: Run-Selenium-Tests
3. Select: Freestyle Project
4. Click OK
🔹 Step 3: Set Up Custom Workspace
1. In the job configuration, go to the General tab
2. Click Advanced
3. ✅ Check Use custom workspace
4. Set directory path to:
C:\Users\areeb\eclipse-workspace\SeleniumTest
🔹 Step 4: Add Maven Build Step
1. Scroll to the Build section
2. Click Add build step → Invoke top-level Maven targets
3. In the Goals field, enter:
bash
CopyEdit
clean test
4. Under Maven Version, select the one you configured earlier (e.g., Maven_3.9.6)
🔹 Step 5: Add [Link] Configuration (If not already there)
Ensure your [Link] in C:\Users\areeb\eclipse-workspace\SeleniumTest has at least:
<project xmlns="[Link]
xmlns:xsi="[Link]
xsi:schemaLocation="[Link]
[Link]
<modelVersion>4.0.0</modelVersion>
<groupId>[Link]</groupId>
<artifactId>SeleniumTest</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>[Link]</groupId>
<artifactId>selenium-java</artifactId>
<version>4.18.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<!-- Added TestNG dependency -->
<dependency>
<groupId>[Link]</groupId>
<artifactId>testng</artifactId>
<version>7.8.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<!-- Specify where test sources are -->
<testSourceDirectory>src/SeleniumTests</testSourceDirectory>
<plugins>
<plugin>
<groupId>[Link]</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<!-- Optional: Tell Surefire to run TestNG tests -->
<suiteXmlFiles>
<suiteXmlFile>[Link]</suiteXmlFile>
</suiteXmlFiles>
<includes>
<include>**/*.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
🔹 Step 6: Run the Jenkins Job
1. Click Apply → Save
2. Hit Build Now
3. Click on the build number → Console Output
4. Verify Selenium opens the browser, runs tests, and shows success/fail logs
Note : Make sure to make folder with name lib and add jar file s in it
selenium jar files and tjcommander as well