Search in sources :

Example 1 with WaitException

use of ru.sbtqa.tag.pagefactory.exceptions.WaitException in project page-factory-2 by sbtqa.

the class WebExtension method waitForTextPresenceInPageSource.

/**
 * Wait until specified text either appears, or disappears from page source
 *
 * @param text                text to search in page source
 * @param shouldTextBePresent boolean, self explanatory
 * @throws ru.sbtqa.tag.pagefactory.exceptions.WaitException TODO
 */
public static void waitForTextPresenceInPageSource(String text, boolean shouldTextBePresent) throws WaitException {
    long timeoutTime = System.currentTimeMillis() + PageFactory.getTimeOut();
    WebElement body = waitUntilElementAppearsInDom(By.tagName("body"));
    while (timeoutTime > System.currentTimeMillis()) {
        sleep(1);
        if (body.getText().replaceAll("\\s+", "").contains(text.replaceAll("\\s+", "")) == shouldTextBePresent) {
            return;
        }
    }
    throw new WaitException("Timed out after '" + PageFactory.getTimeOutInSeconds() + "' seconds waiting for presence of '" + text + "' in page source");
}
Also used : WaitException(ru.sbtqa.tag.pagefactory.exceptions.WaitException) WebElement(org.openqa.selenium.WebElement)

Example 2 with WaitException

use of ru.sbtqa.tag.pagefactory.exceptions.WaitException in project page-factory-2 by sbtqa.

the class WebWait method waitForTextPresenceInPageSource.

/**
 * Wait until specified text either appears, or disappears from page source
 *
 * @param text text to search in page source
 * @param shouldTextBePresent boolean, self explanatory
 * @throws WaitException in case if text didn't load in the page source
 */
public static void waitForTextPresenceInPageSource(String text, boolean shouldTextBePresent) throws WaitException, InterruptedException {
    long timeoutTime = System.currentTimeMillis() + PROPERTIES.getTimeout() * 1000L;
    Wait.presence(By.tagName("body"), "Element \"body\" did not appear after timeout");
    while (timeoutTime > System.currentTimeMillis()) {
        WebElement body = Environment.getDriverService().getDriver().findElement(By.tagName("body"));
        if (body.getText().replaceAll("\\s+", "").contains(text.replaceAll("\\s+", "")) == shouldTextBePresent) {
            return;
        }
        Thread.sleep(1000);
    }
    throw new WaitException("Timed out after '" + PROPERTIES.getTimeout() + "' seconds waiting for presence of '" + text + "' in page source");
}
Also used : WaitException(ru.sbtqa.tag.pagefactory.exceptions.WaitException) WebElement(org.openqa.selenium.WebElement)

Example 3 with WaitException

use of ru.sbtqa.tag.pagefactory.exceptions.WaitException in project page-factory-2 by sbtqa.

the class WebElementsPage method assertModalWindowAppears.

/**
 * Wait for a new browser window, then wait for a specific text inside the
 * appeared window List of previously opened windows is being saved before
 * each click, so if modal window appears without click, this method won't
 * catch it. Text is being waited by {@link #assertTextAppears}, so it will
 * be space-trimmed as well
 *
 * @param text text that will be searched inside of the window
 * @throws ru.sbtqa.tag.pagefactory.exceptions.WaitException if
 */
@ActionTitle("ru.sbtqa.tag.pagefactory.modal.window.with.text.appears")
public void assertModalWindowAppears(String text) throws WaitException {
    try {
        String popupHandle = WebExtension.findNewWindowHandle((Set<String>) Stash.getValue("beforeClickHandles"));
        if (null != popupHandle && !popupHandle.isEmpty()) {
            PageFactory.getWebDriver().switchTo().window(popupHandle);
        }
        assertTextAppears(text);
    } catch (Exception ex) {
        throw new WaitException("Modal window with text '" + text + "' didn't appear during timeout", ex);
    }
}
Also used : WaitException(ru.sbtqa.tag.pagefactory.exceptions.WaitException) PageException(ru.sbtqa.tag.pagefactory.exceptions.PageException) WaitException(ru.sbtqa.tag.pagefactory.exceptions.WaitException) ElementNotFoundException(ru.sbtqa.tag.pagefactory.exceptions.ElementNotFoundException) ActionTitle(ru.sbtqa.tag.pagefactory.annotations.ActionTitle)

Example 4 with WaitException

use of ru.sbtqa.tag.pagefactory.exceptions.WaitException in project page-factory-2 by sbtqa.

the class WebWait method waitForModalWindowWithText.

/**
 * Wait for a modal window with text to appear
 * @param text expected text in modal window
 * @throws WaitException in case if window was not found
 */
public static void waitForModalWindowWithText(String text) throws WaitException {
    try {
        String popupHandle = WindowHandles.findNewWindowHandle(Stash.getValue("beforeClickHandles"));
        if (null != popupHandle && !popupHandle.isEmpty()) {
            Environment.getDriverService().getDriver().switchTo().window(popupHandle);
        }
        waitForTextPresenceInPageSource(text, true);
    } catch (Exception ex) {
        throw new WaitException("Modal window with text '" + text + "' didn't appear during timeout", ex);
    }
}
Also used : WaitException(ru.sbtqa.tag.pagefactory.exceptions.WaitException) WaitException(ru.sbtqa.tag.pagefactory.exceptions.WaitException)

Aggregations

WaitException (ru.sbtqa.tag.pagefactory.exceptions.WaitException)4 WebElement (org.openqa.selenium.WebElement)2 ActionTitle (ru.sbtqa.tag.pagefactory.annotations.ActionTitle)1 ElementNotFoundException (ru.sbtqa.tag.pagefactory.exceptions.ElementNotFoundException)1 PageException (ru.sbtqa.tag.pagefactory.exceptions.PageException)1