public RequestGuardFactory(RequestGuard guard, Document document, GrapheneContext context) { this.guard = guard; this.document = document; this.context = context; this.waitGuard = waitAjax() .withTimeout(context.getConfiguration().getWaitGuardInterval(), TimeUnit.SECONDS) .pollingEvery(Math.min(context.getConfiguration().getWaitGuardInterval() * 100, 200), TimeUnit.MILLISECONDS); }
public RequestGuardFactory(RequestGuard guard, Document document, GrapheneContext context) { this.guard = guard; this.document = document; this.context = context; this.waitGuard = waitAjax() .withTimeout(context.getConfiguration().getWaitGuardInterval(), TimeUnit.SECONDS) .pollingEvery(Math.min(context.getConfiguration().getWaitGuardInterval() * 100, 200), TimeUnit.MILLISECONDS); }
@Test public void testWithTimeout() { TimeUnit unit = TimeUnit.MILLISECONDS; long duration = 2000; long started = System.currentTimeMillis(); try { Graphene.waitModel() .withTimeout(duration, unit) .until() .element(BY_HEADER) .text() .equalTo("sjkldhkdjfgjlkfg"); Assert.fail(TimeoutException.class.getName() + " should be thrown."); } catch(TimeoutException e) { long was = System.currentTimeMillis() - started; Assert.assertTrue("The waiting time shouldn't be much bigger than " + duration + " " + unit + ", but was " + was + " ms.", was < unit.toMillis(duration + duration / 2)); Assert.assertTrue("The waiting time shouldn't lower than " + duration + " " + unit + ", but was " + was + " ms.", was >= unit.toMillis(duration)); } }
@Override public boolean addFile(File file) { final int expectedSize = advanced().getFileInputElements().size() + 1; String containerStyleClassBefore = advanced().getInputContainer().getAttribute("class"); Utils.jQ("attr('class', '')", advanced().getInputContainer()); if (browser instanceof PhantomJSDriver) { // workaround for PhantomJS where usual upload does not work ((PhantomJSDriver) browser).executePhantomJS("var page = this; page.uploadFile('input[type=file]', '" + file.getAbsolutePath() + "');"); } else { // for all other browsers advanced().getFileInputElement().sendKeys(file.getAbsolutePath()); } Utils.jQ("attr('class', '" + containerStyleClassBefore + "')", advanced().getInputContainer()); try { Graphene.waitGui().withTimeout(1, TimeUnit.SECONDS).until(new Predicate<WebDriver>() { @Override public boolean apply(WebDriver input) { return advanced().getFileInputElements().size() == expectedSize; } }); } catch (TimeoutException ignored) { return FALSE; } return TRUE; }
@Test @RunAsClient @InSequence(20) public void testTimeout(@ArquillianResource URL url) throws Exception { // 1. Create our test with a unique channel id. final String channelId = "" + System.currentTimeMillis(); // Set timeout for 1 minute. String params = String.format("/channelPage.jsp?test-channel-id=%s&timeout-minutes=%d", channelId, 1); driver.get(url + params); // 2. Verify that the server received our channel id and is using it for this tests. WebElement channel = driver.findElement(By.id("channel-id")); assertEquals(channelId, channel.getText()); // 3. Verify that the channel gets closed after the 1 minute timeout. Graphene.waitModel(driver).until().element(By.id("status")).text().equalTo("opened"); // This should put us over the 1 minute timeout. Graphene.waitModel(driver).withTimeout(90, TimeUnit.SECONDS).until().element(By.id("status")).text().equalTo("closed"); } }
Graphene.waitModel(driver).withTimeout(5, TimeUnit.SECONDS).until().element(button).is().enabled(); button.click(); } catch (NoSuchElementException e) {