-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24778d7
commit 507cbfd
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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); | ||
} | ||
} | ||
} |