Practical 8
Practical Title:
To design and execute automated test scripts using Selenium for functional testing
Theory:
1. What is Functional Testing?
Functional testing is a type of testing that checks whether the application functions
according to the specified requirements.
It focuses on inputs, outputs, and expected behavior.
__________________________________________________________
2. Advantages of Selenium for Testing:
Selenium provides:
• Automation of browser actions
• Support for multiple languages (Python, Java, etc.)
• Cross-browser testing
• Open-source and free
• Integration with testing frameworks
__________________________________________________________
Procedure:
Step 1: Setup Selenium environment
Step 2: Launch browser using WebDriver
Step 3: Navigate to a web application
Step 4: Locate elements using locators (id, name, xpath, etc.)
Step 5: Perform actions (click, send keys, submit)
Step 6: Validate output using assertions
Step 7: Close the browser
Activity / Task:
Task 1:
Write a Selenium script to test login functionality of a website.
Code:
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class LoginTest {
public static void main(String[] args) throws InterruptedException
{
[Link]().setup();
WebDriver driver = new ChromeDriver();
// Open website
[Link]("[Link]
[Link]().window().maximize();
[Link](3000);
// Enter username
[Link]([Link]("username")).sendKeys("tomsmith");
[Link](3000);
// Enter password
[Link]([Link]("password")).sendKeys("SuperSecretPassword!");
[Link](3000);
// Click login
[Link]([Link]("button[type='submit']")).click();
[Link](5000);
// Close browser
[Link]();
}
}
__________________________________________
Task 2:
Test form submission with valid and invalid inputs.
Description:
__________________________________________
Advantages:
1. Fast Execution
2. Accurate Testing
3. Reusable Scripts
4. Cross Browser Support
5. Supports CI/CD Integration
Challenges:
1. Maintenance of Scripts
2. Dynamic Element Handling
3. Requires Programming Knowledge