Introduction
After creating your first Selenium script, the next step is to run your first automation test. Running a Selenium test means executing a Python script that automatically controls a web browser, performs predefined actions, verifies expected results, and reports whether the test has passed or failed.
Executing automation tests is the core of Selenium-based testing. Every automation engineer runs Selenium scripts multiple times during development, debugging, regression testing, and Continuous Integration/Continuous Deployment (CI/CD) pipelines.
In this tutorial, you’ll learn how to run your first Selenium automation test, understand the execution flow, verify test results, explore practical examples, and follow industry best practices.
What is an Automation Test?
An automation test is a program that automatically performs testing activities on a web application without manual intervention.
Instead of manually opening a browser and checking application functionality, Selenium executes these steps automatically.
A typical automation test performs the following tasks:
Launch the browser
Open the application
Perform user actions
Validate expected results
Report the test status
Close the browser
Why Do We Run Automation Tests?
Running automation tests helps to:
Reduce manual testing effort
Execute repetitive test cases quickly
Improve testing accuracy
Detect defects early
Save testing time
Support Continuous Integration (CI/CD)
Enable regression testing
Automation tests provide faster and more reliable feedback compared to manual testing.
Prerequisites
Before running your first automation test, ensure that:
Python is installed.
Selenium is installed.
A browser (Chrome, Firefox, Edge, etc.) is installed.
Selenium installation has been verified.
Your Selenium script is saved successfully.
Sample Automation Test
Create a Python file named:
first_test.py
Write the following code:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://example.com")
print("Page Title:", driver.title)
driver.quit()
Running the Test in Visual Studio Code
Follow these steps:
Step 1
Open your Selenium project in Visual Studio Code.
Step 2
Open the Python file.
Example:
first_test.py
Step 3
Click the Run Python File button located at the top-right corner.
OR
Open the integrated terminal and execute:
python first_test.py
On some systems, you may need:
python3 first_test.py
Running the Test in PyCharm
Follow these steps:
Step 1
Open your Selenium project.
Step 2
Right-click on:
first_test.py
Step 3
Click:
Run 'first_test'
PyCharm executes the automation script.
Output
Page Title: Example Domain
During execution:
Chrome launches.
Example.com opens.
The page title is printed in the console.
The browser closes.
Understanding the Test Execution Flow
When the automation script runs, Selenium performs the following steps:
Python Script
│
▼
Selenium WebDriver
│
▼
Browser Driver
│
▼
Launch Browser
│
▼
Open Website
│
▼
Execute Commands
│
▼
Validate Results
│
▼
Close Browser
This sequence represents the basic lifecycle of a Selenium automation test.
Verifying Test Execution
If everything is configured correctly, you should observe:
The browser launches automatically.
The specified website opens.
The automation commands execute successfully.
The expected output appears in the terminal.
The browser closes without errors.
If these steps occur successfully, your first Selenium automation test has passed.
Practical Example
The following automation test opens Google’s homepage and verifies its title.
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.google.com")
assert "Google" in driver.title
print("Test Passed")
driver.quit()
Output
Test Passed
The assert statement validates that the page title contains the word Google.
Automation Testing Example
Suppose you’re testing a company’s login page.
Your first automation test could:
Launch Chrome
Open the login page
Verify the page title
Print a success message
Close the browser
Example:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://example.com")
assert "Example Domain" in driver.title
print("Homepage Loaded Successfully")
driver.quit()
Output
Homepage Loaded Successfully
Real-World Example
Imagine you’re testing an online banking application.
Your first automated test might:
Launch the browser
Open the banking website
Verify that the homepage loads correctly
Check the application title
Close the browser
If the title matches the expected value, the application is considered available for further testing.
Common Mistakes Beginners Make
Forgetting to Save the File
Running an unsaved file may execute outdated code.
Always save your script before running it.
Running the Wrong Python File
Ensure that you’re executing the correct Selenium script.
Incorrect:
python test.py
Correct:
python first_test.py
Forgetting to Install Selenium
If Selenium is not installed, you may see:
ModuleNotFoundError: No module named 'selenium'
Install Selenium using:
pip install selenium
Closing the Browser Too Early
Avoid placing:
driver.quit()
before completing all automation steps.
Best Practices
Keep your first automation test simple.
Verify browser launch before interacting with elements.
Use meaningful file names such as
login_test.pyorhomepage_test.py.Use assertions to validate expected results.
Always close the browser using
driver.quit().Organize test scripts inside a dedicated project folder.
Test your scripts on multiple browsers whenever possible.
Conclusion
Running your first Selenium automation test is an important milestone in your automation journey. It demonstrates the complete automation workflow—from launching a browser and opening a website to validating results and closing the browser.
Once you’re comfortable running basic automation tests, you’ll be ready to interact with web elements, implement synchronization, handle dynamic pages, and build scalable automation frameworks using Selenium with Python.
Frequently Asked Questions (FAQs)
What is an automation test?
An automation test is a program that automatically executes testing steps on an application without manual intervention.
How do I run a Selenium script?
In Visual Studio Code:
python first_test.py
Or click Run Python File.
How do I know if my test passed?
If the script executes successfully without errors and the expected output or assertions are satisfied, the test has passed.
Why is the browser closing automatically?
The browser closes because the script calls:
driver.quit()
This ends the browser session after the test completes.
Can I run the same automation test multiple times?
Yes.
One of the biggest advantages of Selenium is that automation tests can be executed repeatedly with consistent results.
Key Takeaways
Running an automation test means executing a Selenium script to validate application behavior automatically.
Every Selenium automation test follows a basic workflow: launch browser, open application, perform actions, validate results, and close the browser.
Selenium scripts can be executed using Visual Studio Code, PyCharm, or the command line.
Assertions help verify that the application behaves as expected.
Always save your script before execution and close the browser after the test completes.
Successfully running your first automation test prepares you for advanced Selenium topics such as locators, waits, WebElement interactions, and framework development.
