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:webMainScripts.loginLogout.LogoutAndSessionExpiresOnBackButton.java

@Test(priority = 1, groups = { "loginlogout" })
public void LogoutAndSessionExpiresOnBackButtonClick() throws BiffException, IOException, InterruptedException {
    WebDriver d = getBrowser();
    loginLogout = PageFactory.initElements(d, LoginLogoutMethods.class);
    general = PageFactory.initElements(d, WebCommonMethods.class);// initiating the driver and the .class file (the pageObject script)       

    WebCommonMethods.openURL();/*w w  w.  j  a va 2s. com*/

    System.out.println("Checking for LogoutAndSessionExpiresOnBackButton test...");
    LoginLogoutMethods.login("admin");
    Thread.sleep(4000);
    LoginLogoutMethods.logout();

    //session expiry check
    d.navigate().back();
    //System.out.println("Current URL: " + d.getCurrentUrl());
    Assert.assertEquals(d.getCurrentUrl(),
            "http://localhost/orangehrm-3.1.2/orangehrm-3.1.2/symfony/web/index.php/pim/viewEmployeeList");

    Cell[] loginPageLabels = WebCommonMethods.readExcelNextRowOfUniqueValue("webTabsWithSubheading",
            "#loginPage");
    Assert.assertEquals(LoginLogoutMethods.loginPanelHeadingLabel.getText(), loginPageLabels[1].getContents());
}

From source file:wsattacker.sso.openid.attacker.evaluation.attack.KeyConfusionAttack.java

License:Open Source License

@Attack(number = 1)
private AttackResult performSecondVariantOfKeyConfusionAttack() {
    OpenIdServerConfiguration.getAttackerInstance().setInterceptIdPResponse(true);
    OpenIdServerConfiguration.getAttackerInstance().setMethodGet(false);

    OpenIdServerConfiguration.getAnalyzerInstance().setInterceptIdPResponse(true);
    OpenIdServerConfiguration.getAnalyzerInstance().setMethodGet(false);

    OpenIdServerConfiguration.getAttackerInstance().setPerformAttack(true);

    String victimIdp = OpenIdServerConfiguration.getAnalyzerInstance().getXrdsConfiguration().getBaseUrl();

    AttackParameter opEndpointParameter = keeper.getParameter("openid.op_endpoint");
    opEndpointParameter.setAttackValueUsedForSignatureComputation(true);
    opEndpointParameter.setValidMethod(HttpMethod.DO_NOT_SEND);
    opEndpointParameter.setAttackMethod(HttpMethod.GET);
    opEndpointParameter.setAttackValue(victimIdp);

    String victimIdentity = OpenIdServerConfiguration.getAnalyzerInstance().getXrdsConfiguration()
            .getIdentity();/*from  w  w w.  j av  a2 s. com*/

    AttackParameter claimedIdParameter = keeper.getParameter("openid.claimed_id");
    claimedIdParameter.setAttackValueUsedForSignatureComputation(true);
    claimedIdParameter.setValidMethod(HttpMethod.DO_NOT_SEND);
    claimedIdParameter.setAttackMethod(HttpMethod.GET);
    claimedIdParameter.setAttackValue(victimIdentity);

    AttackParameter identityParameter = keeper.getParameter("openid.identity");
    identityParameter.setAttackValueUsedForSignatureComputation(true);
    identityParameter.setValidMethod(HttpMethod.DO_NOT_SEND);
    identityParameter.setAttackMethod(HttpMethod.GET);
    identityParameter.setAttackValue(victimIdentity);

    // include modified parameter in signature
    AttackParameter sigParameter = keeper.getParameter("openid.sig");
    sigParameter.setValidMethod(HttpMethod.DO_NOT_SEND);
    sigParameter.setAttackMethod(HttpMethod.GET);

    // copy log entries before login
    List<RequestLogEntry> logEntriesBeforeLogin = new ArrayList<>(RequestLogger.getInstance().getEntryList());

    LoginResult loginResultAttacker = serviceProvider.login(ServiceProvider.User.ATTACKER);

    WebDriver driver = SeleniumBrowser.getWebDriver();
    JavascriptExecutor jse = (JavascriptExecutor) driver;
    String url = serviceProvider.getUrl();
    jse.executeScript("var win = window.open('" + url + "');");

    List<String> windowhandles = new ArrayList<>(driver.getWindowHandles());
    driver.switchTo().window(windowhandles.get(1));

    LoginResult loginResultVictim = serviceProvider.login(ServiceProvider.User.VICTIM);

    driver.switchTo().window(windowhandles.get(0));

    List<WebElement> links = driver.findElements(By.tagName("a"));
    links.get(1).click();

    /* determines the log entries of the current login procedure:
       logEntries = logEntriesAfterLogin - logEntriesBeforeLogin
       (subtraction of sets) */
    List<RequestLogEntry> logEntriesAfterLogin = RequestLogger.getInstance().getEntryList();
    List<RequestLogEntry> logEntries = (List<RequestLogEntry>) CollectionUtils.subtract(logEntriesAfterLogin,
            logEntriesBeforeLogin);

    // invert order of log - should be chronological
    Collections.reverse(logEntries);

    loginResultAttacker.setScreenshot(SeleniumBrowser.takeScreenshot());
    loginResultAttacker.setLogEntries(logEntries);

    boolean success = serviceProvider.determineAuthenticatedUser(driver.getPageSource(),
            driver.getCurrentUrl()) == User.VICTIM;
    Result result = success ? Result.SUCCESS : Result.FAILURE;
    Interpretation interpretation = success ? Interpretation.CRITICAL : Interpretation.PREVENTED;

    if (loginResultAttacker.hasDirectVerification()) {
        result = Result.NOT_PERFORMABLE;
        interpretation = Interpretation.NEUTRAL;
    }

    assert isSignatureValid(loginResultAttacker) : "Signature is not valid!";

    // close second window
    driver.switchTo().window(windowhandles.get(1)).close();
    driver.switchTo().window(windowhandles.get(0));

    return new AttackResult("Second Variant of Key Confusion", loginResultAttacker, result, interpretation);
}

From source file:wsattacker.sso.openid.attacker.evaluation.strategies.InjectJavaScriptLoginStrategy.java

License:Open Source License

@Override
public LoginResult login(User user, ServiceProvider serviceProvider) {
    // before loginAndDetermineAuthenticatedUser remove all cookies
    SeleniumBrowser.deleteAllCookies();/*from  ww w .j a  v  a2  s.  co m*/

    // copy log entries before login
    List<RequestLogEntry> logEntriesBeforeLogin = new ArrayList<>(RequestLogger.getInstance().getEntryList());

    // open url
    WebDriver driver = SeleniumBrowser.getWebDriver();
    driver.get(serviceProvider.getUrl());

    /* Search the page for the OpenID input field. According to the
       standard it should be called "openid_identifier" but some other
       frequent names are also tried. */
    WebElement element = null;
    String[] possibleNames = { "openid_identifier", "openid", "openID", "openid_url", "openid:url", "user",
            "openid-url", "openid-identifier", "oid_identifier", "ctl00$Column1Area$OpenIDControl1$openid_url",
            "user_input", "openIdUrl" };

    for (String possibleName : possibleNames) {
        try {
            element = driver.findElement(By.name(possibleName));
            System.out.println("Find OpenID field with name: " + possibleName);
            break;
        } catch (NoSuchElementException exception) {
            //System.out.println("Cannot find: " + possibleName);
        }
    }

    // save old XRDS lcoation
    String oldIdentity = OpenIdServerConfiguration.getAttackerInstance().getHtmlConfiguration().getIdentity();

    /* If an input field is found, it is filled with the OpenID identifier.
       Selenium cannot set text of hidden input field, consequently,
       JavaScript is injected which performs this task. */
    if (element != null) {
        JavascriptExecutor jse = (JavascriptExecutor) driver;

        // set text of text field
        switch (user) {
        case VICTIM:
            jse.executeScript("arguments[0].value='" + serviceProvider.getVictimOpenId() + "'", element);
            break;
        case ATTACKER:
            jse.executeScript("arguments[0].value='" + serviceProvider.getAttackerOpenId() + "'", element);
            break;
        case ATTACKER_RANDOM:
            String attackerOpenId = serviceProvider.getAttackerOpenId();

            if (attackerOpenId.endsWith("/")) {
                attackerOpenId = attackerOpenId.substring(0, attackerOpenId.length() - 1);
            }

            String randomAttackerIdentity = attackerOpenId + RandomStringUtils.random(10, true, true);
            OpenIdServerConfiguration.getAttackerInstance().getHtmlConfiguration()
                    .setIdentity(randomAttackerIdentity);
            jse.executeScript("arguments[0].value='" + randomAttackerIdentity + "'", element);
            break;
        }

        // special case: owncloud
        if (driver.getCurrentUrl().contains("owncloud")) {
            // set arbitrary password
            WebElement passwordElement = driver.findElement(By.id("password"));
            passwordElement.clear();
            passwordElement.sendKeys("xyz");

            WebElement submitElement = driver.findElement(By.id("submit"));

            jse.executeScript("var element = arguments[0]; element.removeAttribute('id');", submitElement);
        }

        // submit form
        if (element.isDisplayed()) {
            // element.submit(); // does not work as expected
            element.sendKeys(Keys.RETURN);
        } else {
            jse.executeScript("var element = arguments[0];" + "while(element.tagName != 'FORM') {"
                    + "element = element.parentNode;" + "console.log(element);" + "}" + "element.submit();",
                    element);
        }
    }

    // click on accept in modal alert window (if present)
    try {
        driver.switchTo().alert().accept();
    } catch (NoAlertPresentException ex) {
        // do nothing
    }

    // wait 10 seconds: hopefully, all redirects are performed then
    try {
        Thread.sleep(10000);
    } catch (InterruptedException ex) {
        Logger.getLogger(ServiceProvider.class.getName()).log(Level.SEVERE, null, ex);
    }

    /* determines the log entries of the current login procedure:
       logEntries = logEntriesAfterLogin - logEntriesBeforeLogin
       (subtraction of sets) */
    List<RequestLogEntry> logEntriesAfterLogin = RequestLogger.getInstance().getEntryList();
    List<RequestLogEntry> logEntries = (List<RequestLogEntry>) CollectionUtils.subtract(logEntriesAfterLogin,
            logEntriesBeforeLogin);

    // invert order of log - should be chronological
    Collections.reverse(logEntries);

    File screenshot = SeleniumBrowser.takeScreenshot();
    String pageSource = driver.getPageSource();

    // restore old XRDS location
    OpenIdServerConfiguration.getAttackerInstance().getHtmlConfiguration().setIdentity(oldIdentity);

    return new LoginResult(pageSource, logEntries, screenshot, driver.getCurrentUrl());
}

From source file:xmlparser.XmlConfigReader.java

License:Apache License

private static String stripFragmentFromCurrentURL(WebDriver current_driver) {
    String current_url = current_driver.getCurrentUrl();
    int t = current_url.indexOf("#");

    if (t != -1)/*from w  w w  .j  a  v  a  2  s. c om*/
        return current_url.substring(0, t);
    else
        return current_url;
}

From source file:xmv.solutions.IT2JZ.Jira.Jira.java

/**
 * Tests if the Test Create Page is opened
 *
 * @return result of test//from  w ww . j a  v a 2 s. c o  m
 */
public boolean testCreatePageOpened() {
    try {

        // Wait until CreateIssueLayerIsReady
        (new WebDriverWait(browserSession, waitTimoutLength)).until(new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver browserSession) {
                return browserSession.findElement(By.id(CREATE_ISSUE_TYPE__ID)).getText()
                        .contains(CREATE_ISSUE_TYPE__EXPECTED_CONTENT);
            }
        });

        // Save URL
        try {
            urlTestCreatePage = new URL(browserSession.getCurrentUrl());
        } catch (Exception e) {
            return false;
        }

        return true;

    } catch (Exception e) {

        urlTestCreatePage = null;
        return false;
    }
}

From source file:zz.pseas.ghost.login.taobao.LogInTaobaoWebDriver.java

License:Apache License

public static void main(String[] args) throws InterruptedException {
    WebDriver ie = BrowserFactory.getIE();
    ie.get("https://login.taobao.com/member/login.jhtml");

    Thread.sleep(5000);//from   w  w  w .  java 2s.co  m

    String tbuserNmae = "TBname";
    String tbpassWord = "TBpasssword";

    WebElement btn = ie.findElement(By.id("J_Quick2Static"));
    if (btn != null && btn.isDisplayed()) {
        btn.click();
    }

    ie.findElement(By.id("TPL_username_1")).clear();
    ie.findElement(By.id("TPL_username_1")).sendKeys(tbuserNmae);

    ie.findElement(By.id("TPL_password_1")).clear();
    ie.findElement(By.id("TPL_password_1")).sendKeys(tbpassWord);

    ie.findElement(By.id("J_SubmitStatic")).click();

    Thread.sleep(10000L);

    String html = ie.getPageSource();

    System.out.println(html);
    String url = ie.getCurrentUrl();
    System.out.println(url);
    /*WebElement phoneCheck = ie.findElement(By.id("J_GetCode"));
    if(phoneCheck!=null && phoneCheck.isDisplayed()){
       WebElement btn2 = ie.findElement(By.id("J_GetCode"));
       btn2.click();
    }*/

    //Thread.sleep(5000);

}