Search in sources :

Example 46 with Cookie

use of org.openqa.selenium.Cookie in project oxAuth by GluuFederation.

the class BaseTest method waitForResourceOwnerAndGrantLoginForm.

/**
     * Try to open login form (via the user-agent)
     */
public String waitForResourceOwnerAndGrantLoginForm(String authorizeUrl, AuthorizationRequest authorizationRequest, boolean cleanupCookies) {
    String authorizationRequestUrl = authorizeUrl + "?" + authorizationRequest.getQueryString();
    AuthorizeClient authorizeClient = new AuthorizeClient(authorizeUrl);
    authorizeClient.setRequest(authorizationRequest);
    System.out.println("waitForResourceOwnerAndGrantLoginForm: authorizationRequestUrl:" + authorizationRequestUrl);
    startSelenium();
    if (cleanupCookies) {
        System.out.println("waitForResourceOwnerAndGrantLoginForm: Cleaning cookies");
        deleteAllCookies();
    }
    driver.navigate().to(authorizationRequestUrl);
    WebElement usernameElement = driver.findElement(By.name(loginFormUsername));
    WebElement passwordElement = driver.findElement(By.name(loginFormPassword));
    WebElement loginButton = driver.findElement(By.name(loginFormLoginButton));
    if ((usernameElement == null) || (passwordElement == null) || (loginButton == null)) {
        return null;
    }
    Cookie sessionStateCookie = driver.manage().getCookieNamed("session_state");
    String sessionState = null;
    if (sessionStateCookie != null) {
        sessionState = sessionStateCookie.getValue();
    }
    System.out.println("waitForResourceOwnerAndGrantLoginForm: sessionState:" + sessionState);
    stopSelenium();
    showClientUserAgent(authorizeClient);
    return sessionState;
}
Also used : Cookie(org.openqa.selenium.Cookie) WebElement(org.openqa.selenium.WebElement)

Example 47 with Cookie

use of org.openqa.selenium.Cookie in project oxAuth by GluuFederation.

the class BaseTest method authenticateResourceOwnerAndGrantAccess.

/**
     * The authorization server authenticates the resource owner (via the user-agent)
     * and establishes whether the resource owner grants or denies the client's access request.
     */
public AuthorizationResponse authenticateResourceOwnerAndGrantAccess(String authorizeUrl, AuthorizationRequest authorizationRequest, String userId, String userSecret, boolean cleanupCookies) {
    String authorizationRequestUrl = authorizeUrl + "?" + authorizationRequest.getQueryString();
    AuthorizeClient authorizeClient = new AuthorizeClient(authorizeUrl);
    authorizeClient.setRequest(authorizationRequest);
    System.out.println("authenticateResourceOwnerAndGrantAccess: authorizationRequestUrl:" + authorizationRequestUrl);
    startSelenium();
    if (cleanupCookies) {
        System.out.println("authenticateResourceOwnerAndGrantAccess: Cleaning cookies");
        deleteAllCookies();
    }
    driver.navigate().to(authorizationRequestUrl);
    if (userSecret != null) {
        if (userId != null) {
            WebElement usernameElement = driver.findElement(By.name(loginFormUsername));
            usernameElement.sendKeys(userId);
        }
        WebElement passwordElement = driver.findElement(By.name(loginFormPassword));
        passwordElement.sendKeys(userSecret);
        WebElement loginButton = driver.findElement(By.name(loginFormLoginButton));
        loginButton.click();
    }
    String authorizationResponseStr = driver.getCurrentUrl();
    WebElement allowButton = driver.findElement(By.name(authorizeFormAllowButton));
    final String previousURL = driver.getCurrentUrl();
    allowButton.click();
    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(new ExpectedCondition<Boolean>() {

        public Boolean apply(WebDriver d) {
            return (d.getCurrentUrl() != previousURL);
        }
    });
    authorizationResponseStr = driver.getCurrentUrl();
    Cookie sessionStateCookie = driver.manage().getCookieNamed("session_state");
    String sessionState = null;
    if (sessionStateCookie != null) {
        sessionState = sessionStateCookie.getValue();
    }
    System.out.println("authenticateResourceOwnerAndGrantAccess: sessionState:" + sessionState);
    stopSelenium();
    AuthorizationResponse authorizationResponse = new AuthorizationResponse(authorizationResponseStr);
    if (authorizationRequest.getRedirectUri() != null && authorizationRequest.getRedirectUri().equals(authorizationResponseStr)) {
        authorizationResponse.setResponseMode(ResponseMode.FORM_POST);
    }
    authorizeClient.setResponse(authorizationResponse);
    showClientUserAgent(authorizeClient);
    return authorizationResponse;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Cookie(org.openqa.selenium.Cookie) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) WebElement(org.openqa.selenium.WebElement)

Example 48 with Cookie

use of org.openqa.selenium.Cookie in project SneakerBot by Penor.

the class Adidas method splash.

@SuppressWarnings("deprecation")
public void splash() {
    try {
        WebDriverWait wait = new WebDriverWait(driver, 60L);
        print("Loading webpage: " + url);
        driver.get(url);
        wait.until(new Function<WebDriver, Boolean>() {

            public Boolean apply(WebDriver d) {
                // + String.valueOf(((JavascriptExecutor) d).executeScript("return document.readyState")));
                return String.valueOf(((JavascriptExecutor) d).executeScript("return document.readyState")).equals("complete");
            }
        });
        // TODO: Get to splash page.
        boolean displayed = wait.until(x -> x.findElement(By.className("sk-fading-circle"))).isDisplayed();
        if (displayed) {
            print(proxy != null ? ("[" + proxy.getPassword() + ":" + proxy.getPort() + "] -> ") : "" + "waiting at splash page!");
            while (driver.findElements(By.className("g-recaptcha")).size() == 0) Thread.sleep(5000L);
            print(proxy != null ? ("[" + proxy.getPassword() + ":" + proxy.getPort() + "] -> ") : "" + "passed splash page!");
            driver.manage().getCookies().stream().forEach(c -> {
                if (c.getValue().contains("hmac")) {
                    hmac = c.getValue();
                    hmacExpiration = c.getExpiry();
                }
            });
            if (driver.findElements(By.className("g-recaptcha")).size() > 0)
                siteKey = driver.findElement(By.className("g-recaptcha")).getAttribute("data-sitekey");
            if (driver.findElements(By.id("flashproductform")).size() > 0)
                clientId = driver.findElement(By.id("flashproductform")).getAttribute("action").split("clientId=")[1];
            Date timeLeft = new Date(hmacExpiration.getTime() - System.currentTimeMillis());
            print("[Success] -> SiteKey: " + siteKey + " Client ID: " + clientId + " HMAC: " + hmac + " Time Left: " + timeLeft.getMinutes() + "m" + timeLeft.getSeconds() + "s");
        } else
            print("Error, Element displayed: " + displayed);
        if (manual) {
            FirefoxProfile profile = new FirefoxProfile();
            if (proxy != null) {
                profile.setPreference("network.proxy.type", 1);
                profile.setPreference("network.proxy.http", proxy.getAddress());
                profile.setPreference("network.proxy.http_port", proxy.getPort());
                profile.setPreference("network.proxy.ssl", proxy.getAddress());
                profile.setPreference("network.proxy.ssl_port", proxy.getPort());
            }
            // profile.setPreference("general.useragent.override", driver.set);
            WebDriver checkout = new FirefoxDriver(profile);
            for (Cookie cookie : driver.manage().getCookies()) checkout.manage().addCookie(cookie);
            checkout.get(driver.getCurrentUrl());
        } else
            while (!carted && hmacExpiration.getTime() > System.currentTimeMillis()) atc();
    } catch (Exception e) {
        String name = e.getClass().getName();
        print("[Exception] -> " + name);
        carted = true;
        if (name.equals("org.openqa.selenium.TimeoutException"))
            carted = false;
    } finally {
        print(carted ? "Closing driver, and ending" : "Failed, Retrying...");
        if (carted) {
            driver.quit();
            Thread.currentThread().interrupt();
        }
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ProxyConfig(com.machinepublishers.jbrowserdriver.ProxyConfig) CredentialObject(main.java.sneakerbot.loaders.Credentials.CredentialObject) Settings(com.machinepublishers.jbrowserdriver.Settings) ExpectedConditions(org.openqa.selenium.support.ui.ExpectedConditions) Date(java.util.Date) JBrowserDriver(com.machinepublishers.jbrowserdriver.JBrowserDriver) By(org.openqa.selenium.By) WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) Random(java.util.Random) Type(com.machinepublishers.jbrowserdriver.ProxyConfig.Type) Function(java.util.function.Function) Builder(com.machinepublishers.jbrowserdriver.Settings.Builder) Level(java.util.logging.Level) TimeUnit(java.util.concurrent.TimeUnit) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) UserAgent(com.machinepublishers.jbrowserdriver.UserAgent) Cookie(org.openqa.selenium.Cookie) ProxyObject(main.java.sneakerbot.loaders.Proxy.ProxyObject) Cookie(org.openqa.selenium.Cookie) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) Date(java.util.Date)

Example 49 with Cookie

use of org.openqa.selenium.Cookie in project spring-session by spring-projects.

the class HomePage method terminateButtonDisabled.

public void terminateButtonDisabled() {
    Set<Cookie> cookies = getDriver().manage().getCookies();
    String cookieValue = null;
    for (Cookie cookie : cookies) {
        if ("SESSION".equals(cookie.getName())) {
            cookieValue = new String(Base64.getDecoder().decode(cookie.getValue()));
        }
    }
    WebElement element = getDriver().findElement(By.id("terminate-" + cookieValue));
    assertThat(element.isEnabled()).isFalse();
}
Also used : Cookie(org.openqa.selenium.Cookie) WebElement(org.openqa.selenium.WebElement)

Example 50 with Cookie

use of org.openqa.selenium.Cookie in project xwiki-platform by xwiki.

the class TestUtils method setSession.

public void setSession(Session session) {
    WebDriver.Options options = getDriver().manage();
    options.deleteAllCookies();
    if (session != null) {
        for (Cookie cookie : session.getCookies()) {
            options.addCookie(cookie);
        }
    }
    if (session != null && !StringUtils.isEmpty(session.getSecretToken())) {
        this.secretToken = session.getSecretToken();
    } else {
        recacheSecretToken();
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Cookie(org.openqa.selenium.Cookie)

Aggregations

Cookie (org.openqa.selenium.Cookie)73 Test (org.junit.Test)26 WebElement (org.openqa.selenium.WebElement)16 WebDriver (org.openqa.selenium.WebDriver)14 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)9 Date (java.util.Date)8 App (com.coveros.selenified.application.App)7 IOException (java.io.IOException)7 AbstractKeycloakTest (org.keycloak.testsuite.AbstractKeycloakTest)7 BasicClientCookie (org.apache.http.impl.cookie.BasicClientCookie)6 Test (org.testng.annotations.Test)6 Collectors (java.util.stream.Collectors)5 BasicCookieStore (org.apache.http.impl.client.BasicCookieStore)5 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)5 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)5 AuthorizeClient (org.gluu.oxauth.client.AuthorizeClient)5 Matchers (org.hamcrest.Matchers)5 Page (org.jboss.arquillian.graphene.page.Page)5 Assert (org.junit.Assert)5 AdminRoles (org.keycloak.models.AdminRoles)5