Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileInputStream
- import java.util.Properties
- import org.openqa.selenium.chrome.ChromeDriver
- import org.openqa.selenium.interactions.Actions
- import org.openqa.selenium.support.ui.{ExpectedCondition, ExpectedConditions, WebDriverWait}
- import org.openqa.selenium.{By, JavascriptExecutor, WebDriver}
- import org.scalatest.{BeforeAndAfterAll, FunSuite}
- abstract class TestBase extends FunSuite with BeforeAndAfterAll {
- implicit var driver: WebDriver = null
- val prop = new Properties()
- prop.load(new FileInputStream(".cfg\\website-tests.cfg"))
- // val allProfiles = new ProfilesIni()
- System.setProperty("webdriver.chrome.driver", prop.getProperty("chromedriver_path"))
- driver = new ChromeDriver()
- val js = driver.asInstanceOf[JavascriptExecutor]
- val builder = new Actions(driver)
- def WaitTillDisplayed (arg: String) {
- new WebDriverWait(driver, 100).until(new ExpectedCondition[Boolean] {
- override def apply(d: WebDriver) = d.findElement(By.xpath(arg)).isDisplayed()
- })
- }
- def WaitTillToBeClickable(arg: String) {
- WaitTillDisplayed(arg)
- new WebDriverWait(driver, 100).until(ExpectedConditions.elementToBeClickable(By.xpath(arg)))
- }
- def WaitTillGettext (arg1: String, arg2: String) {
- new WebDriverWait(driver, 100).until(new ExpectedCondition[Boolean] {
- override def apply(d: WebDriver) = d.findElement(By.xpath(arg1)).getText == arg2
- })
- }
- def WaitAndRefresh(arg1: String, arg2: String){
- System.out.println("before wait")
- new WebDriverWait(driver, 30).until(new ExpectedCondition[Unit]{
- //try the following cycle for 30 seconds
- @Override
- override def apply(d: WebDriver){
- //refresh the page
- d.navigate().refresh()
- System.out.println("Refreshed")
- //look for element for 5 seconds
- new WebDriverWait(driver, 5).until(new ExpectedCondition[Unit]{
- @Override
- override def apply(d: WebDriver) {
- System.out.println("Looking for the element")
- d.findElement(By.xpath(arg1)).getText == arg2
- }
- })
- }
- })
- System.out.println("Done")
- }
- /*
- def WaitAndRefresh(arg1: String){
- System.out.println("before wait")
- new WebDriverWait(driver, 30).until(new ExpectedCondition[Unit]{
- //try the following cycle for 30 seconds
- @Override
- override def apply(d: WebDriver){
- //refresh the page
- System.out.println("Looking for the element")
- d.findElement(By.xpath(arg1)).isDisplayed
- //look for element for 5 seconds
- new WebDriverWait(driver, 5).until(new ExpectedCondition[Unit]{
- @Override
- override def apply(d: WebDriver) {
- d.navigate().refresh()
- System.out.println("Refreshed")
- }
- })
- }
- })
- System.out.println("Done")
- }
- */
- def PressNotification() {
- WaitTillToBeClickable("//div[@class='info__text']")
- WaitTillDisplayed("//div[@class='info__text']")
- js.executeScript("arguments[0].click();", driver.findElement(By.xpath("//div[@class='info__text']")))
- }
- override def afterAll{
- Thread.sleep(1000)
- driver.quit
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement