These tools solve different testing problems. pytest is a Python testing framework, Robot Framework is keyword-driven automation, and Playwright is modern web E2E testing.
pytest Discovery
pytest discovers:
test_*.py*_test.py- functions starting with
test_
def test_add():
assert 1 + 2 == 3Fixtures
Fixtures prepare test state and can clean up afterward.
import pytest
@pytest.fixture
def setup_env():
print("prepare")
yield
print("cleanup")Use a fixture by naming it as a test parameter.
def test_example(setup_env):
assert TrueFixture Scope
Scope controls lifecycle:
function: once per test functionclass: once per test classmodule: once per filesession: once per test session
In real projects, shared fixtures usually live in conftest.py.
Robot Framework
Robot Framework uses keyword-driven tests that are easier for business stakeholders to read.
*** Test Cases ***
Login With Valid User
Open Browser To Login Page
Login With Valid Credentials ${USERNAME} ${PASSWORD}
Page Should Contain Element id=dashboardIt is useful for acceptance tests and workflow automation.
Playwright
Playwright is suited for modern web E2E.
test("user can login", async ({ page }) => {
await page.goto("/login");
await page.getByLabel("Username").fill("jesse");
await page.getByLabel("Password").fill("password");
await page.getByRole("button", { name: "Login" }).click();
await expect(page.getByTestId("dashboard")).toBeVisible();
});Reducing Flaky Tests
Avoid fixed sleeps as a universal solution.
Better options:
- Wait for elements to be visible
- Wait for buttons to be clickable
- Wait for requests
- Wait for URL changes
- Prepare data through API or database
- Keep UI tests focused on core paths
Stable tests wait for explicit conditions, not arbitrary time.