Skip to content

Commit

Permalink
Fix deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
burakkaygusuz committed Dec 2, 2024
1 parent fa4667c commit aadda4d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public WebElement findInput(By by) {
return wait.until(webDriver -> CustomConditions.elementToBeTypeable(webElement).apply(webDriver));
}

public String findAttribute(By by, String attribute) {
public String findDomProperty(By by, String property) {
WebElement webElement = this.findElement(by);
return webElement.getAttribute(attribute);
return webElement.getDomProperty(property);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public static ExpectedCondition<WebElement> elementToBeTypeable(final WebElement
return new ExpectedCondition<>() {
@Override
public WebElement apply(WebDriver driver) {
String inputType = element.getAttribute("type");
String inputName = element.getAttribute("name");
String inputType = element.getDomProperty("type");
String inputName = element.getDomProperty("name");
try {
if (inputType.matches("text|mail|password|number") ||
inputName.contains("message")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@

public class FormAuthenticationTest extends TestBase {

@Test(testName = "Login Test")
void loginTest() {
driver.get(props.getProperty("BASE_URL"));
assertThat(driver.getTitle()).isEqualTo("The Internet");

final By loginPageLinkTextLocator = By.linkText("Form Authentication");
final By usernameInputLocator = By.id("username");
final By passwordInputLocator = By.id("password");
final By loginButtonLocator = By.cssSelector("button[type='submit']");
final By securePageMessageLocator = By.id("flash");

webElementService.findButton(loginPageLinkTextLocator).click();
assertThat(webElementService.findElement(By.tagName("h2")).getText()).isEqualTo("Login Page");
webElementService.findInput(usernameInputLocator).sendKeys("tomsmith");
webElementService.findInput(passwordInputLocator).sendKeys("SuperSecretPassword!");

assertSoftly(soft -> {
soft.assertThat(webElementService.findAttribute(usernameInputLocator, "value")).isEqualTo("tomsmith");
soft.assertThat(webElementService.findAttribute(passwordInputLocator, "value"))
.isEqualTo("SuperSecretPassword!");
});

webElementService.findButton(loginButtonLocator).submit();
wait.until(ExpectedConditions.urlContains("/secure"));
assertThat(webElementService.findElement(securePageMessageLocator).getText().trim())
.contains("You logged into a secure area!");
}
@Test(testName = "Login Test")
void loginTest() {
driver.get(props.getProperty("BASE_URL"));
assertThat(driver.getTitle()).isEqualTo("The Internet");

final By loginPageLinkTextLocator = By.linkText("Form Authentication");
final By usernameInputLocator = By.id("username");
final By passwordInputLocator = By.id("password");
final By loginButtonLocator = By.cssSelector("button[type='submit']");
final By securePageMessageLocator = By.id("flash");

webElementService.findButton(loginPageLinkTextLocator).click();
assertThat(webElementService.findElement(By.tagName("h2")).getText()).isEqualTo("Login Page");
webElementService.findInput(usernameInputLocator).sendKeys("tomsmith");
webElementService.findInput(passwordInputLocator).sendKeys("SuperSecretPassword!");

assertSoftly(soft -> {
soft.assertThat(webElementService.findDomProperty(usernameInputLocator, "value")).isEqualTo("tomsmith");
soft.assertThat(webElementService.findDomProperty(passwordInputLocator, "value"))
.isEqualTo("SuperSecretPassword!");
});

webElementService.findButton(loginButtonLocator).submit();
wait.until(ExpectedConditions.urlContains("/secure"));
assertThat(webElementService.findElement(securePageMessageLocator).getText().trim())
.contains("You logged into a secure area!");
}
}

0 comments on commit aadda4d

Please sign in to comment.