Skip to content

Commit

Permalink
add class with bases methods
Browse files Browse the repository at this point in the history
  • Loading branch information
irinaBerendeeva87 committed Dec 15, 2023
1 parent 24778d7 commit 507cbfd
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/main/java/org/example/pageobjects/BasePageObject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.example.pageobjects;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.pagefactory.DefaultElementLocatorFactory;
import org.openqa.selenium.support.pagefactory.DefaultFieldDecorator;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

import static org.openqa.selenium.support.PageFactory.initElements;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOf;

public class BasePageObject {

private final WebDriver driver;
private final WebDriverWait wait;
private static final Duration timeout = Duration.ofSeconds(10);

public BasePageObject(WebDriver driver) {
this.driver = driver;
wait = new WebDriverWait(driver, timeout);
DefaultElementLocatorFactory locatorFactory = new DefaultElementLocatorFactory(driver);
initElements(new DefaultFieldDecorator(locatorFactory), this);
}

public WebDriver getDriver() {
return driver;
}

public String getCurrentUrl() {
return driver.getCurrentUrl();
}

protected WebElement waitForVisibility(WebElement element) {
wait.until(visibilityOf(element));
return element;
}

protected void sleep(long milliseconds) {
try {
Thread.sleep(milliseconds);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit 507cbfd

Please sign in to comment.