Advertisement
Guest User

Untitled

a guest
Oct 15th, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 3.20 KB | None | 0 0
  1. import java.io.FileInputStream
  2. import java.util.Properties
  3.  
  4. import org.openqa.selenium.chrome.ChromeDriver
  5. import org.openqa.selenium.interactions.Actions
  6. import org.openqa.selenium.support.ui.{ExpectedCondition, ExpectedConditions, WebDriverWait}
  7. import org.openqa.selenium.{By, JavascriptExecutor, WebDriver}
  8. import org.scalatest.{BeforeAndAfterAll, FunSuite}
  9.  
  10. abstract class TestBase extends FunSuite with BeforeAndAfterAll {
  11.   implicit var driver: WebDriver = null
  12.   val prop = new Properties()
  13.   prop.load(new FileInputStream(".cfg\\website-tests.cfg"))
  14.  // val allProfiles = new ProfilesIni()
  15.   System.setProperty("webdriver.chrome.driver", prop.getProperty("chromedriver_path"))
  16.  
  17.   driver = new ChromeDriver()
  18.   val js = driver.asInstanceOf[JavascriptExecutor]
  19.   val builder = new Actions(driver)
  20.  
  21.   def WaitTillDisplayed (arg: String) {
  22.     new WebDriverWait(driver, 100).until(new ExpectedCondition[Boolean] {
  23.       override def apply(d: WebDriver) =  d.findElement(By.xpath(arg)).isDisplayed()
  24.     })
  25.   }
  26.  
  27.   def WaitTillToBeClickable(arg: String)  {
  28.     WaitTillDisplayed(arg)
  29.     new WebDriverWait(driver, 100).until(ExpectedConditions.elementToBeClickable(By.xpath(arg)))
  30.   }
  31.  
  32.   def WaitTillGettext (arg1: String, arg2: String) {
  33.     new WebDriverWait(driver, 100).until(new ExpectedCondition[Boolean] {
  34.       override def apply(d: WebDriver) = d.findElement(By.xpath(arg1)).getText == arg2
  35.     })
  36.   }
  37.  
  38.   def WaitAndRefresh(arg1: String, arg2: String){
  39.     System.out.println("before wait")
  40.     new WebDriverWait(driver, 30).until(new ExpectedCondition[Unit]{
  41.       //try the following cycle for 30 seconds
  42.       @Override
  43.       override def apply(d: WebDriver){
  44.       //refresh the page
  45.         d.navigate().refresh()
  46.         System.out.println("Refreshed")
  47.         //look for element for 5 seconds
  48.         new WebDriverWait(driver, 5).until(new ExpectedCondition[Unit]{
  49.             @Override
  50.             override def apply(d: WebDriver) {
  51.               System.out.println("Looking for the element")
  52.               d.findElement(By.xpath(arg1)).getText == arg2
  53.             }
  54.         })
  55.       }
  56.     })
  57.     System.out.println("Done")
  58.   }
  59.  /*
  60.   def WaitAndRefresh(arg1: String){
  61.     System.out.println("before wait")
  62.     new WebDriverWait(driver, 30).until(new ExpectedCondition[Unit]{
  63.       //try the following cycle for 30 seconds
  64.       @Override
  65.       override def apply(d: WebDriver){
  66.         //refresh the page
  67.         System.out.println("Looking for the element")
  68.         d.findElement(By.xpath(arg1)).isDisplayed
  69.         //look for element for 5 seconds
  70.         new WebDriverWait(driver, 5).until(new ExpectedCondition[Unit]{
  71.           @Override
  72.           override def apply(d: WebDriver) {
  73.             d.navigate().refresh()
  74.             System.out.println("Refreshed")
  75.           }
  76.         })
  77.       }
  78.     })
  79.     System.out.println("Done")
  80.   }
  81.   */
  82.  
  83.   def PressNotification()    {
  84.     WaitTillToBeClickable("//div[@class='info__text']")
  85.     WaitTillDisplayed("//div[@class='info__text']")
  86.     js.executeScript("arguments[0].click();", driver.findElement(By.xpath("//div[@class='info__text']")))
  87.   }
  88.  
  89.   override def afterAll{
  90.     Thread.sleep(1000)
  91.     driver.quit
  92.   }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement