Sobes.tech
Junior

How to test a login form?

sobes.tech AI

Answer from AI

To test the login form, several key scenarios need to be checked:

  • Field validation: ensure that fields do not accept empty values and incorrect formats (e.g., invalid email).
  • Successful login check: enter correct data and verify that the user is authorized and directed to the correct page.
  • Error handling with incorrect data: enter wrong login or password and ensure that the correct error message is displayed.
  • Button behavior check: the "Login" button should only be active when required fields are filled.
  • Security testing: verify that the password is not displayed in plain text and that there are no vulnerabilities like SQL injections.

Example of a simple automated test using Selenium (Java):

WebDriver driver = new ChromeDriver();
driver.get("https://example.com/login");

// Enter login and password
WebElement loginInput = driver.findElement(By.id("login"));
WebElement passwordInput = driver.findElement(By.id("password"));
loginInput.sendKeys("validUser");
passwordInput.sendKeys("validPass");

// Click the button
WebElement submitButton = driver.findElement(By.id("submit"));
submitButton.click();

// Check redirection
assertTrue(driver.getCurrentUrl().contains("dashboard"));

driver.quit();