Search in sources :

Example 56 with TimeoutException

use of org.openqa.selenium.TimeoutException in project acceptance-test-harness by jenkinsci.

the class TSRPluginManager method installPlugins.

/**
 * Installs specified plugins.
 *
 * deprecated Please be encouraged to use {@link WithPlugins} annotations to statically declare
 * the required plugins you need. If you really do need to install plugins in the middle
 * of a test, as opposed to be in the beginning, then this is the right method.
 * <p/>
 * The deprecation marker is to call attention to {@link WithPlugins}. This method
 * is not really deprecated.
 */
@Deprecated
public void installPlugins(final String... specs) {
    final Map<String, String> candidates = getMapShortNamesVersion(specs);
    if (uploadPlugins) {
        for (PluginMetadata newPlugin : ucmd.get().transitiveDependenciesOf(candidates.keySet())) {
            final String name = newPlugin.name;
            final String claimedVersion = candidates.get(name);
            String currentSpec;
            if (StringUtils.isNotEmpty(claimedVersion)) {
                currentSpec = name + "@" + claimedVersion;
            } else {
                currentSpec = name;
            }
            if (!isInstalled(currentSpec)) {
                // we need to override existing "old" plugins
                try {
                    newPlugin.uploadTo(jenkins, injector, null);
                } catch (IOException | ArtifactResolutionException e) {
                    throw new AssertionError("Failed to upload plugin: " + newPlugin, e);
                }
            }
        }
        // TODO: Use better detection if this is actually necessary
        try {
            waitForCond(new Callable<Boolean>() {

                @Override
                public Boolean call() throws Exception {
                    return isInstalled(specs);
                }
            }, 5);
        } catch (TimeoutException e) {
            jenkins.restart();
        }
    } else {
        if (!updated)
            checkForUpdates();
        OUTER: for (final String n : candidates.keySet()) {
            for (int attempt = 0; attempt < 2; attempt++) {
                // # of installations attempted, considering retries
                visit("available");
                check(find(by.xpath("//input[starts-with(@name,'plugin.%s.')]", n)));
                clickButton("Install");
                sleep(1000);
                try {
                    new UpdateCenter(jenkins).waitForInstallationToComplete(n);
                } catch (InstallationFailedException e) {
                    if (e.getMessage().contains("Failed to download from")) {
                        // retry
                        continue;
                    }
                }
                // installation completed
                continue OUTER;
            }
        }
    }
}
Also used : InstallationFailedException(org.jenkinsci.test.acceptance.po.UpdateCenter.InstallationFailedException) IOException(java.io.IOException) IOException(java.io.IOException) TimeoutException(org.openqa.selenium.TimeoutException) InstallationFailedException(org.jenkinsci.test.acceptance.po.UpdateCenter.InstallationFailedException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) PluginMetadata(org.jenkinsci.test.acceptance.update_center.PluginMetadata) TimeoutException(org.openqa.selenium.TimeoutException)

Example 57 with TimeoutException

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

the class YandexTest method doLogout.

private void doLogout() {
    assertTrue(driver.getCurrentUrl().matches(".*#inbox"));
    // When I am logged on user
    WebElement element = driver.findElement(By.cssSelector("div.mail-App-Header div.mail-User div.mail-User-Name"));
    highlight(element);
    element.click();
    // And I am about to log off
    element = driver.findElement(By.cssSelector("body.mail-Page-Body div.ui-dialog div._nb-popup-content div.b-user-dropdown-content-with-exit div.b-mail-dropdown__item a.ns-action"));
    highlight(element);
    element.click();
    // to update the path, increase the sleep interval below
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
    }
    // And I confirm I am going to log off
    /*
		// auto-generated xpath: no longer correct, difficult to maintain
		element = driver.findElement(
				By.xpath("//div[5]/div[2]/table/tbody/tr/td/div[3]/div/a"));
		*/
    /*
		element = wait.until(ExpectedConditions.visibilityOf(driver
				.findElement(By.xpath("//table//a[@class='ns-action'][text()='Выйти на всех устройствах']"))));
		*/
    element = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//table//a[@class='ns-action' and contains(string(),'Выйти на всех устройствах')]"))));
    // Evaluate logout URL
    highlight(element);
    String logout_href = element.getAttribute("href");
    System.err.println("Logout href: " + element.getAttribute("href"));
    /*
		 * Logout href: https://passport.yandex.ru/passport?mode=embeddedauth&action=change_default&uid=419561298&yu=3540052471494536037&retpath=https%3A%2F%2Fpassport.yandex.ru%2Fpassport%3Fmode%3Dlogout%26global%3D1%26yu%3D3540052471494536037
		 */
    String retpath = null;
    Pattern pattern = Pattern.compile("https://passport.yandex.ru/passport?\\?mode=.+&retpath=(.+)$");
    Matcher matcher = pattern.matcher(logout_href);
    if (matcher.find()) {
        try {
            retpath = java.net.URLDecoder.decode(matcher.group(1).toString(), "UTF-8");
        } catch (UnsupportedEncodingException e) {
        // ignore
        }
    }
    System.err.println("Extracted Logout relpath: " + retpath);
    String currentUrl = driver.getCurrentUrl();
    element.click();
    try {
        wait.until(ExpectedConditions.not(ExpectedConditions.urlContains(currentUrl)));
    } catch (TimeoutException e) {
        verificationErrors.append(e.toString());
    }
    try {
        wait.until(ExpectedConditions.urlContains(finalUrl));
    } catch (TimeoutException e) {
    // TODO
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) UnsupportedEncodingException(java.io.UnsupportedEncodingException) WebElement(org.openqa.selenium.WebElement) TimeoutException(org.openqa.selenium.TimeoutException)

Example 58 with TimeoutException

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

the class YandexTest method useCookieTest.

// @Ignore
@Test
public void useCookieTest() throws Exception {
    String loginUrl = doLogin();
    System.err.println("Getting the cookies");
    Set<Cookie> cookies = driver.manage().getCookies();
    System.err.println("Closing the browser");
    wait = null;
    System.err.println("re-open the browser, about to use the session cookies");
    driver.close();
    driver = new FirefoxDriver();
    // re-initialize wait object
    wait = new WebDriverWait(driver, flexibleWait);
    wait.pollingEvery(polling, TimeUnit.MILLISECONDS);
    System.err.println("Navigating to " + loginUrl);
    driver.get(loginUrl);
    System.err.println("Loading cookies");
    for (Cookie cookie : cookies) {
        driver.manage().addCookie(cookie);
    }
    driver.navigate().refresh();
    System.err.println("Waiting for inbox");
    try {
        wait.until(ExpectedConditions.urlContains("#inbox"));
    } catch (TimeoutException | UnreachableBrowserException e) {
        verificationErrors.append(e.toString());
    }
    doLogout();
}
Also used : Cookie(org.openqa.selenium.Cookie) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) UnreachableBrowserException(org.openqa.selenium.remote.UnreachableBrowserException) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) TimeoutException(org.openqa.selenium.TimeoutException) Test(org.junit.Test)

Example 59 with TimeoutException

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

the class NgIgnoreSyncIntegrationTest method testNonAngularIgnoreSync.

// @Ignore
@Test
public void testNonAngularIgnoreSync() {
    if (isCIBuild) {
        return;
    }
    NgWebDriver ngDriver = new NgWebDriver(seleniumDriver, true);
    ngDriver.navigate().to("http://www.google.com");
    long startTime = System.currentTimeMillis();
    ngDriver.waitForAngular();
    long estimatedTime = System.currentTimeMillis() - startTime;
    System.err.println("waitForAngular: " + estimatedTime);
    NgWebElement element = ngDriver.findElement(By.cssSelector("input#gs_htif0"));
    try {
        element.getAttribute("id");
    } catch (TimeoutException exception) {
        fullStackTrace = org.apache.commons.lang.exception.ExceptionUtils.getFullStackTrace(exception);
        System.err.println("TimeoutException thrown: " + fullStackTrace);
        return;
    }
}
Also used : NgWebDriver(com.github.sergueik.jprotractor.NgWebDriver) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) TimeoutException(org.openqa.selenium.TimeoutException) Test(org.junit.Test)

Example 60 with TimeoutException

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

the class WebDriverActionExecutionBase method execute.

@Override
public void execute(TestScenario testScenario) throws InterruptedException, IOException, URISyntaxException {
    prepare();
    long elapsedTime = System.nanoTime();
    try {
        this.automationResult = AutomationResult.EXECUTING;
        while (testScenario.hasMoreSteps()) {
            if (ConfigurationUtils.toSeconds(System.nanoTime() - elapsedTime) > timeout) {
                this.automationResult = AutomationResult.TIMEOUT;
                throw new TimeoutException("Could not execute the action! Waited " + String.valueOf(System.nanoTime() - elapsedTime) + " to do " + testScenario.nextActionName() + " http queries in queue: " + httpRequestQueue.size());
            }
            if (httpRequestQueue.isEmpty() && !lock) {
                lock = testScenario.nextActionExpectsHttpRequest();
                WebDriverAction webDriverAction = testScenario.pollWebdriverAction();
                executeIgnoringExceptions(webDriverAction);
                waitingTimes.add(System.nanoTime() - elapsedTime);
                elapsedTime = System.nanoTime();
            }
        }
        this.automationResult = AutomationResult.SUCCESS;
    } catch (AssertionError e) {
        e.printStackTrace();
        this.automationResult = AutomationResult.ASSERTION_ERROR;
    } finally {
        replaySettings.cleanUpReplay();
    }
    this.loadingTimes = new LoadingTimes(waitingTimes, testScenario.getActions());
}
Also used : LoadingTimes(com.hribol.automation.core.utils.LoadingTimes) TimeoutException(org.openqa.selenium.TimeoutException) WebDriverAction(com.hribol.automation.core.actions.WebDriverAction)

Aggregations

TimeoutException (org.openqa.selenium.TimeoutException)72 WebElement (org.openqa.selenium.WebElement)37 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)30 NoSuchElementException (org.openqa.selenium.NoSuchElementException)23 Test (org.junit.Test)17 MessageEvent (org.cerberus.engine.entity.MessageEvent)16 By (org.openqa.selenium.By)15 WebDriverException (org.openqa.selenium.WebDriverException)13 IOException (java.io.IOException)10 AnswerItem (org.cerberus.util.answer.AnswerItem)10 WebDriver (org.openqa.selenium.WebDriver)10 BFElementNotFoundException (com.capgemini.ntc.selenium.core.exceptions.BFElementNotFoundException)6 Actions (org.openqa.selenium.interactions.Actions)5 ExpectedCondition (org.openqa.selenium.support.ui.ExpectedCondition)5 URISyntaxException (java.net.URISyntaxException)4 TimeUnit (java.util.concurrent.TimeUnit)3 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)3 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)3 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)3 NgWebElement (com.github.sergueik.jprotractor.NgWebElement)2