Example usage for org.openqa.selenium WebDriver navigate

List of usage examples for org.openqa.selenium WebDriver navigate

Introduction

In this page you can find the example usage for org.openqa.selenium WebDriver navigate.

Prototype

Navigation navigate();

Source Link

Document

An abstraction allowing the driver to access the browser's history and to navigate to a given URL.

Usage

From source file:org.eclipse.skalli.selenium.utils.DriverProvider.java

License:Open Source License

/**
 * Navigates to the base url ({@link #getHTTPBaseUrl()})
 * @param driver The driver// w  w  w. j av a2  s. c  o m
 */
public static void navigateToBaseUrl(WebDriver driver) {
    driver.navigate().to(getHTTPBaseUrl());
}

From source file:org.eclipse.skalli.selenium.utils.DriverProvider.java

License:Open Source License

/**
 * Navigates to "{@link #getHTTPBaseUrl()} + {@code subUrl}"
 * @param driver The driver//from w  w w.j a  v a  2  s. c  o  m
 * @param subUrl The sub url
 */
public static void navigateToSubUrl(WebDriver driver, String subUrl) {
    driver.navigate().to(getHTTPBaseUrl() + subUrl);
}

From source file:org.ehoffman.testing.sample.WebDriverFactory.java

License:Apache License

/**
 * Returns a {@link WebDriver} instance built to the input specifications.
 * //from   w w w.j a  va  2s . c  o m
 * @param type the type of {@link WebDriver}.
 * @return a {@link WebDriver} instance ready for use.
 */
public WebDriver buildWebdriver(final Driver type, final String url) {
    WebDriver driver = null;
    switch (type) {
    case CHROME:
        driver = new ChromeDriver();
        break;
    case FIREFOX:
        driver = new FirefoxDriver();
        break;
    case PHANTOMJS:
    default:
        driver = new PhantomJSDriver();
        break;
    }
    driver.manage().timeouts().implicitlyWait(0, TimeUnit.NANOSECONDS);
    driver.navigate().to(url);
    return driver;
}

From source file:org.jboss.arquillian.graphene.context.TestGrapheneContextProxying.java

License:Open Source License

@Test
public void when_proxy_returns_webdriver_api_then_another_proxy_is_returned_wrapping_the_result_of_invocation() {
    // having//from  ww w . j  a  va2s.c  om
    Navigation navigation = mock(Navigation.class);

    // when
    GrapheneContext.set(driver);
    when(driver.navigate()).thenReturn(navigation);

    // then
    WebDriver driverProxy = GrapheneContext.getProxy();
    Navigation navigationProxy = driverProxy.navigate();
    assertTrue(navigationProxy instanceof GrapheneProxyInstance);

    // verify
    verify(driver, only()).navigate();
}

From source file:org.jboss.arquillian.graphene.context.TestGrapheneProxyHandler.java

License:Open Source License

@Test
public void test_webDriver_methods_which_should_return_proxy() {
    IsProxyable isProxyable = new IsProxyable();

    // when//from   ww w  .j a  va  2 s.  c  o m
    WebDriver driver = Mockito.mock(WebDriver.class, isProxyable);
    Options options = mock(Options.class, isProxyable);
    TargetLocator targetLocator = mock(TargetLocator.class, isProxyable);
    ImeHandler ime = mock(ImeHandler.class, isProxyable);
    Timeouts timeouts = mock(Timeouts.class, isProxyable);

    // then
    try {
        driver.manage();
        driver.navigate();
        driver.switchTo();
        driver.findElement(By.className(""));
        driver.findElements(By.className(""));
        driver.getWindowHandles();

        options.ime();
        options.logs();
        options.timeouts();
        options.window();
        options.getCookies();

        targetLocator.activeElement();
        targetLocator.alert();
        targetLocator.defaultContent();
        targetLocator.frame(0);
        targetLocator.frame("name");
        targetLocator.frame(mock(WebElement.class));
        targetLocator.window("name");

        ime.getAvailableEngines();

        timeouts.implicitlyWait(1L, TimeUnit.MICROSECONDS);
        timeouts.setScriptTimeout(1L, TimeUnit.MICROSECONDS);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    assertEquals(Arrays.asList(), isProxyable.getViolations());
}

From source file:org.jboss.arquillian.warp.extension.phaser.ftest.BasicPhaserTest.java

License:Apache License

@Test
@RunAsClient//from   w w  w  . j a  v a  2s.com
public void test() {
    Warp.execute(new ClientAction() {

        @Override
        public void action() {
            browser.navigate().to(contextPath + "index.jsf");
        }
    }).verify(new InitialRequestVerification());

    NameChangedToX x = Warp.filter(new JsfRequestFilter()).execute(new ClientAction() {
        public void action() {
            WebElement nameInput = browser.findElement(By.id("helloWorldJsf:nameInput"));
            nameInput.sendKeys("X");

            new WebDriverWait(browser, 5).until(new Predicate<WebDriver>() {
                @Override
                public boolean apply(WebDriver browser) {
                    WebElement output = browser.findElement(By.id("helloWorldJsf:output"));
                    try {
                        return output.getText().contains("JohnX");
                    } catch (StaleElementReferenceException e) {
                        return false;
                    }
                }
            });
        }
    }).verify(new NameChangedToX());

    // verify Object was Deserialized with Server state
    assertEquals("JohnX", x.getUpdatedName());
}

From source file:org.jboss.arquillian.warp.extension.phaser.ftest.lifecycle.TestPhaserLifecycle.java

License:Apache License

@Test
@RunAsClient//from   w  w  w. j ava 2  s  .  c om
public void test() {
    ExecuteAllPhases executed = Warp.execute(new ClientAction() {
        public void action() {
            browser.navigate().to(contextPath + "index.jsf");
        }
    }).verify(new ExecuteAllPhases());

    assertFalse(executed.isPostback());
    verifyExecutedPhases(executed);

    executed = Warp.execute(new ClientAction() {
        public void action() {
            WebElement nameInput = browser.findElement(By.id("helloWorldJsf:nameInput"));
            nameInput.sendKeys("X");

            new WebDriverWait(browser, 5).until(new Predicate<WebDriver>() {
                @Override
                public boolean apply(WebDriver browser) {
                    WebElement output = browser.findElement(By.id("helloWorldJsf:output"));
                    try {
                        return output.getText().contains("JohnX");
                    } catch (StaleElementReferenceException e) {
                        return false;
                    }
                }
            });
        }
    }).verify(new ExecuteAllPhases());

    assertTrue(executed.isPostback());
    verifyExecutedPhases(executed);
}

From source file:org.jboss.arquillian.warp.jsf.ftest.BasicJsfTest.java

License:Apache License

@Test
public void test() {
    Warp.initiate(new Activity() {
        public void perform() {
            browser.navigate().to(contextPath + "index.jsf");
        }/*from   www. jav a2  s  . c  o  m*/
    }).inspect(new Inspection() {
        private static final long serialVersionUID = 1L;

        @Inject
        CdiBean myBean;

        @AfterPhase(RENDER_RESPONSE)
        public void initial_state_havent_changed_yet() {
            assertEquals("John", myBean.getName());
        }
    });

    Warp.initiate(new Activity() {
        public void perform() {
            WebElement nameInput = browser.findElement(By.id("helloWorldJsf:nameInput"));
            nameInput.sendKeys("X");
            browser.findElement(By.tagName("body")).click();
        }
    }).inspect(new Inspection() {
        private static final long serialVersionUID = 1L;

        @Inject
        CdiBean myBean;

        private String updatedName;

        @BeforePhase(UPDATE_MODEL_VALUES)
        public void initial_state_havent_changed_yet() {
            assertEquals("John", myBean.getName());
        }

        @AfterPhase(UPDATE_MODEL_VALUES)
        public void changed_input_value_has_been_applied() {
            assertEquals("JohnX", myBean.getName());
            updatedName = myBean.getName();
        }

        public String getUpdatedName() {
            return updatedName;
        }
    });

    new WebDriverWait(browser, 5).until(new Predicate<WebDriver>() {
        @Override
        public boolean apply(WebDriver browser) {
            WebElement output = browser.findElement(By.id("helloWorldJsf:output"));
            try {
                return output.getText().contains("JohnX");
            } catch (StaleElementReferenceException e) {
                return false;
            }
        }
    });
}

From source file:org.jboss.arquillian.warp.jsf.ftest.lifecycle.TestJsfLifecycle.java

License:Apache License

@Test
public void test() {

    Warp.initiate(new Activity() {
        public void perform() {
            browser.navigate().to(contextPath + "index.jsf");
        }// w  ww . ja va2 s  . co  m
    }).inspect(new Inspection() {
        private static final long serialVersionUID = 1L;

        @BeforeServlet
        public void beforeServlet() {
        }

        @BeforePhase(Phase.RESTORE_VIEW)
        public void beforeRestoreView() {
        }

        @AfterPhase(Phase.RESTORE_VIEW)
        public void afterRestoreView() {
        }

        @BeforePhase(Phase.RENDER_RESPONSE)
        public void beforeRenderResponse() {
        }

        @AfterPhase(Phase.RENDER_RESPONSE)
        public void afterRenderResponse() {
        }
    });

    Warp.initiate(new Activity() {
        public void perform() {
            WebElement nameInput = browser.findElement(By.id("helloWorldJsf:nameInput"));
            nameInput.sendKeys("X");
            browser.findElement(By.tagName("body")).click();
        }
    }).inspect(new Inspection() {
        private static final long serialVersionUID = 1L;

        @BeforePhase(Phase.RESTORE_VIEW)
        public void beforeRestoreView() {
        }

        @AfterPhase(Phase.RESTORE_VIEW)
        public void afterRestoreView() {
        }

        @BeforePhase(Phase.APPLY_REQUEST_VALUES)
        public void beforeApplyRequestValues() {
        }

        @AfterPhase(Phase.APPLY_REQUEST_VALUES)
        public void afterApplyRequestValues() {
        }

        @BeforePhase(Phase.PROCESS_VALIDATIONS)
        public void beforeProcessValidations() {
        }

        @AfterPhase(Phase.PROCESS_VALIDATIONS)
        public void afterProcessValidations() {
        }

        @BeforePhase(Phase.UPDATE_MODEL_VALUES)
        public void beforeUpdateModelValues() {
        }

        @AfterPhase(Phase.UPDATE_MODEL_VALUES)
        public void afterUpdateModelValues() {
        }

        @BeforePhase(Phase.INVOKE_APPLICATION)
        public void beforeInvokeApplication() {
        }

        @AfterPhase(Phase.INVOKE_APPLICATION)
        public void afterInvokeApplication() {
        }

        @BeforePhase(Phase.RENDER_RESPONSE)
        public void beforeRenderResponse() {
        }

        @AfterPhase(Phase.RENDER_RESPONSE)
        public void afterRenderResponse() {
        }
    });

    new WebDriverWait(browser, 5).until(new Predicate<WebDriver>() {
        @Override
        public boolean apply(WebDriver browser) {
            WebElement output = browser.findElement(By.id("helloWorldJsf:output"));
            try {
                return output.getText().contains("JohnX");
            } catch (StaleElementReferenceException e) {
                return false;
            }
        }
    });
}

From source file:org.keycloak.testsuite.adapter.AdapterTestStrategy.java

License:Open Source License

protected void loginAndCheckSession(WebDriver driver, LoginPage loginPage) {
    driver.navigate().to(APP_SERVER_BASE_URL + "/session-portal");
    String currentUrl = driver.getCurrentUrl();
    Assert.assertTrue(currentUrl.startsWith(LOGIN_URL));
    loginPage.login("bburke@redhat.com", "password");
    System.out.println("Current url: " + driver.getCurrentUrl());
    Assert.assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/session-portal" + slash);
    String pageSource = driver.getPageSource();
    Assert.assertTrue(pageSource.contains("Counter=1"));

    // Counter increased now
    driver.navigate().to(APP_SERVER_BASE_URL + "/session-portal");
    pageSource = driver.getPageSource();
    Assert.assertTrue(pageSource.contains("Counter=2"));

}