This repository has been archived by the owner on Dec 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
756b0ee
commit 9dbc8fe
Showing
3 changed files
with
60 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package test.elements; | ||
|
||
import org.openqa.selenium.*; | ||
import org.openqa.selenium.support.ui.ExpectedConditions; | ||
import org.openqa.selenium.support.ui.WebDriverWait; | ||
|
||
public class Element { | ||
private WebDriver driver; | ||
private By locator; | ||
|
||
public Element(WebDriver driver, By locator) { | ||
this.driver = driver; | ||
this.locator = locator; | ||
} | ||
|
||
public void click() { | ||
while (true) { | ||
try { | ||
driver.findElement(locator).click(); | ||
return; | ||
} catch (NoSuchElementException e) { | ||
waitForElement(locator); | ||
} catch (ElementNotInteractableException e) { | ||
waitForElementVisible(locator); | ||
} | ||
} | ||
} | ||
|
||
public void sendKeys(String string) { | ||
while (true) { | ||
try { | ||
driver.findElement(locator).sendKeys(string); | ||
return; | ||
} catch (NoSuchElementException e) { | ||
waitForElement(locator); | ||
} catch (ElementNotInteractableException e) { | ||
waitForElementVisible(locator); | ||
} | ||
} | ||
} | ||
|
||
private void waitForElement(By locator) { | ||
WebDriverWait wait = new WebDriverWait(driver, 30); | ||
wait.until(ExpectedConditions.presenceOfElementLocated(locator)); | ||
} | ||
|
||
private void waitForElementVisible(By locator) { | ||
WebDriverWait wait = new WebDriverWait(driver, 30); | ||
wait.until(ExpectedConditions.visibilityOfElementLocated(locator)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,12 @@ | ||
package test.pages; | ||
|
||
import test.elements.Element; | ||
import org.openqa.selenium.*; | ||
import org.openqa.selenium.support.ui.ExpectedConditions; | ||
import org.openqa.selenium.support.ui.WebDriverWait; | ||
|
||
class BasePage { | ||
WebDriver driver; | ||
class BasePage { | ||
WebDriver driver; | ||
|
||
void click(By locator) { | ||
while (true) { | ||
try { | ||
driver.findElement(locator).click(); | ||
return; | ||
} catch (NoSuchElementException e) { | ||
waitForElement(locator); | ||
} catch (ElementNotInteractableException e) { | ||
waitForElementVisible(locator); | ||
} | ||
Element getElement(By locator) { | ||
return new Element(driver, locator); | ||
} | ||
} | ||
|
||
private void waitForElement(By locator) { | ||
WebDriverWait wait = new WebDriverWait(driver, 30); | ||
wait.until(ExpectedConditions.presenceOfElementLocated(locator)); | ||
} | ||
|
||
private void waitForElementVisible(By locator) { | ||
WebDriverWait wait = new WebDriverWait(driver, 30); | ||
wait.until(ExpectedConditions.visibilityOfElementLocated(locator)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters