List of usage examples for org.openqa.selenium WebDriver getCurrentUrl
String getCurrentUrl();
From source file:com.thoughtworks.inproctester.tests.InProcessHtmlUnitDriverTestWithWebXml.java
License:Apache License
@Test public void shouldSupportGetAndPostRequests() { WebDriver htmlUnitDriver = new InProcessHtmlUnitDriver(httpAppTester); htmlUnitDriver.get("http://localhost/contacts/add"); assertThat(htmlUnitDriver.getTitle(), is("Test Application")); assertThat(htmlUnitDriver.findElement(By.tagName("h3")).getText(), is("Contact Details")); WebElement contactNameElement = htmlUnitDriver.findElement(By.name("contactName")); assertThat(contactNameElement.getAttribute("value"), isEmptyString()); contactNameElement.sendKeys("My Contact"); htmlUnitDriver.findElement(By.tagName("form")).submit(); assertThat(htmlUnitDriver.getCurrentUrl(), is("http://localhost/contacts/1")); assertThat(htmlUnitDriver.findElement(By.name("contactName")).getAttribute("value"), is("My Contact")); }
From source file:com.thoughtworks.selenium.corerunner.CoreTest.java
License:Apache License
public void run(Results results, WebDriver driver, Selenium selenium) { if (!driver.getCurrentUrl().equals(url)) { driver.get(url);//from w ww . j a v a 2 s . c o m } // Are we running a suite or an individual test? List<WebElement> allTables = driver.findElements(By.id("suiteTable")); if (allTables.isEmpty()) { new CoreTestCase(url).run(results, driver, selenium); } else { new CoreTestSuite(url).run(results, driver, selenium); } }
From source file:com.thoughtworks.selenium.corerunner.CoreTestCase.java
License:Apache License
public void run(Results results, WebDriver driver, Selenium selenium) { String currentUrl = driver.getCurrentUrl(); if (!url.equals(currentUrl)) { driver.get(url);/* w ww . j av a2 s.c om*/ } List<CoreTestStep> steps = findCommands(driver); for (CoreTestStep step : steps) { step.run(results, driver, selenium); } }
From source file:com.thoughtworks.selenium.corerunner.CoreTestSuite.java
License:Apache License
public void run(Results results, WebDriver driver, Selenium selenium) { if (!url.equals(driver.getCurrentUrl())) { driver.get(url);// w w w.ja v a 2 s . c o m } List<WebElement> allTables = driver.findElements(By.id("suiteTable")); if (allTables.isEmpty()) { throw new SeleniumException("Unable to locate suite table: " + url); } List<String> allTestUrls = (List<String>) ((JavascriptExecutor) driver).executeScript( "var toReturn = [];\n" + "for (var i = 0; i < arguments[0].rows.length; i++) {\n" + " if (arguments[0].rows[i].cells.length == 0) {\n" + " continue;\n" + " }\n" + " var cell = arguments[0].rows[i].cells[0];\n" + " if (!cell) { continue; }\n" + " var allLinks = cell.getElementsByTagName('a');\n" + " if (allLinks.length > 0) {\n" + " toReturn.push(allLinks[0].href);\n" + " }\n" + "}\n" + "return toReturn;\n", allTables.get(0)); for (String testUrl : allTestUrls) { new CoreTest(testUrl).run(results, driver, selenium); } }
From source file:com.thoughtworks.selenium.webdriven.commands.WaitForPopup.java
License:Apache License
@Override protected Void handleSeleneseCommand(final WebDriver driver, final String windowID, final String timeout) { final long millis = toLong(timeout); final String current = driver.getWindowHandle(); new Wait() {/*from w ww.j a va 2 s . c o m*/ @Override public boolean until() { try { windows.selectPopUp(driver, windowID); return !"about:blank".equals(driver.getCurrentUrl()); } catch (SeleniumException e) { // Swallow } return false; } }.wait(String.format("Timed out waiting for %s. Waited %s", windowID, timeout), millis); driver.switchTo().window(current); return null; }
From source file:com.vaadin.testbench.TestBenchDriverTest.java
@Test public void testTestBenchDriverActsAsProxy() { FirefoxDriver mockDriver = createMock(FirefoxDriver.class); mockDriver.close();// w w w . j a v a 2s . c om 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:db.Db.java
static boolean regAccount(String a[][], String referralUrl, int f, WebDriver driver) throws InterruptedException { String name = a[f][0], shurname = a[f][1], password = a[f][2], mail = a[f][3]; boolean ispresent = false, registered = false; String gsUrl = "https://www.dropbox.com/gs"; driver.get(referralUrl);/* w ww . j a va 2 s . c o m*/ for (int second = 0;; second++) { if (second >= 30) { System.out.println("Connection timeout"); break; } //ispresent try { driver.findElement(By.xpath("//div[2]/div/div/form/div[2]/div[2]/input")); ispresent = true; } catch (NoSuchElementException e) { ispresent = false; } try { if (ispresent) break; } catch (Exception e) { } Thread.sleep(1000); } Thread.sleep(100); if (ispresent) { driver.findElement(By.xpath("//div[2]/div/div/form/div[2]/div[2]/input")).clear(); driver.findElement(By.xpath("//div[2]/div/div/form/div[2]/div[2]/input")).sendKeys(name); driver.findElement(By.xpath("//div[2]/div/div/form/div[3]/div[2]/input")).clear(); driver.findElement(By.xpath("//div[2]/div/div/form/div[3]/div[2]/input")).sendKeys(shurname); driver.findElement(By.xpath("//div[5]/div[2]/input")).clear(); driver.findElement(By.xpath("//div[5]/div[2]/input")).sendKeys(password); driver.findElement(By.xpath("//div[2]/div/div/form/div[4]/div[2]/input")).clear(); driver.findElement(By.xpath("//div[2]/div/div/form/div[4]/div[2]/input")).sendKeys(mail); driver.findElement(By.xpath("//div[6]/input")).click(); //Check tos agree Thread.sleep(100); driver.findElement(By.xpath("//div[2]/div/div/form/button")).click(); //Submit register form for (int second = 0;; second++) { if (second >= 15) { System.out.println("Submitting form timeout"); break; } if (gsUrl.equals(driver.getCurrentUrl())) registered = true; try { if (registered) break; } catch (Exception e) { } Thread.sleep(1000); } } int n = f + 1; if (registered) System.out.print(""); else System.out.print("x"); driver.manage().deleteAllCookies(); return registered; //returns true or false }
From source file:de.knowwe.uitest.UITestUtils.java
License:Open Source License
public static void recompileCurrentArticle(WebDriver driver) { String currentUrl = driver.getCurrentUrl(); if (!currentUrl.contains("&parse=full")) { currentUrl += "&parse=full"; }//from w ww. j a v a 2 s . c om driver.get(currentUrl); }
From source file:DerpSelenium.test.java
public static void loginMega(String username, String passwd) throws InterruptedException { FirefoxProfile profile = new FirefoxProfile(); WebDriver driver = new FirefoxDriver(new FirefoxBinary(new File("/home/michael/bin/firefox")), profile); driver.get("http://www.mega.nz"); (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { @Override//w w w . j ava2 s . co m public Boolean apply(WebDriver d) { try { WebElement loginButton = d.findElement(By.className("top-login-button")); System.out.println(loginButton.getText()); } catch (NoSuchElementException e) { return false; } return true; } }); WebElement loginButton = driver.findElement(By.xpath("//a[@class='top-login-button hidden']")); loginButton.click(); WebElement nameElement = driver.findElement(By.name("login-name")); WebElement pwElement = driver.findElement(By.name("login-password")); nameElement.sendKeys(username); pwElement.sendKeys(passwd); WebElement submitButton = driver.findElement(By.className("top-dialog-login-button")); submitButton.click(); Thread.sleep(15000); String url = driver.getCurrentUrl(); List<WebElement> elements = driver.findElements(By.tagName("div")); Map<String, WebElement> elementMap = new HashMap<>(); for (Iterator<WebElement> it = elements.iterator(); it.hasNext();) { WebElement e = it.next(); try { if (!e.isDisplayed() || !e.isEnabled() || e.getAttribute("class").equals("")) { it.remove(); } else { elementMap.put(e.getAttribute("class"), e); } } catch (StaleElementReferenceException ex) { it.remove(); } } print("Number of added elements = " + elements.size()); List<WebElement> contacts = driver .findElements(By.xpath("//div[@class='nw-fm-left-icon contacts ui-droppable']")); contacts.get(1).click(); Thread.sleep(2000); //driver.navigate().back(); //Thread.sleep(2000); WebElement el = elementMap.get("nw-fm-left-icon shared-with-me ui-droppable"); if (el == null) { print("Element not found"); } else { el.click(); } }
From source file:edu.uga.cs.clickminer.datamodel.log.PageEntry.java
License:Open Source License
/** * <p>getPageEntry.</p>/*from ww w. j a v a 2s . c o m*/ * * @param wdriver a {@link org.openqa.selenium.WebDriver} object. * @param windowIMap a {@link edu.uga.cs.clickminer.index.WindowInteractionIndex} object. * @param windowhandle a {@link java.lang.String} object. * @param results a {@link java.util.List} object. */ public static PageEntry getPageEntry(WebDriver wdriver, WindowInteractionIndex windowIMap, String windowhandle, List<ElementSearchResult> results) { WindowEntry winentry = new WindowEntry(windowhandle, windowIMap.getWindowOpener(windowhandle)); List<FrameEntry> entries = new ArrayList<FrameEntry>(); for (ElementSearchResult result : results) { entries.add(FrameEntry.getFrameEntry(wdriver, result)); } return new PageEntry(winentry, entries, wdriver.getCurrentUrl()); }