Search in sources :

Example 96 with TimeoutException

use of org.openqa.selenium.TimeoutException in project selenium_tests by sergueik.

the class DynamicPageExpectedConditionTest method test2.

@Test(enabled = true)
public void test2() {
    driver.navigate().to(baseURL);
    try {
        // NOTE: generic not returned the expected data - fix needed. For now just read
        // again
        elements = wait.until(new ExpectedCondition<List<WebElement>>() {

            @Override
            public List<WebElement> apply(WebDriver d) {
                List<WebElement> elements = d.findElements(by);
                if (debug)
                    System.err.println("Awaiting for " + min_count + " , got " + elements.size() + " elements");
                int cnt = elements.size() > min_count ? min_count : elements.size() - 1;
                WebElement element = elements.get(cnt);
                if (debug)
                    System.err.println(String.format("Moving to %d element: %s", cnt, element.getText()));
                highlight(element);
                actions.moveToElement(element).build().perform();
                // scroll page down a bit more -
                // eventually leads to more elements to be
                // displayed
                element.sendKeys(Keys.DOWN);
                return (elements.size() >= min_count) ? elements : null;
            }
        });
    } catch (TimeoutException e) {
    }
    System.err.println("Got from wait: " + elements.size() + " elements");
    assertThat(elements.size(), greaterThan(min_count - 1));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) WebElement(org.openqa.selenium.WebElement) TimeoutException(org.openqa.selenium.TimeoutException) Test(org.testng.annotations.Test)

Example 97 with TimeoutException

use of org.openqa.selenium.TimeoutException in project selenium_tests by sergueik.

the class TenminemailTest method getNewRandomEmailTest.

// 
@Test(enabled = true)
public void getNewRandomEmailTest() {
    // Arrange
    WebElement buttonElement;
    try {
        buttonElement = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='click-to-delete']")));
        // by By.xpath: //*[@id=?click-to-delete?]
        if (buttonElement != null) {
            actions.moveToElement(buttonElement).build().perform();
            buttonElement.click();
            sleep(1000);
        }
    } catch (TimeoutException e) {
        System.err.println("Exception (aborting) " + e.toString());
        return;
    }
    WebElement emailInputElement = driver.findElement(By.cssSelector(cssSelector));
    System.err.println("Input element: " + emailInputElement.getAttribute("outerHTML"));
    String text = (String) executeScript(String.format("var element=document.querySelector('%s');" + "var elementText=" + "element.getAttribute('value').replace(/\\n/, ' ')" + "||" + "element.textContent.replace(/\\n/, ' ')" + "||" + "element.innerText.replace(/\\n/, ' ')" + "||" + "element.getAttribute('placeholder')" + "||" + "'';" + "return elementText;", cssSelector));
    System.err.println("input#mail text: " + text);
    assertThat(text, is(""));
    // stale element reference is possible
    emailInputElement.click();
    System.err.println("Clicked input");
    // sleep(1000);
    text = (String) executeScript("return window.getSelection().toString()");
    assertThat(text, notNullValue());
    // not empty
    System.err.println("Selection text email (try 1): " + text);
    text = (String) executeScript("function getSelectionText() { " + "var text = '';" + "if (window.getSelection) {" + "    text = window.getSelection().toString();" + " } else if (document.selection && document.selection.type != 'Control') {" + "     text = document.selection.createRange().text;" + "  }" + "   return text;" + "};return getSelectionText();");
    assertThat(text, notNullValue());
    // not empty
    System.err.println("Selection text email (try 2): " + text);
    text = getSelectionText();
    System.err.println("Selection text email (try 3): " + text);
    // non-empty, but still looking for triggering stale element reference
    text = (String) executeScript(getScriptContent("getText.js"), driver.findElement(By.cssSelector(cssSelector)), false);
    // innerText of input DOM element type is empty
    assertThat(text, is(""));
    System.err.println("Input text (try 1) : " + text);
    System.err.println("Input value (try 1): " + driver.findElement(By.cssSelector(cssSelector)).getAttribute("value"));
    text = (String) executeScript(String.format("var element=document.querySelectorAll('%s')[0];" + "var elementText=" + "element.value.replace(/\\n/, ' ')" + "||" + "element.textContent.replace(/\\n/, ' ')" + "||" + "element.innerText.replace(/\\n/, ' ')" + "||" + "element.getAttribute('placeholder')" + "||" + "'';" + "return elementText;", cssSelector));
    // empty
    System.err.println("Text or value (try 1) : " + text);
    @SuppressWarnings("unchecked") Map<String, Object> // value]
    attributes = (Map<String, Object>) executeScript(getScriptContent("getAttributes.js"), driver.findElement(By.cssSelector(cssSelector)));
    System.err.println("Attributes: ");
    for (Entry<String, Object> entry : attributes.entrySet()) {
        System.err.println(String.format("%s = \"%s\"", entry.getKey(), entry.getValue().toString()));
    }
    System.err.println("Input value (try 2): " + attributes.get("value"));
    try {
        highlight(emailInputElement);
    } catch (StaleElementReferenceException e) {
        System.err.println("Exception (ignored) " + e.toString());
    }
}
Also used : StaleElementReferenceException(org.openqa.selenium.StaleElementReferenceException) WebElement(org.openqa.selenium.WebElement) Map(java.util.Map) TimeoutException(org.openqa.selenium.TimeoutException) Test(org.testng.annotations.Test) BaseTest(com.github.sergueik.selenium.BaseTest)

Example 98 with TimeoutException

use of org.openqa.selenium.TimeoutException in project selenium_tests by sergueik.

the class ServiziCookieTest method pureCookieTest.

@Test(enabled = false, priority = 2)
public void pureCookieTest() throws Exception {
    driver.get(baseURL);
    System.err.println("Generating cookies: " + cookieNames);
    for (String cookieName : cookieNames) {
        String cookieData = extractData(usernome, cookieName);
        deserializeData(cookieData, Optional.of(cookieDataMap));
        Date now = new Date();
        long t = now.getTime();
        t += 7 * 24 * 60 * 60 * 1000;
        Date futureDate = new Date(t);
        cookieDataMap.put("expiry", futureDate);
        System.err.println("Constructing cookie: " + cookieName + "\n" + cookieDataMap);
        Cookie cookie = new Cookie(cookieDataMap.get("name").toString(), cookieDataMap.get("value").toString(), cookieDataMap.get("domain").toString(), cookieDataMap.get("path").toString(), (java.util.Date) cookieDataMap.get("expiry"), Boolean.parseBoolean(cookieDataMap.get("secure").toString()), Boolean.parseBoolean(cookieDataMap.get("httpOnly").toString()));
        driver.manage().addCookie(cookie);
    }
    // org.openqa.selenium.InvalidCookieDomainException:
    driver.get(landURL);
    driver.navigate().refresh();
    if (debug) {
        Set<Cookie> cookies = driver.manage().getCookies();
        for (Cookie cookie : cookies) {
            System.err.println(formatter.format("Name: '%s'\n", cookie.getName()).toString() + formatter.format("Value: '%s'\n", cookie.getValue()).toString() + formatter.format("Domain: '%s'\n", cookie.getDomain()).toString() + formatter.format("Path: '%s'\n", cookie.getPath()).toString() + formatter.format("Expiry: '%tc'\n", cookie.getExpiry()).toString() + formatter.format("Secure: '%b'\n", cookie.isSecure()) + formatter.format("HttpOnly: '%b'\n", cookie.isHttpOnly()));
        }
    }
    sleep(10000);
    // TODO: handle refreshes with Caution. As the 'Click Day' time approaches,
    // reload the page continuously
    // until the transmission button is active.
    // To refresh the page press F5.
    /*
		System.err.println("Waiting for inbox");
		try {
			wait.until(ExpectedConditions.urlContains("#inbox"));
		} catch (TimeoutException | UnreachableBrowserException e) {
			verificationErrors.append(e.toString());
		}
		*/
    int cnt = 0;
    while (cnt < 10) {
        // pencil button
        WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[contains(@id,'btnCompleta')][@title='Modifica']")));
        System.err.println("Pencil button:\n" + element.getAttribute("outerHTML"));
        highlight(element);
        element.click();
        // navigates to
        // http://bandi.servizi.politicheagricole.it/taxcredit/moduloTCR.aspx?ID=331
        List<WebElement> elements = driver.findElements(By.xpath("//*[contains(@id,'msgClickDay')]"));
        if (elements.size() > 0) {
            System.err.println(elements.get(0).getText());
            System.err.println("Waiting for F5 warning to disappear");
            driver.navigate().refresh();
            sleep(1000);
            cnt = cnt + 1;
        }
    }
    /*
		WebElement element = wait
				.until(ExpectedConditions.visibilityOfElementLocated(
						By.xpath("//*[contains(@id,'msgClickDay')]")));
						*/
    try {
        // check if we can user stock methods or write own ?
        wait.until(ExpectedConditions.invisibilityOfElementWithText(By.xpath("//*[contains(@id,'msgClickDay')]"), "Per aggiornare la pagina premere F5"));
    } catch (TimeoutException | UnreachableBrowserException e) {
        verificationErrors.append(e.toString());
    }
    sleep(1000);
    doLogout();
}
Also used : Cookie(org.openqa.selenium.Cookie) UnreachableBrowserException(org.openqa.selenium.remote.UnreachableBrowserException) WebElement(org.openqa.selenium.WebElement) Date(java.util.Date) TimeoutException(org.openqa.selenium.TimeoutException) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 99 with TimeoutException

use of org.openqa.selenium.TimeoutException in project selenium_cdp by sergueik.

the class ChromeDevToolsTest method broserGetWindowBoundsTest.

@Test
public // https://chromedevtools.github.io/devtools-protocol/tot/Browser#method-getWindowForTarget
void broserGetWindowBoundsTest() {
    GetWindowForTargetResponse response = chromeDevTools.send(Browser.getWindowForTarget(Optional.empty()));
    WindowID windowId = response.getWindowId();
    Bounds bounds = response.getBounds();
    System.err.println(String.format("Method Browser.getWindowForTarget result: windowId: %d" + "\nBounds: top: %d, left: %d, width: %d, height: %d", Long.parseLong(windowId.toString()), bounds.getLeft().get(), bounds.getTop().get(), bounds.getWidth().get(), bounds.getHeight().get()));
    @SuppressWarnings("unused") Optional<WindowID> windowIdArg = Optional.of(windowId);
    try {
        bounds = chromeDevTools.send(Browser.getWindowBounds(windowId));
        chromeDevTools.createSessionIfThereIsNotOne();
        @SuppressWarnings("unused") SessionID id = chromeDevTools.getCdpSession();
    } catch (TimeoutException e) {
        System.err.println("Exception (ignored): " + e.toString());
        bounds = null;
    }
    // https://github.com/SeleniumHQ/selenium/issues/7369
    chromeDevTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty()));
    // https://github.com/SeleniumHQ/selenium/blob/master/java/client/src/org/openqa/selenium/devtools/DevTools.java
    // https://github.com/SeleniumHQ/selenium/blob/master/java/client/test/org/openqa/selenium/devtools/ChromeDevToolsNetworkTest.java
    // but Browser has no events, Network has
    chromeDevTools.addListener(Network.dataReceived(), o -> {
        Assert.assertNotNull(o.getRequestId());
        // TODO: Command<GetResponseBodyResponse> - get something practical
        System.err.println("Response body: " + Network.getResponseBody(o.getRequestId()).getMethod());
    });
    driver.get("https://apache.org");
    if (bounds != null) {
        System.err.print(String.format("Method Browser.getWindowBounds(%d): ", Long.parseLong(windowId.toString())));
        if (bounds.getTop().isPresent()) {
            System.err.println(String.format("top: %d, left: %d, width: %d, height: %d", bounds.getTop().get(), bounds.getLeft().get(), bounds.getWidth().get(), bounds.getHeight().get()));
        } else {
            System.err.println("undefined");
        }
    } else {
        System.err.println("Method Browser.getWindowBounds failed");
    }
}
Also used : WindowID(org.openqa.selenium.devtools.v100.browser.model.WindowID) Bounds(org.openqa.selenium.devtools.v100.browser.model.Bounds) GetWindowForTargetResponse(org.openqa.selenium.devtools.v100.browser.Browser.GetWindowForTargetResponse) SessionID(org.openqa.selenium.devtools.idealized.target.model.SessionID) TimeoutException(org.openqa.selenium.TimeoutException) Test(org.junit.Test)

Example 100 with TimeoutException

use of org.openqa.selenium.TimeoutException in project kie-wb-distributions by kiegroup.

the class ProjectLibraryPerspective method possiblyOverrideGavConflict.

private void possiblyOverrideGavConflict() {
    try {
        ConflictingRepositoriesModal modal = ConflictingRepositoriesModal.newInstance();
        modal.overrideArtifactInMavenRepo();
    } catch (TimeoutException | NoSuchElementException ignored) {
        LOG.info("Modal showing GAV conflict didn't appear");
    }
}
Also used : ConflictingRepositoriesModal(org.kie.wb.selenium.model.persps.authoring.ConflictingRepositoriesModal) NoSuchElementException(org.openqa.selenium.NoSuchElementException) TimeoutException(org.openqa.selenium.TimeoutException)

Aggregations

TimeoutException (org.openqa.selenium.TimeoutException)247 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)109 WebElement (org.openqa.selenium.WebElement)85 NoSuchElementException (org.openqa.selenium.NoSuchElementException)52 ExpectedCondition (org.openqa.selenium.support.ui.ExpectedCondition)40 WebDriver (org.openqa.selenium.WebDriver)39 WebDriverException (org.openqa.selenium.WebDriverException)39 AutomatorException (com.testsigma.automator.exceptions.AutomatorException)31 MessageEvent (org.cerberus.engine.entity.MessageEvent)27 ExpectedConditions (org.openqa.selenium.support.ui.ExpectedConditions)27 Reporter (com.coveros.selenified.utilities.Reporter)26 Test (org.junit.Test)25 By (org.openqa.selenium.By)22 Test (org.testng.annotations.Test)20 Element (com.coveros.selenified.element.Element)17 AnswerItem (org.cerberus.util.answer.AnswerItem)17 IOException (java.io.IOException)16 Dimension (org.openqa.selenium.Dimension)14 Point (org.openqa.selenium.Point)14 Constants (com.coveros.selenified.utilities.Constants)13