Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pageobject;
- import org.openqa.selenium.By;
- import org.openqa.selenium.JavascriptExecutor;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.support.PageFactory;
- import org.openqa.selenium.support.ui.ExpectedConditions;
- import org.openqa.selenium.support.ui.FluentWait;
- import org.openqa.selenium.support.ui.WebDriverWait;
- import java.io.*;
- import java.util.Properties;
- import java.util.List;
- public abstract class Page {
- protected String url;
- protected WebDriver webDriver;
- protected FluentWait<WebDriver> wait;
- protected FileInputStream fis;
- protected Properties property = new Properties();
- protected JavascriptExecutor js;
- private static String standURL ;
- public Page(WebDriver webDriver) {
- this.webDriver = webDriver;
- js = (JavascriptExecutor)webDriver;
- try {
- fis = new FileInputStream("src/main/resources/resources");
- property.load(fis);
- standURL= property.getProperty("stand.url");
- } catch (IOException e) {
- e.printStackTrace();
- }
- wait = new WebDriverWait(webDriver, 20)
- .withMessage("Element was not found");
- PageFactory.initElements(webDriver,this);
- }
- public static String getStandURL(){
- return standURL;
- }
- public String getUrl(){
- return this.url;
- }
- public Page open(){
- webDriver.get(url);
- return this;
- }
- protected void input(WebElement webElement , String content){
- waitVisibility(webElement).clear();
- webElement.sendKeys(content);
- webElement.submit();
- }
- protected WebElement waitVisibility(WebElement webElement){
- return wait.until(ExpectedConditions.visibilityOf(webElement));
- }
- protected List<WebElement> waitVisibilityAll(List<WebElement> webElements){
- return wait.until(ExpectedConditions.visibilityOfAllElements(webElements));
- }
- protected WebElement waitClickable(WebElement webElement){
- return wait.until(ExpectedConditions.elementToBeClickable(webElement));
- }
- protected void waitStaleness(WebElement webElement){
- wait.until(ExpectedConditions.stalenessOf(webElement));
- }
- protected By byXpathWithProperty(String key){
- return By.xpath(property.getProperty(key));
- }
- protected Object jsExecutor(String jsScript){
- return js.executeScript(jsScript);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement