Created
December 2, 2024 16:32
-
-
Save borodicht/dadb7f1e98a140bc8a29ac667b49439a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pages; | |
import org.openqa.selenium.*; | |
import org.openqa.selenium.interactions.Actions; | |
import org.openqa.selenium.support.ui.ExpectedCondition; | |
import org.openqa.selenium.support.ui.WebDriverWait; | |
import javax.swing.*; | |
import java.time.Duration; | |
import java.util.Objects; | |
public abstract class BasePage { | |
WebDriver driver; | |
WebDriverWait wait; | |
public BasePage(WebDriver driver) { | |
this.driver = driver; | |
wait = new WebDriverWait(driver, Duration.ofSeconds(20)); | |
} | |
public void write(String label, String text) { | |
driver.findElement(By.xpath(String.format("//label[text()='%s']//ancestor::lightning-input//input", label))) | |
.sendKeys(text); | |
} | |
public void waitForPageLoaded() { | |
new ExpectedCondition<Boolean>() { | |
public Boolean apply(WebDriver driver) { | |
return Objects.requireNonNull(((JavascriptExecutor) driver).executeScript("return document.readyState")) | |
.toString().equals("complete"); | |
} | |
}; | |
} | |
public void clickJS(WebElement element) { | |
JavascriptExecutor js = (JavascriptExecutor) driver; | |
js.executeScript("argument[0].click();", element); | |
} | |
public void scrollJS() { | |
JavascriptExecutor js = (JavascriptExecutor) driver; | |
js.executeScript("window.scrollBy(0, 500)"); | |
} | |
public void scrollJSElement(WebElement element) { | |
JavascriptExecutor js = (JavascriptExecutor) driver; | |
js.executeScript("window.scrollIntoView(true);", element); | |
} | |
public void scroll() { | |
Actions actions = new Actions(driver); | |
actions.moveToElement(driver.findElement(By.id(""))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment