Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.51 KB | None | 0 0
  1. package pageobject;
  2.  
  3. import org.openqa.selenium.By;
  4. import org.openqa.selenium.JavascriptExecutor;
  5. import org.openqa.selenium.WebDriver;
  6. import org.openqa.selenium.WebElement;
  7. import org.openqa.selenium.support.PageFactory;
  8. import org.openqa.selenium.support.ui.ExpectedConditions;
  9. import org.openqa.selenium.support.ui.FluentWait;
  10. import org.openqa.selenium.support.ui.WebDriverWait;
  11. import java.io.*;
  12. import java.util.Properties;
  13. import java.util.List;
  14.  
  15. public abstract class Page  {
  16.  
  17.     protected String url;
  18.     protected WebDriver webDriver;
  19.     protected FluentWait<WebDriver> wait;
  20.     protected FileInputStream fis;
  21.     protected Properties property = new Properties();
  22.     protected JavascriptExecutor js;
  23.  
  24.     private static String standURL ;
  25.  
  26.     public Page(WebDriver webDriver) {
  27.         this.webDriver = webDriver;
  28.         js = (JavascriptExecutor)webDriver;
  29.  
  30.         try {
  31.             fis = new FileInputStream("src/main/resources/resources");
  32.             property.load(fis);
  33.             standURL= property.getProperty("stand.url");
  34.         } catch (IOException e) {
  35.             e.printStackTrace();
  36.         }
  37.  
  38.  
  39.         wait = new WebDriverWait(webDriver, 20)
  40.                 .withMessage("Element was not found");
  41.         PageFactory.initElements(webDriver,this);
  42.  
  43.     }
  44.  
  45.     public static String getStandURL(){
  46.         return standURL;
  47.     }
  48.  
  49.     public String getUrl(){
  50.         return this.url;
  51.     }
  52.  
  53.     public Page open(){
  54.         webDriver.get(url);
  55.         return this;
  56.     }
  57.  
  58.     protected void input(WebElement webElement , String content){
  59.         waitVisibility(webElement).clear();
  60.         webElement.sendKeys(content);
  61.         webElement.submit();
  62.     }
  63.  
  64.     protected WebElement waitVisibility(WebElement webElement){
  65.         return wait.until(ExpectedConditions.visibilityOf(webElement));
  66.     }
  67.  
  68.     protected List<WebElement> waitVisibilityAll(List<WebElement> webElements){
  69.         return wait.until(ExpectedConditions.visibilityOfAllElements(webElements));
  70.     }
  71.  
  72.     protected WebElement waitClickable(WebElement webElement){
  73.         return wait.until(ExpectedConditions.elementToBeClickable(webElement));
  74.     }
  75.  
  76.     protected void waitStaleness(WebElement webElement){
  77.         wait.until(ExpectedConditions.stalenessOf(webElement));
  78.     }
  79.  
  80.     protected By byXpathWithProperty(String key){
  81.         return By.xpath(property.getProperty(key));
  82.     }
  83.  
  84.     protected Object jsExecutor(String jsScript){
  85.         return js.executeScript(jsScript);
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement