From aadda4df8810355ba90ba4782e7366f7c54fe4bd Mon Sep 17 00:00:00 2001 From: Burak Kaygusuz Date: Mon, 2 Dec 2024 09:39:39 +0300 Subject: [PATCH] Fix deprecated methods --- .../services/WebElementService.java | 4 +- .../synchronizations/CustomConditions.java | 4 +- .../tests/FormAuthenticationTest.java | 54 +++++++++---------- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/main/java/io/github/burakkaygusuz/services/WebElementService.java b/src/main/java/io/github/burakkaygusuz/services/WebElementService.java index 7b5371e..efb8c32 100644 --- a/src/main/java/io/github/burakkaygusuz/services/WebElementService.java +++ b/src/main/java/io/github/burakkaygusuz/services/WebElementService.java @@ -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); } } diff --git a/src/main/java/io/github/burakkaygusuz/synchronizations/CustomConditions.java b/src/main/java/io/github/burakkaygusuz/synchronizations/CustomConditions.java index fed9a87..081bd9a 100644 --- a/src/main/java/io/github/burakkaygusuz/synchronizations/CustomConditions.java +++ b/src/main/java/io/github/burakkaygusuz/synchronizations/CustomConditions.java @@ -20,8 +20,8 @@ public static ExpectedCondition 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")) { diff --git a/src/test/java/io/github/burakkaygusuz/tests/FormAuthenticationTest.java b/src/test/java/io/github/burakkaygusuz/tests/FormAuthenticationTest.java index e5ad155..954a1f4 100644 --- a/src/test/java/io/github/burakkaygusuz/tests/FormAuthenticationTest.java +++ b/src/test/java/io/github/burakkaygusuz/tests/FormAuthenticationTest.java @@ -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!"); + } }