Models POM
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
package com.agile611.testng.webdriver.pages;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
import org.openqa.selenium.WebDriver;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||||
|
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||||
|
|
||||||
|
|
||||||
|
public class BasePage {
|
||||||
|
public void waitPageToLoad(WebDriver driver, long secondsTimeout, WebElement webElement){
|
||||||
|
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(secondsTimeout));
|
||||||
|
wait.until(ExpectedConditions.elementToBeClickable(webElement));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,16 +5,16 @@ import org.openqa.selenium.WebElement;
|
|||||||
import org.openqa.selenium.support.FindBy;
|
import org.openqa.selenium.support.FindBy;
|
||||||
import org.openqa.selenium.support.PageFactory;
|
import org.openqa.selenium.support.PageFactory;
|
||||||
|
|
||||||
public class ResultsPage {
|
public class ResultsPage extends BasePage {
|
||||||
|
|
||||||
private WebDriver driver;
|
private WebDriver driver;
|
||||||
|
|
||||||
@FindBy(className = "react-results--main")
|
@FindBy(className = "react-results--main")
|
||||||
public WebElement resultsList;
|
public WebElement resultsList;
|
||||||
|
|
||||||
|
|
||||||
public ResultsPage(WebDriver driver) {
|
public ResultsPage(WebDriver driver) {
|
||||||
PageFactory.initElements(driver, this);
|
PageFactory.initElements(driver, this);
|
||||||
|
waitPageToLoad(driver, 10, resultsList);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isResultsPagePresent() {
|
public boolean isResultsPagePresent() {
|
||||||
|
|||||||
@@ -5,19 +5,18 @@ import org.openqa.selenium.WebElement;
|
|||||||
import org.openqa.selenium.support.FindBy;
|
import org.openqa.selenium.support.FindBy;
|
||||||
import org.openqa.selenium.support.PageFactory;
|
import org.openqa.selenium.support.PageFactory;
|
||||||
|
|
||||||
public class SearchPage {
|
public class SearchPage extends BasePage {
|
||||||
|
|
||||||
private WebDriver driver;
|
private WebDriver driver;
|
||||||
|
|
||||||
@FindBy(id = "searchbox_input")
|
@FindBy(id = "searchbox_input")
|
||||||
public WebElement searchBox;
|
public WebElement searchBox;
|
||||||
|
|
||||||
public SearchPage(WebDriver driver) {
|
public SearchPage(WebDriver driver) {
|
||||||
PageFactory.initElements(driver, this);
|
PageFactory.initElements(driver, this);
|
||||||
driver.get("https://duckduckgo.com/");
|
driver.get("https://duckduckgo.com/");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void searchKeyword(String keyword) {
|
public void searchKeyword(String keyword) {
|
||||||
|
waitPageToLoad(driver, 10, searchBox);
|
||||||
searchBox.clear();
|
searchBox.clear();
|
||||||
searchBox.sendKeys(keyword);
|
searchBox.sendKeys(keyword);
|
||||||
searchBox.submit();
|
searchBox.submit();
|
||||||
|
|||||||
Reference in New Issue
Block a user