List of usage examples for org.openqa.selenium WebDriver getCurrentUrl
String getCurrentUrl();
From source file:io.selendroid.client.waiter.WaitingConditions.java
License:Apache License
public static Callable<String> driverUrlToBe(final WebDriver driver, final String expectedUrl) { return new Callable<String>() { public String call() throws Exception { String url = driver.getCurrentUrl(); if (expectedUrl.equals(url)) { return url; }//from w w w . ja v a 2s. c o m return null; } @Override public String toString() { return "url to be: " + expectedUrl; } }; }
From source file:io.selendroid.demo.webui.EmployeeDirectoryTest.java
License:Apache License
@Step("Find employee <name> with id <id>") public void findEmployee(String name, String id) throws Exception { WebDriver driver = Driver.webDriver; driver.findElement(By.tagName("input")).sendKeys(name); driver.findElement(By.partialLinkText(name)).click(); Assert.assertEquals(driver.getCurrentUrl(), "file:///android_asset/www/index.html#employees/" + id); }
From source file:io.selendroid.demo.webui.EmployeeDirectoryTest.java
License:Apache License
@Step("Verify number of direct reports of employee with id <id> is <number>") public void verifyNumberOfDirectReports(String id, String number) throws Exception { WebDriver driver = Driver.webDriver; // Verify number of direct reports WebElement directs = driver.findElements(By.tagName("li")).get(1); Assert.assertThat(directs.getText(), endsWith(number)); directs.click();//from ww w . ja v a 2 s. c o m Assert.assertEquals(driver.getCurrentUrl(), "file:///android_asset/www/index.html#employees/" + id + "/reports"); }
From source file:io.selendroid.demo.webui.EmployeeDirectoryTest.java
License:Apache License
@Step("Verify the reportees of employee with id <id> are <reportees>") public void verifyNumberOfDirectReports(String id, Table reportees) throws Exception { WebDriver driver = Driver.webDriver; List<TableRow> tableRows = reportees.getTableRows(); for (int i = 0; i < tableRows.size(); i++) { Assert.assertThat(driver.findElements(By.tagName("li")).get(i).getText(), startsWith(tableRows.get(i).getCell("name"))); }/*from w ww. ja v a 2 s. c o m*/ driver.navigate().back(); Assert.assertEquals(driver.getCurrentUrl(), "file:///android_asset/www/index.html#employees/4"); }
From source file:io.selendroid.server.e2e.SessionCreationE2ETest.java
License:Apache License
private void testMethod(SelendroidCapabilities capa) throws Exception { WebDriver driver = new SelendroidDriver("http://localhost:5555/wd/hub", capa); String activityClass = "io.selendroid.testapp." + "HomeScreenActivity"; driver.get("and-activity://" + activityClass); driver.getCurrentUrl(); try {/* ww w.ja va 2 s .c o m*/ driver.findElement(By.id("not there")); Assert.fail(); } catch (NoSuchElementException e) { // expected } WebElement inputField = driver.findElement(By.id("my_text_field")); Assert.assertEquals("true", inputField.getAttribute("enabled")); inputField.sendKeys("Selendroid"); Assert.assertEquals("Selendroid", inputField.getText()); driver.quit(); }
From source file:io.selendroid.server.e2e.SessionCreationE2ETests.java
License:Apache License
private void testMethod(SelendroidCapabilities capa) throws Exception { WebDriver driver = new RemoteWebDriver(new URL("http://localhost:5555/wd/hub"), capa); String activityClass = "io.selendroid.testapp." + "HomeScreenActivity"; driver.get("and-activity://" + activityClass); driver.getCurrentUrl(); try {/*from ww w . j a va 2s .c o m*/ driver.findElement(By.id("not there")); Assert.fail(); } catch (NoSuchElementException e) { // expected } WebElement inputField = driver.findElement(By.id("my_text_field")); Assert.assertEquals("true", inputField.getAttribute("enabled")); inputField.sendKeys("Selendroid"); Assert.assertEquals("Selendroid", inputField.getText()); driver.findElement(By.id("buttonStartWebview")).click(); driver.switchTo().window("WEBVIEW"); WebElement element = driver.findElement(By.id("name_input")); element.clear(); ((JavascriptExecutor) driver).executeScript("var inputs = document.getElementsByTagName('input');" + "for(var i = 0; i < inputs.length; i++) { " + " inputs[i].value = 'helloJavascript';" + "}"); Assert.assertEquals("helloJavascript", element.getAttribute("value")); driver.quit(); }
From source file:io.wcm.qa.galenium.listeners.ExtentReportsListener.java
License:Apache License
@Override public void onTestFailure(ITestResult result) { String logMsgHtml = "Error when dealing with test failure."; try {//from ww w . j a v a 2 s . co m StringBuilder logMsg = new StringBuilder().append(System.lineSeparator()) .append(System.lineSeparator()); logMsg.append("+++++++++++++++Failed Test++++++++++++++++").append(System.lineSeparator()); logMsg.append("Testcase: ").append(getTestName(result)).append(System.lineSeparator()); Throwable throwable = result.getThrowable(); logMsg.append("Location: ").append(getLineThatThrew(throwable)).append(System.lineSeparator()); logMsg.append("Error: ").append(throwable.getMessage()).append(System.lineSeparator()); WebDriver driver = getDriver(); if (driver != null) { logMsg.append(GaleniumReportUtil.takeScreenshot(result, driver)); logMsg.append("URL: ").append(driver.getCurrentUrl()).append(System.lineSeparator()); } if (getTestDevice() != null) { logMsg.append("Browser: ").append(getTestDevice().toString()).append(System.lineSeparator()); } logMsg.append("Duration: ").append(getTestDuration(result)).append(System.lineSeparator()); GaleniumReportUtil.getLogger().debug(GaleniumReportUtil.MARKER_FAIL, "Full stacktrace", throwable); logMsg.append("++++++++++++++++++++++++++++++++++++++++++").append(System.lineSeparator()); logMsgHtml = logMsg.toString().replace(System.lineSeparator(), "<br />"); Reporter.log(logMsgHtml, false); getLogger().error(logMsg.toString()); } catch (Throwable ex) { GaleniumReportUtil.getLogger().error("Error during failure handling", ex); throw ex; } finally { GaleniumReportUtil.endExtentTest(result, LogStatus.FAIL, logMsgHtml); } }
From source file:io.wcm.qa.galenium.reporting.GaleniumReportUtil.java
License:Apache License
/** * Take screenshot of current browser window and add to reports. * @param result/*w w w . j av a 2 s . c om*/ * @param driver to take screenshot from * @return log message including screenshot if everything was successful */ public static String takeScreenshot(ITestResult result, WebDriver driver) { String destScreenshotFilePath = null; String filenameOnly = null; if (driver instanceof TakesScreenshot) { filenameOnly = System.currentTimeMillis() + "_" + result.getName() + ".png"; File screenshotFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); try { File destFile = new File(PATH_SCREENSHOTS_ROOT, filenameOnly); FileUtils.copyFile(screenshotFile, destFile); destScreenshotFilePath = PATH_SCREENSHOTS_RELATIVE_ROOT + File.separator + filenameOnly; String screenCapture = getExtentTest().addScreenCapture(destScreenshotFilePath); getLogger().info(screenCapture); } catch (IOException ex) { log.error("Cannot copy screenshot.", ex); } } StringBuilder logMsg = new StringBuilder(); if (filenameOnly != null) { logMsg.append("Screenshot: ").append(PATH_SCREENSHOTS_ROOT).append(File.separator).append(filenameOnly) .append(System.lineSeparator()); if (destScreenshotFilePath != null) { String url = driver.getCurrentUrl(); String title = driver.getTitle(); Reporter.log("<a href=\"" + url + "\"><img src=\"" + destScreenshotFilePath + "\" alt=\"" + title + "\"/></a>", true); } } return logMsg.toString(); }
From source file:IWDmainsiteProject.PageObjects.Verify_Pages.java
public static void Verify_current_url_Meet_the_team(WebDriver driver) { String currentURL = driver.getCurrentUrl(); System.out.println(currentURL); String expectedcurrentURL = "https://www.iwdagency.com/#meet-the-team"; assertEquals(currentURL, expectedcurrentURL); System.out.println("Link is correct https://www.iwdagency.com/#meet-the-team"); }
From source file:IWDmainsiteProject.PageObjects.Verify_Pages.java
public static void Verify_Title_link_Portfolio(WebDriver driver) { String actualTitle = driver.getTitle(); System.out.println(actualTitle); String expectedTitle = "IWD Agency's Portfolio"; assertEquals(expectedTitle, actualTitle); System.out.println("Title is correct"); String currentURL = driver.getCurrentUrl(); System.out.println(currentURL); String expectedcurrentURL = "https://www.iwdagency.com/portfolio"; assertEquals(currentURL, expectedcurrentURL); System.out.println("Link is correct https://www.iwdagency.com/portfolio"); }