这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.baeldung.selenium;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;


public class SeleniumAttributeTextLiveTest {

private WebDriver driver;

private static final String URL = "https://www.baeldung.com/contact";
private static final String LABEL_XPATH = "//label[contains(text(),'Your Name')]";
private static final String LABEL_TEXT = "Your Name*";

private static final String INPUT_XPATH = "//label[contains(text(),'Your Name')]//input";
private static final String INPUT_NAME = "your-name";
private static final String INPUT_LENGTH = "400";

@BeforeEach
public void setUp() {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
}

@AfterEach
public void tearDown() {
driver.quit();
}

@Test
public void givenBaeldungContactPage_whenFoundLabel_thenContainsText() {
driver.get(URL);
WebElement inputElement = driver.findElement(By.xpath(LABEL_XPATH));
assertEquals(LABEL_TEXT, inputElement.getText());
}

@Test
public void givenBaeldungContactPage_whenFoundNameInput_thenContainsText() {
driver.get(URL);
WebElement inputElement = driver.findElement(By.xpath(INPUT_XPATH));
assertEquals("", inputElement.getText());
}

@Test
public void givenBaeldungContactPage_whenFoundNameInput_thenHasAttributeName() {
driver.get(URL);
WebElement inputElement = driver.findElement(By.xpath(INPUT_XPATH));
assertEquals(INPUT_NAME, inputElement.getAttribute("name"));
}

@Test
public void givenBaeldungContactPage_whenFoundNameInput_thenHasAttributeMaxlength() {
driver.get(URL);
WebElement inputElement = driver.findElement(By.xpath(INPUT_XPATH));
assertEquals(INPUT_LENGTH, inputElement.getAttribute("maxlength"));
}

@Test
public void givenBaeldungContactPage_whenFoundNameInput_thenHasNoAttributeX() {
driver.get(URL);
WebElement inputElement = driver.findElement(By.xpath(INPUT_XPATH));
assertNull(inputElement.getAttribute("X"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

import static org.junit.jupiter.api.Assertions.*;

import java.util.List;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
Expand Down