List of usage examples for org.openqa.selenium WebDriver getCurrentUrl
String getCurrentUrl();
From source file:com.pages.CompanyLoginpage.java
public static void CompanyLogin(WebDriver driver, String Companynumber) throws InterruptedException { String url = driver.getCurrentUrl(); if (URL.equalsIgnoreCase(url)) { driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS); common.Wait_Until_ElementVisible(driver, LicenseAgreement_popup); driver.findElement(By.xpath("//button[@id='btnEULAAgree']")).click(); //Thread.sleep(1000); driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS); } else {//from w ww. j a v a 2s. co m driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS); JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript(String.format("window.localStorage.clear();")); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); driver.manage().deleteAllCookies(); Actions act = new Actions(driver); act.sendKeys(Keys.CONTROL.F5).perform(); driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS); driver.findElement(By.xpath("//button[@id='btnEULAAgree']")).click(); //Thread.sleep(1000); driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS); driver.manage().timeouts().implicitlyWait(1000, TimeUnit.SECONDS); } JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("return document.readyState").equals("complete"); //Thread.sleep(1000); WebDriverWait ww = new WebDriverWait(driver, 30); ww.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(AccessKey_fld_xpath))); driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS); driver.findElement(By.xpath(AccessKey_fld_xpath)).sendKeys(Companynumber); driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS); driver.findElement(By.xpath(Download_btn_xpath)).click(); driver.manage().timeouts().implicitlyWait(1000, TimeUnit.SECONDS); // Thread.sleep(500); ww.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(HomePage_NavBar))); }
From source file:com.partnet.automation.selenium.AbstractConfigurableDriverProvider.java
License:Apache License
/** * Screenshooter for HTMLUnit. It saves the html source to disk following the * same pattern as the screenshot path. The HTMLUnit session is transfered to * PhantomJs, which takes the screenshot, and is destroyed. The original * driver is not destroyed//from w ww . j ava 2 s. co m * * Note: Javascript events, current page changes, etc.. are not saved and are * not captured in the screenshots taken. * * @param path * - where to save the file. This assumes a png file will be * generated * @param baseUrl * - used to transfer the cookies to the phantomjs driver properly. * * @see #getPhantomJsWebDriver() */ public void saveScreenshotForHtmlUnit(String path, String baseUrl) { final WebDriver driver = this.get(); if (!(driver instanceof HtmlUnitDriver)) { LOG.warn("Wrong driver called screenshooter for HTMLUnit driver, default to regular screenshooter"); this.saveScreenshotAs(path); return; } PhantomJSDriver phantomJs = (PhantomJSDriver) getPhantomJsWebDriver(); try { phantomJs.get(baseUrl); String url = driver.getCurrentUrl(); LOG.debug("Url: {}", url); for (Cookie cookie : driver.manage().getCookies()) { LOG.debug("Cookie: {}", cookie.toString()); phantomJs.manage().addCookie(cookie); } phantomJs.get(url); // set current thread to phantomjs, and take screenshot in the default way this.set(phantomJs); LOG.debug("HTML Screenshot taken: {}", this.saveScreenshotAs(path)); } finally { // set back original driver for this thread this.set(driver); phantomJs.close(); phantomJs.quit(); } }
From source file:com.redhat.darcy.webdriver.internal.WindowUrlWebDriverTargetTest.java
License:Open Source License
@Test public void shouldTargetAWindowWhichMatchesTheUrlMatcher() { WebDriverTarget target = WebDriverTargets.windowByUrl(equalTo("foo")); WebDriver found = target.switchTo(locator); assertThat(found.getCurrentUrl(), is("foo")); }
From source file:com.redhat.darcy.webdriver.internal.WindowUrlWebDriverTargetTest.java
License:Open Source License
@Test public void shouldKeepFindingTheSameWindowEvenIfItsUrlLaterDoesNotMatch() { WebDriverTarget target = WebDriverTargets.windowByUrl(equalTo("foo")); WebDriver found = target.switchTo(locator); assertThat(found.getCurrentUrl(), is("foo")); when(fooWindow.getCurrentUrl()).thenReturn("no longer foo"); WebDriver foundAgain = target.switchTo(locator); assertThat(foundAgain.getCurrentUrl(), is("no longer foo")); }
From source file:com.safeway.app.appcert.smoketester.SmokeTester.java
@Test public void executeSmokeTest() throws Exception { // Create a new instance of the Firefox driver // Notice that the remainder of the code relies on the interface, // not the implementation. System.setProperty("webdriver.chrome.driver", "C:\\Nino\\ChromeWebDriver\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); TestCaseReader tcreader = new TestCaseReader(); List<TestScriptTemplate> tcl = tcreader.readExcel(); List<TestScriptTemplate> validatedTestScript = new ArrayList(); String log_execution = ""; Iterator<TestScriptTemplate> i = tcl.iterator(); while (i.hasNext()) { TestScriptTemplate testscript = i.next(); //collect the results TestScriptTemplate testexecution = new TestScriptTemplate(); testexecution.setAppCode(testscript.getAppCode()); log_execution = log_execution + " Start smoke testing for application code: " + testexecution.getAppCode(); //access the URL driver.get(testscript.getAppURL()); //login if not yet if (driver.getCurrentUrl().contains("identity.safeway.com")) { //key in userid and password WebElement weusername = driver.findElement(By.id("username")); //System.out.println("tag:" + weusername.getTagName()); weusername.sendKeys(testscript.getAppUserID()); WebElement wepassword = driver.findElement(By.id("password")); //System.out.println("tag:" + wepassword.getTagName()); wepassword.sendKeys(testscript.getAppPassword()); WebElement weloginform = driver.findElement(By.name("loginData")); //System.out.println("tag:" + weloginform.getTagName()); weloginform.submit();//from ww w . j a va 2 s. c om } //recoding URL; required so no need to check for nullity testexecution.setAppURL(driver.getCurrentUrl()); log_execution = log_execution + " Current URL: " + driver.getCurrentUrl(); //recoding title; required so no need to check for nullity testexecution.setHomePageTitle(driver.getTitle()); log_execution = log_execution + " Login Successful"; log_execution = log_execution + " Page Title: " + driver.getTitle(); if (isElementExist(testscript.getHomePageElementType(), testscript.getHomePageElement(), driver)) { System.out.println("Element match!" + testscript.getHomePageElement()); log_execution = log_execution + " Home Page Element validation..."; testexecution.setHomePageElement(testscript.getHomePageElement()); } else { testexecution.setHomePageElement("not found"); } //next page validation if (!testscript.getLevel1URL().isEmpty() || !testscript.getLevel1URL().equals("")) { //go to next level page driver.get(testscript.getLevel1URL()); log_execution = log_execution + " Next Page validation URL: " + testscript.getLevel1URL(); testexecution.setLevel1URL(driver.getCurrentUrl()); System.out.println("execution log: current level 1 URL on set" + testexecution.getLevel1URL()); if (!testscript.getLevel1PageTitle().isEmpty() || !testscript.getLevel1PageTitle().equals("")) { testexecution.setLevel1PageTitle(driver.getTitle()); log_execution = log_execution + " Next Page title validation: " + driver.getTitle(); } if (isElementExist(testscript.getLevel1ElementType(), testscript.getLevel1Element(), driver)) { testexecution.setLevel1Element(testscript.getLevel1Element()); log_execution = log_execution + " Next Page element validation: " + testscript.getLevel1Element(); } else { testexecution.setLevel1Element("not found"); } } testexecution.setLogs(log_execution); System.out.println("Execution Log: " + log_execution); log_execution = ""; SmokeTestValidator testvalidator = new SmokeTestValidator(testscript); TestScriptTemplate testingresult = testvalidator.getTestResult(testexecution); validatedTestScript.add(testingresult); } tcreader.writetoExcel(validatedTestScript); //Close the browser driver.quit(); //return log_execution; }
From source file:com.smash.revolance.ui.model.helper.UserHelper.java
License:Open Source License
private static String getCurrentUrl(User user) throws Exception { WebDriver browser = user.getBrowser(); try {/*from w w w .j a v a2 s . c o m*/ return browser.getCurrentUrl(); } catch (UnhandledAlertException e) { UserHelper.handleAlert(user); return browser.getCurrentUrl(); } }
From source file:com.sugarcrm.candybean.automation.VInterface.java
License:Open Source License
/** * Focus a browser window by its window title or URL if it does not * match the current title or URL./* w w w.j av a 2 s . c om*/ * * <p>If more than one window has the same title or URL, the first * encountered is the one that is focused.</p> * * @param titleOrUrl the exact window title or URL to be matched * @throws Exception if the specified window cannot be found */ public void focusWindow(String titleOrUrl) throws Exception { String curTitle = this.wd.getTitle(); String curUrl = this.wd.getCurrentUrl(); if (titleOrUrl.equals(curTitle) || titleOrUrl.equals(curUrl)) { candybean.log.warning( "No focus was made because the given string matched the current title or URL: " + titleOrUrl); } else { Set<String> windowHandlesSet = this.wd.getWindowHandles(); String[] windowHandles = windowHandlesSet.toArray(new String[] { "" }); int i = 0; boolean windowFound = false; while (i < windowHandles.length && !windowFound) { WebDriver window = this.wd.switchTo().window(windowHandles[i]); if (window.getTitle().equals(titleOrUrl) || window.getCurrentUrl().equals(titleOrUrl)) { windows.push(new Pair<Integer, String>(new Integer(i), this.wd.getWindowHandle())); candybean.log.info("Focused by title or URL: " + titleOrUrl + " to window: " + windows.peek()); windowFound = true; } i++; } if (!windowFound) { this.wd.switchTo().window(windows.peek().y); throw new Exception("The given focus window string matched no title or URL: " + titleOrUrl); } } }
From source file:com.sugarcrm.candybean.automation.webdriver.WebDriverInterface.java
License:Open Source License
/** * Focus a browser window by its window title or URL if it does not * match the current title or URL.//ww w .j av a 2 s. c om * * <p>If more than one window has the same title or URL, the first * encountered is the one that is focused.</p> * * @param titleOrUrl the exact window title or URL to be matched * @throws CandybeanException if the specified window cannot be found */ public void focusWindow(String titleOrUrl) throws CandybeanException { String curTitle = this.wd.getTitle(); String curUrl = this.wd.getCurrentUrl(); if (titleOrUrl.equals(curTitle) || titleOrUrl.equals(curUrl)) { logger.warning( "No focus was made because the given string matched the current title or URL: " + titleOrUrl); } else { Set<String> windowHandlesSet = this.wd.getWindowHandles(); String[] windowHandles = windowHandlesSet.toArray(new String[] { "" }); int i = 0; boolean windowFound = false; while (i < windowHandles.length && !windowFound) { WebDriver window = this.wd.switchTo().window(windowHandles[i]); if (window.getTitle().equals(titleOrUrl) || window.getCurrentUrl().equals(titleOrUrl)) { windows.push(new Pair<Integer, String>(new Integer(i), this.wd.getWindowHandle())); logger.info("Focused by title or URL: " + titleOrUrl + " to window: " + windows.peek()); windowFound = true; } i++; } if (!windowFound) { this.wd.switchTo().window(windows.peek().y); throw new CandybeanException( "The given focus window string matched no title or URL: " + titleOrUrl); } } }
From source file:com.testsel.maventestsel.PageTest.java
/** * /*from www.j av a 2 s . c o m*/ */ // public PageTest(WebDriver wd) { // , ? ? if (!wd.getCurrentUrl().contains(URL_MATCH)) { throw new IllegalStateException("This is not the page you are expected"); } PageFactory.initElements(wd, this); this.wd = wd; }
From source file:com.thoughtworks.inproctester.tests.InProcessHtmlUnitDriverTest.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")); contactNameElement.clear();//from ww w . ja v a 2 s . com 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")); }