Search in sources :

Example 51 with Cookie

use of org.openqa.selenium.Cookie in project selenified by Coveros.

the class ActionGoIT method setCookieTest.

@Test(groups = { "integration", "actions", "go" }, description = "An integration test to check the setCookie method")
public void setCookieTest(ITestContext context) throws IOException, ParseException {
    String dateval = "2011-11-17T09:52:13";
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    df.setTimeZone(TimeZone.getTimeZone("UTC"));
    Cookie cookie = new Cookie("new_cookie", "this_cookie", getTestSite(this.getClass().getName(), context).split("/")[2].split(":")[0], "/", df.parse(dateval));
    // use this object to manipulate the app
    App app = this.apps.get();
    // perform some actions
    app.setCookie(cookie);
    // verify no issues
    finish();
}
Also used : Cookie(org.openqa.selenium.Cookie) App(com.coveros.selenified.application.App) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.testng.annotations.Test)

Example 52 with Cookie

use of org.openqa.selenium.Cookie in project java.webdriver by sayems.

the class StoreCookieInfo method main.

public static void main(String... args) {
    WebDriver driver = new FirefoxDriver();
    driver.get("http://www.facebook.com");
    driver.findElement(By.name("email")).sendKeys("<<ur mailID>>");
    driver.findElement(By.name("pass")).sendKeys("<<ur password>>");
    driver.findElement(By.name("persistent")).click();
    driver.findElement(By.name("pass")).submit();
    File f = new File("browser.data");
    try {
        f.delete();
        f.createNewFile();
        FileWriter fos = new FileWriter(f);
        BufferedWriter bos = new BufferedWriter(fos);
        for (Cookie ck : driver.manage().getCookies()) {
            bos.write((ck.getName() + ";" + ck.getValue() + ";" + ck.getDomain() + ";" + ck.getPath() + ";" + ck.getExpiry() + ";" + ck.isSecure()));
            bos.newLine();
        }
        bos.flush();
        bos.close();
        fos.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Cookie(org.openqa.selenium.Cookie) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FileWriter(java.io.FileWriter) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 53 with Cookie

use of org.openqa.selenium.Cookie in project ats-framework by Axway.

the class PhantomJsDriver method getHttpOnlyCookies.

public static List<Cookie> getHttpOnlyCookies() {
    List<Cookie> cookies = new ArrayList<Cookie>();
    if (System.getProperty(PhantomJsDriver.HTTP_ONLY_COOKIES_PROPERTY) != null) {
        String[] cookieNames = System.getProperty(PhantomJsDriver.HTTP_ONLY_COOKIES_PROPERTY).split(",");
        try {
            String cookiesFileContent = IoUtils.streamToString(IoUtils.readFile(PhantomJsDriver.cookiesFile));
            for (String cookieName : cookieNames) {
                int cookieIndex = cookiesFileContent.indexOf(cookieName + "=");
                if (cookieIndex >= 0) {
                    int endIndex = cookiesFileContent.indexOf("\\0", cookieIndex);
                    if (endIndex < 0) {
                        endIndex = cookiesFileContent.indexOf(')', cookieIndex);
                    }
                    String wholeCookieData = cookiesFileContent.substring(cookieIndex, endIndex);
                    String[] cookieParts = wholeCookieData.split(";\\s+");
                    String value = cookieParts[0].substring(cookieParts[0].indexOf('=') + 1);
                    String path = null;
                    String domain = null;
                    boolean isSecure = false;
                    for (String cp : cookieParts) {
                        if ("secure".equalsIgnoreCase(cp)) {
                            isSecure = true;
                        } else if (cp.startsWith("path=")) {
                            path = cp.substring(cp.indexOf('=') + 1);
                        } else if (cp.startsWith("domain=")) {
                            domain = cp.substring(cp.indexOf('=') + 1);
                        }
                    }
                    cookies.add(new Cookie(cookieName, value, domain, path, null, isSecure));
                }
            }
        } catch (Exception e) {
            log.error("Couldn't parse HttpOnly cookeis, from the temp file: " + cookiesFile, e);
        }
    }
    return cookies;
}
Also used : Cookie(org.openqa.selenium.Cookie) ArrayList(java.util.ArrayList)

Example 54 with Cookie

use of org.openqa.selenium.Cookie in project selenium_java by sergueik.

the class GoogleDriveTest method getCookieTest.

// @Ignore
@Test
public void getCookieTest() throws Exception {
    doLogin();
    Set<Cookie> cookies = driver.manage().getCookies();
    if (debug) {
        System.err.println("Cookies:");
    }
    JSONArray cookieJSONArray = new JSONArray();
    for (Cookie cookie : cookies) {
        if (debug) {
            System.err.println(formatter.format("Name: '%s'\n" + "Value: '%s'\n" + "Domain: '%s'\n" + "Path: '%s'\n" + "Expiry: '%tc'\n" + "Secure: '%b'\n" + "HttpOnly: '%b'\n" + "\n", cookie.getName(), cookie.getValue(), cookie.getDomain(), cookie.getPath(), cookie.getExpiry(), cookie.isSecure(), cookie.isHttpOnly()).toString());
        }
        JSONObject cookieJSONObject = new JSONObject(cookie);
        if (debug) {
            System.err.println(cookieJSONObject.toString());
        }
        cookieJSONArray.put(cookieJSONObject);
    }
    JSONObject cookiesJSONObject = new JSONObject();
    cookiesJSONObject.put("cookies", cookieJSONArray);
    if (debug) {
        System.err.println(cookiesJSONObject.toString());
    }
    doLogout();
}
Also used : Cookie(org.openqa.selenium.Cookie) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Test(org.junit.Test)

Example 55 with Cookie

use of org.openqa.selenium.Cookie in project selenium_java by sergueik.

the class YandexTest method useCookieTest.

// @Ignore
@Test
public void useCookieTest() throws Exception {
    String loginUrl = doLogin();
    System.err.println("Getting the cookies");
    Set<Cookie> cookies = driver.manage().getCookies();
    System.err.println("Closing the browser");
    wait = null;
    System.err.println("re-open the browser, about to use the session cookies");
    driver.close();
    driver = new FirefoxDriver();
    // re-initialize wait object
    wait = new WebDriverWait(driver, flexibleWait);
    wait.pollingEvery(polling, TimeUnit.MILLISECONDS);
    System.err.println("Navigating to " + loginUrl);
    driver.get(loginUrl);
    System.err.println("Loading cookies");
    for (Cookie cookie : cookies) {
        driver.manage().addCookie(cookie);
    }
    driver.navigate().refresh();
    System.err.println("Waiting for inbox");
    try {
        wait.until(ExpectedConditions.urlContains("#inbox"));
    } catch (TimeoutException | UnreachableBrowserException e) {
        verificationErrors.append(e.toString());
    }
    doLogout();
}
Also used : Cookie(org.openqa.selenium.Cookie) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) UnreachableBrowserException(org.openqa.selenium.remote.UnreachableBrowserException) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) TimeoutException(org.openqa.selenium.TimeoutException) Test(org.junit.Test)

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