Why Learn Test Automation?
If you’re starting your QA career or want to level up your testing skills, learning how to automate tests is a smart move. Automation helps reduce repetitive manual testing, speeds up releases, and makes your resume stand out — especially in Agile or DevOps teams.
In this guide, you’ll write your first test automation script using either Selenium (Java) or Cypress (JavaScript) — no prior automation experience needed.
🚀 Option 1: Create a Test Automation Script Using Selenium (Java)
Step 1: Set Up Your Environment
You’ll need:
- Java (JDK 8+)
- IntelliJ or Eclipse
- Maven
- Selenium WebDriver
Maven Dependency:
xmlCopyEdit<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.18.1</version>
</dependency>
Step 2: Write a Simple Script
Here’s a script that opens Google and searches for “QA Playbook”.
javaCopyEditimport org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class GoogleSearchTest {
public static void main(String[] args) {
// Set up ChromeDriver
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
WebDriver driver = new ChromeDriver();
// Navigate to Google
driver.get("https://www.google.com");
// Locate the search box and enter text
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("QA Playbook");
searchBox.submit();
// Wait and close
try { Thread.sleep(3000); } catch (InterruptedException e) {}
driver.quit();
}
}
✅ What this does:
Launches Chrome, searches Google, and closes the browser.
🌿 Option 2: Create a Test Script Using Cypress (JavaScript)
Step 1: Set Up Cypress
You’ll need:
- Node.js & npm
- A test project folder
Install Cypress:
bashCopyEditnpm init -y
npm install cypress --save-dev
Open Cypress with:
bashCopyEditnpx cypress open
Step 2: Write a Test Script
Create a file in: cypress/e2e/search.cy.js
javascriptCopyEditdescribe('Google Search Test', () => {
it('searches for QA Playbook', () => {
cy.visit('https://www.google.com');
cy.get('input[name="q"]').type('QA Playbook{enter}');
cy.wait(3000);
});
});
✅ What this does:
Opens Google in the Cypress test browser, types a search, and waits.
🧠 Which Tool Should You Learn First?
Feature | Selenium | Cypress |
---|---|---|
Language | Java, Python, etc. | JavaScript only |
Setup | More steps | Quick & easy |
Test Speed | Slower | Fast |
Community | Mature | Growing fast |
Use Case | Cross-browser | Mostly Chrome/Edge |
💡 Recommendation:
- Start with Cypress if you know JavaScript or want fast results
- Try Selenium if you’re already learning Java or need cross-browser support
📁 Tips for Beginners
- Always break your tests into small reusable parts
- Use comments to describe each step
- Focus on one scenario at a time
- Learn basic selectors (IDs, names, XPaths)
- Avoid relying only on
Thread.sleep
– learn waits and assertions next
✅ What’s Next?
Now that you’ve created your first script, explore these next steps:
- Add assertions to validate results
- Run tests in headless mode
- Explore Page Object Model (POM)
- Integrate with CI/CD tools like GitHub Actions or Jenkins
💥 Start Building Your Automation Portfolio Today
Even a single script can show initiative to employers. Add your code to GitHub and explain the logic in a README. Over time, build on this with multiple test scenarios.