SELENIUM CONFIGURATION

Описание к видео SELENIUM CONFIGURATION

SELENIUM CONFIGURATION FOR JAVA TESTER
Example: Automation Test Case and Test Script using Selenium WebDriver

Test Case: Validate Login Functionality on Example Website


---

Test Script: Selenium WebDriver (Java)

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class LoginTest {
public static void main(String[] args) {
// Set up the ChromeDriver path
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");

// Initialize WebDriver
WebDriver driver = new ChromeDriver();

try {
// Step 1: Launch the browser and navigate to the login page
driver.get("https://example.com/login");

// Step 2: Locate and interact with elements
WebElement usernameField = driver.findElement(By.id("username"));
WebElement passwordField = driver.findElement(By.id("password"));
WebElement loginButton = driver.findElement(By.id("loginButton"));

// Step 3: Enter credentials and click login
usernameField.sendKeys("validUsername");
passwordField.sendKeys("validPassword");
loginButton.click();

// Step 4: Verify login
String expectedUrl = "https://example.com/dashboard";
if (driver.getCurrentUrl().equals(expectedUrl)) {
System.out.println("Test Passed: User successfully logged in.");
} else {
System.out.println("Test Failed: Login not successful.");
}
} finally {
// Close the browser
driver.quit();
}
}
}


---

Example: API Testing with Selenium and REST Assured

Test Case: Validate API Response of Login Endpoint


---

Test Script: REST Assured (Java)

import io.restassured.RestAssured;
import io.restassured.response.Response;

import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;

public class LoginApiTest {
public static void main(String[] args) {
// Set base URI
RestAssured.baseURI = "https://example.com/api";

// Create a POST request for login
Response response = given()
.header("Content-Type", "application/json")
.body("{\"username\":\"validUsername\", \"password\":\"validPassword\"}")
.when()
.post("/login");

// Assert response status and content
response.then().statusCode(200)
.body("status", equalTo("success"))
.body("token", notNullValue());

// Print the response
System.out.println("Response: " + response.asString());
}
}


---

Execution Notes

1. WebDriver Setup: Replace path/to/chromedriver with the actual path to your chromedriver executable.


2. API Tool: The REST Assured library is used for API testing. Add the necessary dependencies to your pom.xml if using Maven.


3. Prerequisites: Ensure proper API and website availability.


4. Parallel Execution: You can integrate both scripts into a test suite for automated execution.

Комментарии

Информация по комментариям в разработке