QA Cheat Sheets 2026: Selenium, Playwright, SQL, HTTP Codes & Git
Six one-page cheat sheets every tester needs before an interview or a sprint — Selenium locators & commands, Playwright, SQL queries, HTTP status codes, Git and TestNG. Save any of them as a free PDF.
Cheat sheets are the fastest way to revise before an interview, a live coding round or your first week on a new automation project. We have put the commands and syntax testers use every day on one page, with short notes on when to use each one.
Use the contents below to jump to a sheet. Tap Download PDF to save the whole page as a PDF (choose “Save as PDF” in the print dialog) and keep it on your phone or laptop.
1. Selenium locators cheat sheet (Java)
| Locator | Syntax | Use when |
|---|---|---|
| ID | By.id("email") | Unique, stable id exists — fastest and first choice |
| Name | By.name("password") | Form fields with a name attribute |
| Class name | By.className("btn-primary") | Single class only (no spaces) |
| Tag name | By.tagName("a") | Collect all links, rows, inputs |
| Link text | By.linkText("Forgot password?") | Exact visible text of a link |
| Partial link text | By.partialLinkText("Forgot") | Part of a link’s text |
| CSS selector | By.cssSelector("input#email") | Fast, readable; preferred over XPath |
| XPath | By.xpath("//button[text()='Login']") | Text-based, parent/sibling navigation |
CSS selector syntax
| Pattern | Example | Meaning |
|---|---|---|
| #id | #email | Element with id=”email” |
| .class | .card.active | Element with both classes |
| tag[attr=value] | input[type='submit'] | Attribute equals |
| [attr^=] | a[href^='https'] | Starts with |
| [attr$=] | img[src$='.png'] | Ends with |
| [attr*=] | div[class*='error'] | Contains |
| parent > child | form > button | Direct child |
| ancestor descendant | table td | Any descendant |
| A + B | label + input | Next sibling |
| :nth-child(n) | tr:nth-child(2) td | Position among siblings |
XPath syntax
| Pattern | Example |
|---|---|
| Attribute | //input[@id='email'] |
| Exact text | //button[text()='Login'] |
| Contains | //div[contains(@class,'error')] |
| Starts with | //input[starts-with(@id,'user_')] |
| AND / OR | //input[@type='text' and @name='q'] |
| Index | (//table//tr)[3] |
| Parent | //span[text()='Price']/.. |
| Following sibling | //label[text()='Email']/following-sibling::input |
| Ancestor | //td[text()='Asha']/ancestor::tr |
| Normalize space | //h2[normalize-space()='My Orders'] |
Selenium 4 relative locators
import static org.openqa.selenium.support.locators.RelativeLocator.with;
WebElement password = driver.findElement(with(By.tagName("input")).below(By.id("email")));
WebElement cancel = driver.findElement(with(By.tagName("button")).toLeftOf(By.id("submit")));
// also: above(), toRightOf(), near()2. Selenium WebDriver commands cheat sheet
| Task | Code (Java) |
|---|---|
| Start Chrome (Selenium Manager) | WebDriver driver = new ChromeDriver(); |
| Open URL / back / refresh | driver.get(url); driver.navigate().back(); driver.navigate().refresh(); |
| Title / URL | driver.getTitle(); driver.getCurrentUrl(); |
| Type / click / clear | el.sendKeys("text"); el.click(); el.clear(); |
| Read text / attribute | el.getText(); el.getAttribute("value"); el.getDomAttribute("href"); |
| State checks | el.isDisplayed(); el.isEnabled(); el.isSelected(); |
| Implicit wait | driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5)); |
| Explicit wait | new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.id("pay"))); |
| Dropdown | new Select(el).selectByVisibleText("India"); |
| Mouse hover / drag | new Actions(driver).moveToElement(menu).perform(); new Actions(driver).dragAndDrop(src, dst).perform(); |
| Right / double click | new Actions(driver).contextClick(el).doubleClick(el).perform(); |
| Alert | Alert a = driver.switchTo().alert(); a.getText(); a.accept(); |
| Frame | driver.switchTo().frame("payFrame"); driver.switchTo().defaultContent(); |
| New window / tab | driver.switchTo().newWindow(WindowType.TAB); for (String h : driver.getWindowHandles()) driver.switchTo().window(h); |
| JavaScript click / scroll | ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", el); |
| Screenshot | File f = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); |
| Upload file | driver.findElement(By.id("cv")).sendKeys("C:/data/cv.pdf"); |
| Cookies | driver.manage().getCookies(); driver.manage().deleteAllCookies(); |
| Headless | ChromeOptions o = new ChromeOptions(); o.addArguments("--headless=new"); |
| Close vs quit | driver.close(); // current window driver.quit(); // whole session |
🚀 Revised? Now apply to today’s QA jobs
QA Jobs India shares 100+ fresh QA & software testing openings every morning — manual, automation, API and remote roles.
See today’s QA jobs →3. Playwright cheat sheet (TypeScript)
CLI commands
| Command | What it does |
|---|---|
npm init playwright@latest | Create a new project with config and example test |
npx playwright install --with-deps | Install browsers and OS dependencies |
npx playwright test | Run all tests (headless, in parallel) |
npx playwright test login.spec.ts --headed | Run one file with a visible browser |
npx playwright test --project=chromium | Run one project/browser |
npx playwright test --grep @smoke | Run tagged tests |
npx playwright test --ui | UI mode with watch and time-travel |
npx playwright test --debug | Step through with the Inspector |
npx playwright codegen https://site.com | Record actions and generate code |
npx playwright show-report | Open the last HTML report |
npx playwright show-trace trace.zip | Open a trace file |
npx playwright test --shard=1/3 | Run one shard of the suite on CI |
Locators, actions and assertions
// locators (preferred order)
page.getByRole('button', { name: 'Login' })
page.getByLabel('Email')
page.getByPlaceholder('Search jobs')
page.getByText('Welcome back')
page.getByTestId('cart-count')
page.locator('#id, .class, [data-x="1"]')
page.getByRole('row').filter({ hasText: 'Asha' }).getByRole('button')
// actions
await page.goto('/login');
await locator.click(); await locator.dblclick();
await locator.fill('text'); await locator.press('Enter');
await locator.check(); await locator.selectOption('India');
await locator.hover(); await locator.setInputFiles('cv.pdf');
await locator.dragTo(target);
// web-first assertions (auto-retry)
await expect(page).toHaveURL(/dashboard/);
await expect(page).toHaveTitle('Orders');
await expect(locator).toBeVisible();
await expect(locator).toHaveText('Paid');
await expect(locator).toContainText('Order');
await expect(locator).toHaveValue('qa@test.com');
await expect(locator).toHaveCount(5);
await expect(locator).toBeEnabled();
await expect.soft(locator).toHaveAttribute('aria-checked', 'true');
// network
await page.route('**/api/jobs', r => r.fulfill({ json: [] }));
const resp = page.waitForResponse('**/api/cart');
// frames, popups, dialogs
page.frameLocator('#pay').getByLabel('Card');
const popup = page.waitForEvent('popup');
page.once('dialog', d => d.accept());4. SQL cheat sheet for testers
| Need | Query |
|---|---|
| All columns | SELECT * FROM users; |
| Filter | SELECT name, city FROM users WHERE city = 'Pune' AND status = 'ACTIVE'; |
| Pattern match | SELECT * FROM users WHERE email LIKE '%@gmail.com'; |
| Range / list | WHERE salary BETWEEN 30000 AND 60000; WHERE city IN ('Pune','Mumbai'); |
| NULL check | SELECT * FROM orders WHERE delivered_at IS NULL; |
| Sort and limit | SELECT * FROM orders ORDER BY created_at DESC LIMIT 10; |
| Count / sum / avg | SELECT COUNT(*), SUM(amount), AVG(amount) FROM orders; |
| Group with filter | SELECT city, COUNT(*) FROM users GROUP BY city HAVING COUNT(*) > 100; |
| Distinct | SELECT DISTINCT status FROM orders; |
| Inner join | SELECT o.id, u.name FROM orders o JOIN users u ON u.id = o.user_id; |
| Left join (find missing) | SELECT u.id FROM users u LEFT JOIN orders o ON o.user_id = u.id WHERE o.id IS NULL; |
| Duplicates | SELECT email, COUNT(*) FROM users GROUP BY email HAVING COUNT(*) > 1; |
| 2nd highest salary | SELECT MAX(salary) FROM emp WHERE salary < (SELECT MAX(salary) FROM emp); |
| Nth highest (window) | SELECT salary FROM (SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) r FROM emp) t WHERE r = 3; |
| Insert / update / delete | INSERT INTO users(name) VALUES('Asha'); UPDATE users SET status='X' WHERE id=5; DELETE FROM users WHERE id=5; |
5. HTTP status codes cheat sheet
| Code | Name | What a tester should check |
|---|---|---|
| 200 | OK | Successful GET/PUT; validate response body and schema |
| 201 | Created | POST created a resource; check Location header / returned id |
| 202 | Accepted | Request queued for async processing; poll for the result |
| 204 | No Content | Success with empty body (often DELETE) |
| 301 / 302 | Moved / Found | Redirects; check target URL and SEO redirects |
| 304 | Not Modified | Caching works (ETag / If-Modified-Since) |
| 400 | Bad Request | Invalid input — negative tests should return clear errors |
| 401 | Unauthorized | Missing/invalid token — test expired and wrong tokens |
| 403 | Forbidden | Logged in but no permission — role-based access tests |
| 404 | Not Found | Wrong id or URL — must not leak stack traces |
| 405 | Method Not Allowed | Wrong HTTP method for the endpoint |
| 409 | Conflict | Duplicate record or version conflict |
| 415 | Unsupported Media Type | Wrong Content-Type header |
| 422 | Unprocessable Entity | Valid JSON but failed business validation |
| 429 | Too Many Requests | Rate limiting; check Retry-After header |
| 500 | Internal Server Error | Server bug — always report with request/response |
| 502 / 503 / 504 | Bad Gateway / Unavailable / Timeout | Downstream or infra issues; test retries and error pages |
HTTP methods
| Method | Purpose | Idempotent |
|---|---|---|
| GET | Read a resource | Yes |
| POST | Create / trigger an action | No |
| PUT | Replace a resource fully | Yes |
| PATCH | Update part of a resource | Not guaranteed |
| DELETE | Remove a resource | Yes |
| HEAD / OPTIONS | Headers only / allowed methods (CORS preflight) | Yes |
6. Git commands cheat sheet
| Command | What it does |
|---|---|
git clone <url> | Copy a remote repository |
git status | See changed, staged and untracked files |
git switch -c feature/login-tests | Create and switch to a new branch |
git add . / git add file | Stage changes |
git commit -m "Add login tests" | Save staged changes with a message |
git push -u origin feature/login-tests | Push a new branch and set upstream |
git pull --rebase | Get latest changes and replay yours on top |
git fetch | Download remote changes without merging |
git merge main | Merge main into the current branch |
git log --oneline --graph | Compact history |
git diff / git diff --staged | Show unstaged / staged changes |
git stash / git stash pop | Park work temporarily and bring it back |
git restore file | Discard local changes in a file |
git reset --soft HEAD~1 | Undo last commit, keep changes staged |
git revert <commit> | Create a new commit that undoes one (safe on shared branches) |
git cherry-pick <commit> | Apply one commit to the current branch |
git branch -d name | Delete a merged local branch |
target/, node_modules/, reports and .env to .gitignore.Bonus: TestNG annotations and order
| Annotation | Runs |
|---|---|
| @BeforeSuite / @AfterSuite | Once before / after the whole suite |
| @BeforeTest / @AfterTest | Before / after each <test> tag in testng.xml |
| @BeforeClass / @AfterClass | Before / after the first / last method in a class |
| @BeforeMethod / @AfterMethod | Before / after every @Test method |
| @Test(priority, groups, dependsOnMethods, dataProvider, invocationCount, enabled) | The test itself |
| @DataProvider | Supplies data sets to a test |
| @Parameters | Reads values from testng.xml |
Order: BeforeSuite → BeforeTest → BeforeClass → BeforeMethod → Test → AfterMethod → AfterClass → AfterTest → AfterSuite.
FAQs
How do I download these cheat sheets as a PDF?
Tap the Download PDF button at the top, then choose “Save as PDF” as the printer. Headers, menus and buttons are hidden automatically in the PDF.
Are these cheat sheets enough for an interview?
They are for quick revision. Pair them with the full interview question banks linked below and one hands-on project.
Which cheat sheet should a fresher start with?
SQL, HTTP status codes and Selenium locators — these are asked in almost every fresher QA interview.
Will you add more cheat sheets?
Yes. We will keep adding sheets such as Postman, Linux commands and Appium on the QA Study Material hub.
📚 More QA interview question banks
Selenium (60) · Playwright (50) · Manual Testing (60) · API Testing (50) · SQL for Testers (50) · Mobile / Appium (50) · JIRA & Agile (50) — open the all-in-one QA Study Material hub →
💎 Get every QA opening, every day
Join QA Jobs India Premium for 100+ verified QA jobs daily with HR contact details.