List of usage examples for org.openqa.selenium WebDriver get
void get(String url);
From source file:com.twiceagain.mywebdriver.startup.DemoGrid.java
License:Open Source License
public static void main(String[] args) { WebDriver wd = Drivers.getDriver(Drivers.Config.defaultGridFirefox()); wd.get("https://www.google.com"); System.out.printf("\nSaved file to : %s\n", Drivers.screenshot2File(wd, "grid_FullPageGoogle.png")); WebElement we = wd.findElement(By.id("hplogo")); System.out.printf("\nSaved file to : %s\n", Drivers.screenshot2File(wd, we, "grid_LogoGoogle.png")); wd.quit();/*from w w w. jav a2 s. c o m*/ }
From source file:com.twiceagain.mywebdriver.startup.DemoNoGrid.java
License:Open Source License
/** * * @param args the command line arguments *//*from w w w. ja v a 2 s .com*/ public static void main(String[] args) { WebDriver wd = Drivers.getDriver(Drivers.Config.defaultLocalFirefox()); wd.get("https://www.google.com"); System.out.printf("\nSaved file to : %s\n", Drivers.screenshot2File(wd, "local_FullPageGoogle.png")); WebElement we = wd.findElement(By.id("hplogo")); System.out.printf("\nSaved file to : %s\n", Drivers.screenshot2File(wd, we, "local_LogoGoogle.png")); wd.quit(); }
From source file:com.twiceagain.rservejavademo.webaccess.BasicDriverTest.java
/** * Test of _getDriver method, of class BasicDriver. * @throws java.lang.InterruptedException *///www .java 2 s .co m @Test public void testGetDriver() throws InterruptedException { System.out.println("getDriver"); WebDriver expResult = null; WebDriver wd = BasicDriver.getDriver(); wd.get("http://www.google.fr"); Thread.sleep(1000); assert (wd.getTitle().contains("Google")); WebElement searchBox = wd.findElement(By.name("q")); searchBox.sendKeys("ChromeDriver test"); searchBox.submit(); Thread.sleep(5000); // Let the user actually see something! wd.close(); }
From source file:com.twiceagain.rservejavademo.webaccess.BasicDriverTest.java
@Test public void testAttributes() { WebDriver wd = BasicDriver.getDriver(); wd.get("http://www.google.fr"); WebElement we = wd.findElement(By.tagName("input")); System.out.println("Listing attributes : " + BasicDriver.getAttributes(wd, we)); wd.close();//from ww w . java 2s . c o m }
From source file:com.vaadin.testbench.TestBenchDriverTest.java
@Test public void testTestBenchDriverActsAsProxy() { FirefoxDriver mockDriver = createMock(FirefoxDriver.class); mockDriver.close();//from w w w .j a va 2 s .c o m expectLastCall().once(); WebElement mockElement = createNiceMock(WebElement.class); expect(mockDriver.findElement(isA(By.class))).andReturn(mockElement); List<WebElement> elements = Arrays.asList(mockElement); expect(mockDriver.findElements(isA(By.class))).andReturn(elements); mockDriver.get("foo"); expectLastCall().once(); expect(mockDriver.getCurrentUrl()).andReturn("foo"); expect(mockDriver.getPageSource()).andReturn("<html></html>"); expect(mockDriver.getTitle()).andReturn("bar"); expect(mockDriver.getWindowHandle()).andReturn("baz"); Set<String> handles = new HashSet<String>(); expect(mockDriver.getWindowHandles()).andReturn(handles); Options mockOptions = createNiceMock(Options.class); expect(mockDriver.manage()).andReturn(mockOptions); Navigation mockNavigation = createNiceMock(Navigation.class); expect(mockDriver.navigate()).andReturn(mockNavigation); mockDriver.quit(); expectLastCall().once(); expect(((JavascriptExecutor) mockDriver).executeScript(anyObject(String.class))).andStubReturn(true); TargetLocator mockTargetLocator = createNiceMock(TargetLocator.class); expect(mockDriver.switchTo()).andReturn(mockTargetLocator); replay(mockDriver); // TestBenchDriverProxy driver = new TestBenchDriverProxy(mockDriver); WebDriver driver = TestBench.createDriver(mockDriver); driver.close(); By mockBy = createNiceMock(By.class); assertTrue(driver.findElement(mockBy) instanceof TestBenchElementCommands); assertTrue(driver.findElements(mockBy).get(0) instanceof TestBenchElementCommands); driver.get("foo"); assertEquals("foo", driver.getCurrentUrl()); assertEquals("<html></html>", driver.getPageSource()); assertEquals("bar", driver.getTitle()); assertEquals("baz", driver.getWindowHandle()); assertEquals(handles, driver.getWindowHandles()); assertEquals(mockOptions, driver.manage()); assertEquals(mockNavigation, driver.navigate()); driver.quit(); assertEquals(mockTargetLocator, driver.switchTo()); verify(mockDriver); }
From source file:com.vha.techdev.webapp.test.SimpleTest.java
License:Apache License
@Test public void testSimple() throws Exception { driver.get(serverUrl + "index.html"); // wait a bit ajax response new WebDriverWait(driver, 2).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver driver) { return driver.findElements(By.className("info").id("version")).size() > 0; }/*from ww w . j a v a2s. c om*/ }); WebElement version = driver.findElement(By.id("version")); Assert.assertEquals(ComponentInfo.IMPLEMENTATION.toString(), version.getText()); String whoToSend = "foo"; WebElement who = driver.findElement(By.id("who")); who.sendKeys(whoToSend); WebElement sendBtn = driver.findElement(By.id("send-btn")); sendBtn.click(); // wait a bit ajax response new WebDriverWait(driver, 2) .until(ExpectedConditions.textToBePresentInElement(By.id("response"), whoToSend)); WebElement response = driver.findElement(By.id("response")); Assert.assertEquals("Hello " + whoToSend, response.getText()); }
From source file:com.vha.techdev.webapp.test.SimpleTest.java
License:Apache License
@Test public void testFileUpload() throws Exception { driver.get(serverUrl + "index.html"); long fileLength = 16384L; File tempFile = createTestFile(fileLength); String expectedResponse = tempFile.getName() + ":application/octet-stream:" + fileLength; WebElement uploadFile = driver.findElement(By.id("uploadfile")); uploadFile.sendKeys(tempFile.getAbsolutePath()); WebElement uploadBtn = driver.findElement(By.id("upload-btn")); uploadBtn.click();//from ww w.java 2 s . c o m // wait a bit ajax response new WebDriverWait(driver, 5).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver driver) { return driver.findElements(By.className("info").id("file-response")).size() > 0; } }); WebElement fileResponse = driver.findElement(By.id("file-response")); Assert.assertEquals(expectedResponse, fileResponse.getText()); }
From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java
License:Apache License
/** * Opens an URL in the test frame. This accepts both relative and absolute * URLs. The "open" command <br>//ww w .ja v a2s. com * waits for the page to load before proceeding, ie. the "AndWait" suffix is * implicit. Note: The URL <br> * must be on the same domain as the runner HTML due to security * restrictions in the browser <br> * (Same Origin Policy). If you need to open an URL on another domain, use * the Selenium Server <br> * to start a new browser session on that domain. * * @param locator * : url of the openning page * @param waitTime * : time to wait till the page is loaded. * * */ private void doOpen(final ObjectLocator locator, final String waitTime) { String url = ""; WebDriver driver = getDriver(); try { url = locator.getActualLocator(); if ("default".equalsIgnoreCase(url)) { PropertyHandler propertyHandler = new PropertyHandler("runtime.properties"); url = propertyHandler.getRuntimeProperty("DEFAULT_URL"); if ("".equals(url)) { throw new WebDriverException("Empty URL : " + url); } } setCommandStartTime(getCurrentTime()); driver.get(url); try { driver.manage().timeouts().implicitlyWait(Integer.parseInt(waitTime), TimeUnit.MILLISECONDS); } catch (Exception e) { e.printStackTrace(); } reportresult(true, "OPEN : " + url + "", "PASSED", url); } catch (WebDriverException e) { String errorString = e.getMessage(); reportresult(true, "OPEN : " + url + "", "FAILED", "Cannot access the empty URL. URL : " + url + ". Actual Error : " + errorString); checkTrue(false, true, "Cannot access the empty URL. URL : " + url + ". Actual Error : " + errorString); } catch (Exception e) { String errorString = e.getMessage(); reportresult(true, "OPEN : " + url + "", "FAILED", "Cannot access the URL. URL : " + url + ". Actual Error : " + errorString); checkTrue(false, true, "Cannot access the URL. URL : " + url + ". Actual Error : " + errorString); } }
From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java
License:Apache License
/** * Opens an URL in a new test frame. This accepts both relative and absolute * URLs. The "open" command <br>//from w ww . j a v a 2 s . com * waits for the page to load before proceeding, ie. the "AndWait" suffix is * implicit. Note: The URL <br> * must be on the same domain as the runner HTML due to security * restrictions in the browser <br> * (Same Origin Policy). If you need to open an URL on another domain, use * the Selenium Server <br> * to start a new browser session on that domain. * * @param locator * the locator * @param waitTime * the wait time */ private void doNavigateToURL(final ObjectLocator locator, final String waitTime) { String url = ""; WebDriver driver = getDriver(); try { url = locator.getActualLocator(); setCommandStartTime(getCurrentTime()); if (url.toLowerCase(Locale.getDefault()).startsWith("openwindow=")) { Set<String> oldWindowHandles = getAllWindows(); String actualUrl = url.substring(url.indexOf('=') + 1, url.length()); JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("window.open('" + actualUrl + "', '_newWindow');"); super.sleep(Integer.parseInt(waitTime)); Set<String> newWindowHandles = getAllWindows(); newWindowHandles.removeAll(oldWindowHandles); Object[] newWindowArr = newWindowHandles.toArray(); driver.switchTo().window(newWindowArr[0].toString()); } else { driver.get(url); super.sleep(Integer.parseInt(waitTime)); } reportresult(true, "NAVIGATE TO URL Command :" + url + "", "PASSED", url); } catch (Exception e) { String errorString = e.getMessage(); reportresult(true, "NAVIGATE TO URL :" + url + "", "FAILED", "NAVIGATE TO URL command : URL " + url + " failed. Actual Error : " + errorString); checkTrue(false, true, "NAVIGATE TO URL command : URL " + url + " failed. Actual Error : " + errorString); } }
From source file:com.vmware.gemfire.tools.pulse.testbed.driver.PulseUITest.java
License:Apache License
private static void loginToPulse(WebDriver driver, String userName, String password) { driver.get(pulseURL); WebElement userNameElement = driver.findElement(By.id("user_name")); WebElement passwordElement = driver.findElement(By.id("user_password")); userNameElement.sendKeys(userName);/*from w w w. j ava 2s . c om*/ passwordElement.sendKeys(password); passwordElement.submit(); WebElement userNameOnPulsePage = (new WebDriverWait(driver, 10)).until(new ExpectedCondition<WebElement>() { @Override public WebElement apply(WebDriver d) { return d.findElement(By.id("userName")); } }); assertNotNull(userNameOnPulsePage); }