Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BasePage {
- public WebDriver driver;
- private WebDriverWait jsWait;
- private static JavascriptExecutor jsExec;
- public BasePage() {
- this.driver = DataStoreManager.getWebDriver();
- PageFactory.initElements(driver, this);
- jsWait = new WebDriverWait(this.driver, 10);
- jsExec = (JavascriptExecutor) this.driver;
- }
- public WebDriver getDriver() {
- return this.driver;
- }
- public Object evaluateJavascript(String script, Object... params) {
- JavascriptExecutor js = (JavascriptExecutor) getDriver();
- return js.executeScript(script, params);
- }
- public FluentWait<WebDriver> getWait() {
- return new WebDriverWait(driver, 15L)
- .pollingEvery(Duration.ofMillis(500L))
- .ignoring(NoSuchElementException.class)
- .ignoring(NoSuchFrameException.class)
- .ignoring(StaleElementReferenceException.class)
- .ignoring(ElementNotInteractableException.class)
- .ignoring(InvalidElementStateException.class);
- }
- public void waitXseconds(long seconds) {
- int x = (int) (seconds + Integer.parseInt("000"));
- try {
- sleep(Integer.parseInt(seconds + "000"));
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- public void jsClick(WebElement element) {
- evaluateJavascript("arguments[0].click();", element);
- }
- public void jsFill(WebElement element, String value) {
- evaluateJavascript("arguments[0].value='" + value + "';", element);
- }
- public void waitForElementToBeVisible(WebElement element) {
- getWait().until(ExpectedConditions.visibilityOf(element));
- }
- public void scrollToElementAndWait(WebElement element) {
- waitForElementToBeVisible(element);
- evaluateJavascript("arguments[0].scrollIntoView(true);", element);
- }
- public static int randomIntGenerator(int low, int high) {
- SecureRandom random = new SecureRandom();
- return random.nextInt(high - low + 1) + low;
- }
- public static String randomStringGenerator(int stringLength) {
- return RandomStringUtils.randomAlphabetic(stringLength);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement