Skip to content

Instantly share code, notes, and snippets.

@borodicht
Created December 2, 2024 16:32
Show Gist options
  • Save borodicht/dadb7f1e98a140bc8a29ac667b49439a to your computer and use it in GitHub Desktop.
Save borodicht/dadb7f1e98a140bc8a29ac667b49439a to your computer and use it in GitHub Desktop.
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