Example usage for org.openqa.selenium WebDriver getCurrentUrl

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

Introduction

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

Prototype

String getCurrentUrl();

Source Link

Document

Get a string representing the current URL that the browser is looking at.

Usage

From source file:SmokeTester_UnitTest.java

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 + "\nStart 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  w  w  w .j a  v a 2  s  .c  o m*/
            log_execution = log_execution + " Login Successful";
        }

        //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 + " 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);
        SmokeTestValidator_UnitTest testvalidator = new SmokeTestValidator_UnitTest(testscript);
        TestScriptTemplate testingresult = testvalidator.getTestResult(testexecution);
        validatedTestScript.add(testingresult);

    }

    tcreader.writetoExcel(validatedTestScript);
    //Close the browser
    driver.quit();
    //return log_execution;
}

From source file:br.edu.ifpb.praticas.testSystem.FilmeTest.java

@Test
public void testCadastro() throws Exception {
    WebDriver driver = new FirefoxDriver();
    WebElement element = driver.findElement(By.name("nome"));
    // Create a new instance of the Firefox driver
    // Notice that the remainder of the code relies on the interface, 
    // not the implementation.

    assertEquals("http://localhost:8085/SisFilme/index.xhtml", driver.getCurrentUrl());

    Thread.sleep(2000L);/*from w w w.j  a  v  a  2  s.c  o  m*/
    element = driver.findElement(By.name("nome"));
    element.sendKeys("007 contra moscol");
    element = driver.findElement(By.name("nome"));
    element.sendKeys("007 contra moscol");

    element = driver.findElement(By.name("ano"));
    element.sendKeys("2014");
    element = driver.findElement(By.name("genero"));
    element = driver.findElement(By.name("nota"));
    element.sendKeys("2");

    element = driver.findElement(By.name("salvar"));
    Thread.sleep(2000L);
    element.click();
    assertEquals("http://localhost:8085/SisFilme/gerenciamento.xhtml", driver.getCurrentUrl());

    assertNotNull(element);
    // Wait for the page to load, timeout after 10 seconds
    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver d) {
            return d.getTitle().contains("NetBeans");
        }
    });

    //Close the browser
    driver.quit();
}

From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.WebDriverRunner.java

License:Open Source License

public void setScreen(String screenName) {
    String location;//  w  w w  .  j a  va 2 s.  co  m

    try {
        location = ReflectionUtil.getLocation(screenName);
    } catch (Exception ex) {
        location = "";
    }

    Set<String> lWindowHandles = driver.getWindowHandles();
    for (String lWindowHandle : lWindowHandles) {
        WebDriver lWindow = driver.switchTo().window(lWindowHandle);
        if (!location.isEmpty() && lWindow.getCurrentUrl().equalsIgnoreCase(location)) {
            return;
        }
        if (lWindow.getTitle().toUpperCase().indexOf(screenName.toUpperCase()) >= 0) {
            return;
        }
    }
}

From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.WebDriverRunnerTest.java

License:Open Source License

@Test
public void testGet() {
    WebDriver driverExpected = Mockito.mock(WebDriver.class);

    Mockito.when(driverExpected.getCurrentUrl()).thenReturn("url");
    WebDriverRunner runner = new WebDriverRunner();
    runner.setWebDriver(driverExpected);

    runner.get("url");
}

From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.WebDriverRunnerTest.java

License:Open Source License

@Test
public void testGetCurrentUrl() {
    WebDriver driverExpected = Mockito.mock(WebDriver.class);

    Mockito.when(driverExpected.getCurrentUrl()).thenReturn("url");
    WebDriverRunner runner = new WebDriverRunner();
    runner.setWebDriver(driverExpected);

    Assert.assertEquals("url", runner.getCurrentUrl());
}

From source file:com.actian.amc.pages.InstanceNewPage.java

public InstanceNewPage(WebDriver driver) {
    super(driver);
    // Check that we're on the right page.
    if (!driver.getCurrentUrl().contains("#ProvisionPlace:ProvisionPlace")) {
        throw new IllegalStateException("This is not a valid new instance page");
    }/*from   w w  w. j a v a  2 s.c  o m*/
}

From source file:com.citrix.g2w.webdriver.pages.branding.settings.BrandingPreviewPage.java

License:Open Source License

/**
 * Constructor to initialize instance variables and verify the current page url.
 * //from   w  w  w . j  a v  a  2s  .c  o  m
 * @param webDriver (web driver)
 */
public BrandingPreviewPage(final WebDriver webDriver) {
    this.driver = webDriver;
    Assert.assertTrue(webDriver.getCurrentUrl().contains("preview.tmpl"));
    PageFactory.initElements(this.driver, this);
}

From source file:com.citrix.g2w.webdriver.pages.branding.settings.ManageBrandingSettingsPage.java

License:Open Source License

/**
 * Constructor to initialize instance variables and verify the current page url.
 * /*from w w w.jav a 2  s  .c o m*/
 * @param webDriver (web driver)
 */
public ManageBrandingSettingsPage(final WebDriver webDriver) {
    this.driver = webDriver;
    Assert.assertTrue(webDriver.getCurrentUrl().contains("branding/manage.tmpl"));
    PageFactory.initElements(this.driver, this);
    this.logger.logWithScreenShot("Branding settings page", this.driver);
}

From source file:com.citrix.g2w.webdriver.pages.recordings.MyRecordingsPage.java

License:Open Source License

/**
 * Constructor to initialize instance variables and verify if we are on the
 * My Recordings page./* w  ww. j a  v a  2  s  .  com*/
 *
 * @param webDriver (web driver)
 */
public MyRecordingsPage(final WebDriver webDriver) {
    this.driver = webDriver;
    Assert.assertTrue(webDriver.getCurrentUrl().contains("recordings.tmpl"));
    PageFactory.initElements(this.driver, this);
}

From source file:com.citrix.g2w.webdriver.pages.recordings.MyRecordingsPage.java

License:Open Source License

public MyRecordingsPage(String url, final WebDriver webDriver) {
    this.driver = webDriver;
    this.driver.get(url);
    Assert.assertTrue(webDriver.getCurrentUrl().contains("recordings.tmpl"));
    PageFactory.initElements(this.driver, this);
}