Example usage for org.openqa.selenium Cookie getExpiry

List of usage examples for org.openqa.selenium Cookie getExpiry

Introduction

In this page you can find the example usage for org.openqa.selenium Cookie getExpiry.

Prototype

public Date getExpiry() 

Source Link

Usage

From source file:io.vertigo.ui.FileDownloader4Tests.java

License:Apache License

/**
 * Load in all the cookies WebDriver currently knows about so that we can mimic the browser cookie state
 *
 * @param seleniumCookieSet//from w w w  . j a v  a2s .  c  o m
 * @return BasicCookieStore
 */
private static BasicCookieStore mimicCookieState(final Set<Cookie> seleniumCookieSet) {
    final BasicCookieStore mimicWebDriverCookieStore = new BasicCookieStore();
    for (final Cookie seleniumCookie : seleniumCookieSet) {
        final BasicClientCookie duplicateCookie = new BasicClientCookie(seleniumCookie.getName(),
                seleniumCookie.getValue());
        duplicateCookie.setDomain(seleniumCookie.getDomain());
        duplicateCookie.setSecure(seleniumCookie.isSecure());
        duplicateCookie.setExpiryDate(seleniumCookie.getExpiry());
        duplicateCookie.setPath(seleniumCookie.getPath());
        mimicWebDriverCookieStore.addCookie(duplicateCookie);
    }

    return mimicWebDriverCookieStore;
}

From source file:net.sourceforge.jwebunit.webdriver.WebDriverTestingEngineImpl.java

License:Open Source License

public List<javax.servlet.http.Cookie> getCookies() {
    List<javax.servlet.http.Cookie> result = new LinkedList<javax.servlet.http.Cookie>();
    Set<Cookie> cookies = driver.manage().getCookies();
    for (Cookie cookie : cookies) {
        javax.servlet.http.Cookie c = new javax.servlet.http.Cookie(cookie.getName(), cookie.getValue());
        c.setDomain(cookie.getDomain());
        Date expire = cookie.getExpiry();
        if (expire == null) {
            c.setMaxAge(-1);// w ww. j  ava 2 s. co m
        } else {
            Date now = Calendar.getInstance().getTime();
            // Convert milli-second to second
            Long second = Long.valueOf((expire.getTime() - now.getTime()) / 1000);
            c.setMaxAge(second.intValue());
        }
        c.setPath(cookie.getPath());
        c.setSecure(cookie.isSecure());
        result.add(c);
    }
    return result;
}

From source file:nz.co.testamation.core.reader.pdf.BrowserCookieHttpContextProvider.java

License:Apache License

@Override
public HttpContext get() {
    BasicHttpContext localContext = new BasicHttpContext();
    Set<Cookie> cookies = browserDriver.getAllCookies();
    BasicCookieStore cookieStore = new BasicCookieStore();

    for (Cookie cookie : cookies) {
        BasicClientCookie clientCookie = new BasicClientCookie(cookie.getName(), cookie.getValue());
        clientCookie.setDomain(cookie.getDomain());
        clientCookie.setPath(cookie.getPath());
        clientCookie.setExpiryDate(cookie.getExpiry());
        cookieStore.addCookie(clientCookie);
    }/*  w ww. j  av  a  2 s . c o m*/
    localContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);
    return localContext;
}

From source file:org.ado.picasa.FileDownloader.java

License:Apache License

private HttpState mimicCookieState(Set<org.openqa.selenium.Cookie> seleniumCookieSet) {
    HttpState mimicWebDriverCookieState = new HttpState();
    for (org.openqa.selenium.Cookie seleniumCookie : seleniumCookieSet) {
        Cookie httpClientCookie = new Cookie(seleniumCookie.getDomain(), seleniumCookie.getName(),
                seleniumCookie.getValue(), seleniumCookie.getPath(), seleniumCookie.getExpiry(),
                seleniumCookie.isSecure());
        mimicWebDriverCookieState.addCookie(httpClientCookie);
    }//from  w  ww.j  a v  a 2s. co m
    return mimicWebDriverCookieState;
}

From source file:org.alfresco.po.share.util.FileDownloader.java

License:Open Source License

/**
 * Loads the cookies from WebDriver to mimic the browser cookie state
 * @return {@link BasicCookieStore} current state
 *//*  w  ww  .  ja v  a  2s  . co m*/
private BasicCookieStore getCookies() {

    BasicCookieStore mimicWebDriverCookie = new BasicCookieStore();
    Set<Cookie> cookies = driver.manage().getCookies();

    for (Cookie seleniumCookie : cookies) {
        BasicClientCookie duplicateCookie = new BasicClientCookie(seleniumCookie.getName(),
                seleniumCookie.getValue());
        duplicateCookie.setDomain(seleniumCookie.getDomain());
        duplicateCookie.setSecure(seleniumCookie.isSecure());
        duplicateCookie.setExpiryDate(seleniumCookie.getExpiry());
        duplicateCookie.setPath(seleniumCookie.getPath());
        mimicWebDriverCookie.addCookie(duplicateCookie);
    }
    return mimicWebDriverCookie;
}

From source file:org.alfresco.selenium.FetchHttpClient.java

License:Open Source License

/**
 * Prepare the client cookie based on the authenticated {@link WebDriver} 
 * cookie. /*ww  w. j  a v  a  2  s  .c om*/
 * @param driver {@link WebDriver}
 * @return BasicClientCookie with correct credentials.
 */
public static BasicClientCookie generateSessionCookie(WebDriver driver) {
    Cookie originalCookie = driver.manage().getCookieNamed("JSESSIONID");
    if (originalCookie == null) {
        return null;
    }
    // just build new apache-like cookie based on webDriver's one
    String cookieName = originalCookie.getName();
    String cookieValue = originalCookie.getValue();
    BasicClientCookie resultCookie = new BasicClientCookie(cookieName, cookieValue);
    resultCookie.setDomain(originalCookie.getDomain());
    resultCookie.setExpiryDate(originalCookie.getExpiry());
    resultCookie.setPath(originalCookie.getPath());
    return resultCookie;
}

From source file:org.cerberus.service.engine.impl.WebDriverService.java

License:Open Source License

@Override
public String getFromCookie(Session session, String cookieName, String cookieParameter) {
    Cookie cookie = session.getDriver().manage().getCookieNamed(cookieName);
    if (cookie != null) {
        if (cookieParameter.equals("name")) {
            return cookie.getName();
        }/*from  w w  w .j av a2  s. c  om*/
        if (cookieParameter.equals("expiry")) {
            return cookie.getExpiry().toString();
        }
        if (cookieParameter.equals("value")) {
            return cookie.getValue();
        }
        if (cookieParameter.equals("domain")) {
            return cookie.getDomain();
        }
        if (cookieParameter.equals("path")) {
            return cookie.getPath();
        }
        if (cookieParameter.equals("isHttpOnly")) {
            return String.valueOf(cookie.isHttpOnly());
        }
        if (cookieParameter.equals("isSecure")) {
            return String.valueOf(cookie.isSecure());
        }
    } else {
        return "cookieNotFound";
    }
    return null;
}

From source file:renascere.Renascere.java

License:Open Source License

/**
 * @Description Method that gets current browser cookies and veries it number based on the inputs
 * @param driver -- Browser object to be used to gather the information
 * @param numberCookies  -- Expected number of cookies expected. 
 *//*from w  w w. ja va  2 s  .c  om*/
public static void checkCookies(WebDriver driver, int numberCookies) {
    //Getting cookies information
    Set<Cookie> seleniumCookies = driver.manage().getCookies();
    int currentCookies = driver.manage().getCookies().size();
    if (currentCookies == numberCookies) {
        logMessage(result.PASS, "Number of cookies is correct (" + currentCookies + ").");
        for (Cookie seleniumCookie : seleniumCookies) {
            logMessage(result.INFO,
                    "c.Name: " + seleniumCookie.getName() + " ||| c.Value: " + seleniumCookie.getValue()
                            + " ||| c.Domain: " + seleniumCookie.getDomain() + " ||| c.Path: "
                            + seleniumCookie.getPath() + " ||| c.Expiry: " + seleniumCookie.getExpiry()
                            + " ||| c.Class: " + seleniumCookie.getClass());
        }
    } else {
        logMessage(result.WARNING, "Number of cokkies is not the expected: " + currentCookies);
    }
}

From source file:webtest.Test1.java

public void runTest1() {

    List<String> ouList = new ArrayList<>();

    int count = 0;
    try {/*from www .  ja  v  a  2s .c o  m*/
        BufferedReader in;
        in = new BufferedReader(
                new FileReader("C:\\Users\\hallm8\\Documents\\NetBeansProjects\\WebTest\\src\\webtest\\OU"));
        String str;

        while ((str = in.readLine()) != null) {
            ouList.add(str);
        }

    } catch (FileNotFoundException ex) {
        Logger.getLogger(Test1.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Test1.class.getName()).log(Level.SEVERE, null, ex);
    }

    FirefoxProfile fp = new FirefoxProfile(
            new File("C:\\Users\\hallm8\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\tiu8eb0h.default"));
    fp.setPreference("webdriver.load.strategy", "unstable");
    WebDriver driver = new FirefoxDriver(fp);

    driver.manage().window().maximize();
    driver.get("http://byui.brightspace.com/d2l/login?noredirect=true");
    WebElement myDynamicElement = (new WebDriverWait(driver, 60))
            .until(ExpectedConditions.presenceOfElementLocated(By.id("d2l_minibar_placeholder")));

    // times out after 60 seconds
    Actions actions = new Actions(driver);
    for (String ouList1 : ouList) {
        WebDriverWait wait = new WebDriverWait(driver, 60);
        /**
         * PULLING VALENCE REQUESTS
         *
         * Step 1: Open up Selenium and authenticate by having the user sign
         * in. This bypasses the Authorization Protection
         *
         * Step 2: Open up HTTP Client and pass the cookies into it.
         *
         * Step 3: Open up the JSON parser of your choosing and parse into
         * it!
         */

        try {

            Set<Cookie> seleniumCookies = driver.manage().getCookies();
            CookieStore cookieStore = new BasicCookieStore();

            for (Cookie seleniumCookie : seleniumCookies) {
                BasicClientCookie basicClientCookie = new BasicClientCookie(seleniumCookie.getName(),
                        seleniumCookie.getValue());
                basicClientCookie.setDomain(seleniumCookie.getDomain());
                basicClientCookie.setExpiryDate(seleniumCookie.getExpiry());
                basicClientCookie.setPath(seleniumCookie.getPath());
                cookieStore.addCookie(basicClientCookie);
            }
            HttpClient httpClient = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();
            HttpGet request = new HttpGet(
                    "https://byui.brightspace.com/d2l/api/le/1.7/" + ouList1 + "/content/toc");
            request.addHeader("accept", "application/json");
            HttpResponse response = httpClient.execute(request);
            HttpEntity entity = response.getEntity();

            String jsonString = EntityUtils.toString(response.getEntity());

            JSONObject obj = new JSONObject(jsonString);
            JSONArray modules = obj.getJSONArray("Modules");
            System.out.println(jsonString);

            for (int i = 0; i < modules.length(); i++) {
                if (modules.getJSONObject(i).has("Modules")) {
                    modules.put(modules.getJSONObject(i).getJSONArray("Modules"));
                }

                System.out.println(modules.get(i));
                JSONArray topics = modules.getJSONObject(i).getJSONArray("Topics");
                for (int j = 0; j < topics.length(); j++) {
                    JSONObject topic = topics.getJSONObject(j);
                    System.out.println(topic.get("Title"));
                }
            }
            JSONArray jsonArray = new JSONArray();
            JSONObject jsonObject = new JSONObject();

            /**
             * This covers Dropbox Folders
             *
             * System.out.println(ouList1);
             * driver.get("https://byui.brightspace.com/d2l/lms/dropbox/admin/folders_manage.d2l?ou="
             * + ouList1); driver.manage().timeouts().implicitlyWait(3,
             * TimeUnit.SECONDS);
             *
             * List<WebElement> links =
             * driver.findElements(By.xpath("//a[contains(@href,
             * '/d2l/lms/dropbox/admin/mark/')]"));
             *
             * ArrayList<String> dropBoxes = new ArrayList<>();
             *
             * System.out.println(links.size()); for (WebElement link :
             * links) {
             *
             * System.out.println(link.getAttribute("href")); if
             * (link.getAttribute("href") != null &&
             * link.getAttribute("href").contains("/d2l/lms/dropbox/admin/mark/"))
             * {
             * dropBoxes.add(link.getAttribute("href").replace("mark/folder_submissions_users",
             * "modify/folder_newedit_properties"));
             * System.out.println("successfully pulled: " +
             * link.getAttribute("href")); } }
             *
             * for (int j = 0; j < dropBoxes.size(); j++) { String dropBox =
             * dropBoxes.get(j); driver.get(dropBox);
             *
             * if (!driver.findElements(By.linkText("Show Submission
             * Options")).isEmpty()) { driver.findElement(By.linkText("Show
             * Submission Options")).click();
             * driver.manage().timeouts().implicitlyWait(1800,
             * TimeUnit.SECONDS); }
             *
             * if (driver.findElement(By.id("z_cd")).isSelected()) {
             * //((JavascriptExecutor)
             * driver).executeScript("arguments[0].scrollIntoView(true);",
             * driver.findElement(By.id("z_ce")));
             * actions.moveToElement(driver.findElement(By.id("z_ce"))).click().perform();
             * actions.moveToElement(driver.findElement(By.id("z_ci"))).click().perform();
             * driver.findElement(By.id("z_c")).click();
             * driver.manage().timeouts().implicitlyWait(3,
             * TimeUnit.SECONDS); } }
             *
             * // Response response = json.fromJson(, Response.class) /**
             * This covers content.
             */
            /*
            driver.get("https://byui.brightspace.com/d2l/le/content/9730/Home");
            driver.manage().timeouts().pageLoadTimeout(1800, TimeUnit.SECONDS);
                    
            List<WebElement> dragElement = driver.findElements(By.xpath("//div[contains(@id,'TreeItem')]//div[contains(@class, 'd2l-textblock')]"));
            /*
            for (int i = 4; i < dragElement.size(); i++) {
                    
            WebElement drag = dragElement.get(i);
                    
                    
            drag.click();
                    
            wait.until(ExpectedConditions.elementToBeClickable(drag));
            /*
            driver.manage().timeouts().pageLoadTimeout(1800, TimeUnit.SECONDS);
            System.out.println(driver.findElement(By.xpath("//h1[contains(@class, 'd2l-page-title d2l-heading vui-heading-1')]")).getText());
            (new WebDriverWait(driver, 60)).until(new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver d) {
            return drag.getText().contains(d.findElement(By.xpath("//h1[contains(@class, 'd2l-page-title d2l-heading vui-heading-1')]")).getText());
            }
            });
                    
                    
            try {
            // while the following loop runs, the DOM changes -
            // page is refreshed, or element is removed and re-added
            // This took me forever to figure out!!!
            Thread.sleep(2000);
            } catch (InterruptedException ex) {
            Logger.getLogger(Test1.class.getName()).log(Level.SEVERE, null, ex);
            }
                    
                    
            List<WebElement> contentItems = driver.findElements(By.className("d2l-fuzzydate"));
                    
            for (int k = 1; k < contentItems.size(); k++) {
            WebElement content = contentItems.get(k);
            wait.until(presenceOfElementLocated(By.className(content.getAttribute("class"))));
            WebElement parent1 = content.findElement(By.xpath(".."));
            System.out.println(parent1.getTagName());
            WebElement parent2 = parent1.findElement(By.xpath(".."));
            System.out.println(parent2.getTagName());
            WebElement parent3 = parent2.findElement(By.xpath(".."));
            System.out.println(parent3.getTagName());
            WebElement parent4 = parent3.findElement(By.xpath(".."));
            System.out.println(parent4.getTagName());
            WebElement parent5 = parent4.findElement(By.xpath(".."));
            System.out.println(parent5.getTagName());
            WebElement parent6 = parent5.findElement(By.xpath(".."));
            System.out.println(parent6.getTagName());
            //System.out.println(parent5.getText());
            System.out.println(parent6.getAttribute("title"));
            }
                    
            }
             */
            /**
             * This covers quizzes
             */
            /*
            driver.get("https://byui.brightspace.com/d2l/lms/quizzing/admin/quizzes_manage.d2l?ou=" + ouList1);
            driver.manage().timeouts().pageLoadTimeout(1800, TimeUnit.SECONDS);
                    
            List<WebElement> links = driver.findElements(By.className("vui-outline"));
                    
            ArrayList<String> quizzes = new ArrayList<>();
                    
            for (WebElement link : links) {
            if (link.getAttribute("href") != null && link.getAttribute("href").contains("byui.brightspace.com/d2l/lms/quizzing/admin/modify")) {
            quizzes.add(link.getAttribute("href"));
            System.out.println("successfully pulled: " + link.getAttribute("href"));
                    
            }
            }
                    
            for (int j = 0; j < quizzes.size(); j++) {
            String quiz = quizzes.get(j);
            boolean isLA = false;
            driver.get(quiz);
            driver.manage().timeouts().pageLoadTimeout(1800, TimeUnit.SECONDS);
                    
            if (!driver.findElements(By.linkText("Expand optional advanced properties")).isEmpty()) {
            driver.findElement(By.linkText("Expand optional advanced properties")).click();
            driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
                    
            }
                    
            if (driver.findElement(By.name("disableRightClick")).isSelected()) {
            ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", driver.findElement(By.name("disableRightClick")));
            driver.findElement(By.name("disableRightClick")).click();
            driver.findElement(By.id("z_b")).click();
            driver.manage().timeouts().pageLoadTimeout(1800, TimeUnit.SECONDS);
            count++;
            }
                    
            List<WebElement> labels = driver.findElements(By.tagName("label"));
            for (WebElement label : labels) {
            if (label.getText().contains("LA")) {
            isLA = true;
            break;
            }
            }
                    
            driver.findElement(By.id("z_h_Assessment_l")).click();
            driver.manage().timeouts().pageLoadTimeout(1800, TimeUnit.SECONDS);
                    
            if (driver.findElement(By.name("autoExportGrades")).isSelected()
            && isLA == true) {
            driver.findElement(By.name("autoExportGrades")).click();
            count++;
            }
                    
            if (driver.findElement(By.name("autoSetGraded")).isSelected()
            && isLA == true) {
            driver.findElement(By.name("autoSetGraded")).click();
            count++;
            }
                    
            if (!driver.findElement(By.name("autoSetGraded")).isSelected()
            && isLA == false) {
            driver.findElement(By.name("autoSetGraded")).click();
            count++;
                    
            }
                    
            if (!driver.findElement(By.name("autoExportGrades")).isSelected()
            && isLA == false) {
            driver.findElement(By.name("autoExportGrades")).click();
            count++;
            }
                    
            driver.findElement(By.id("z_b")).click();
            driver.manage().timeouts().pageLoadTimeout(1800, TimeUnit.SECONDS);
                    
            System.out.println("count is: " + count);
                    
            /**
            *
            * Submission Views
            *
             */
            /*
                           driver.findElement(By.linkText("Submission Views")).click();
                           driver.manage().timeouts().pageLoadTimeout(1800, TimeUnit.SECONDS);
                                   
                           driver.findElement(By.linkText("Default View")).click();
                           driver.manage().timeouts().pageLoadTimeout(1800, TimeUnit.SECONDS);
                                   
                           if (!driver.findElement(By.name("showQuestions")).isSelected()) {
                           System.out.println("show answers clicked!!!  URL: " + quiz);
                           driver.findElement(By.name("showQuestions")).click();
                           }
                                   
                           if (!driver.findElement(By.id("z_p")).isSelected()) {
                           driver.findElement(By.id("z_p")).click();
                           }
                           if (!driver.findElement(By.name("showCorrectAnswers")).isSelected()) {
                           driver.findElement(By.name("showCorrectAnswers")).click();
                           }
                           if (!driver.findElement(By.name("showQuestionScore")).isSelected()) {
                           driver.findElement(By.name("showQuestionScore")).click();
                           }
                           if (!driver.findElement(By.name("showScore")).isSelected()) {
                           driver.findElement(By.name("showScore")).click();
                           }
                                   
                           driver.findElement(By.id("z_a")).click();
                            */
            //}
            /**
             * This covers content.
             */
            /*
            driver.get("https://byui.brightspace.com/d2l/le/content/9730/Home");
            driver.manage().timeouts().pageLoadTimeout(1800, TimeUnit.SECONDS);
                    
            List<WebElement> dragElement = driver.findElements(By.xpath("//div[contains(@id,'TreeItem')]//div[contains(@class, 'd2l-textblock')]"));
            /*
            for (int i = 4; i < dragElement.size(); i++) {
                    
            WebElement drag = dragElement.get(i);
                    
                    
            drag.click();
                    
            wait.until(ExpectedConditions.elementToBeClickable(drag));
            /*
            driver.manage().timeouts().pageLoadTimeout(1800, TimeUnit.SECONDS);
            System.out.println(driver.findElement(By.xpath("//h1[contains(@class, 'd2l-page-title d2l-heading vui-heading-1')]")).getText());
            (new WebDriverWait(driver, 60)).until(new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver d) {
            return drag.getText().contains(d.findElement(By.xpath("//h1[contains(@class, 'd2l-page-title d2l-heading vui-heading-1')]")).getText());
            }
            });
                    
                    
            try {
            // while the following loop runs, the DOM changes -
            // page is refreshed, or element is removed and re-added
            // This took me forever to figure out!!!
            Thread.sleep(2000);
            } catch (InterruptedException ex) {
            Logger.getLogger(Test1.class.getName()).log(Level.SEVERE, null, ex);
            }
                    
                    
            List<WebElement> contentItems = driver.findElements(By.className("d2l-fuzzydate"));
                    
            for (int k = 1; k < contentItems.size(); k++) {
            WebElement content = contentItems.get(k);
            wait.until(presenceOfElementLocated(By.className(content.getAttribute("class"))));
            WebElement parent1 = content.findElement(By.xpath(".."));
            System.out.println(parent1.getTagName());
            WebElement parent2 = parent1.findElement(By.xpath(".."));
            System.out.println(parent2.getTagName());
            WebElement parent3 = parent2.findElement(By.xpath(".."));
            System.out.println(parent3.getTagName());
            WebElement parent4 = parent3.findElement(By.xpath(".."));
            System.out.println(parent4.getTagName());
            WebElement parent5 = parent4.findElement(By.xpath(".."));
            System.out.println(parent5.getTagName());
            WebElement parent6 = parent5.findElement(By.xpath(".."));
            System.out.println(parent6.getTagName());
            //System.out.println(parent5.getText());
            System.out.println(parent6.getAttribute("title"));
            }
                    
            }
             */
            /**
             * This covers quizzes
             */
            /*
            driver.get("https://byui.brightspace.com/d2l/lms/quizzing/admin/quizzes_manage.d2l?ou=" + ouList1);
            driver.manage().timeouts().pageLoadTimeout(1800, TimeUnit.SECONDS);
            System.out.println("Opening OU# " + ouList1);
            wait.until(ExpectedConditions.elementToBeClickable(By.className("d2l-tool-areas")));
                    
            List<WebElement> links = driver.findElements(By.xpath("//a[contains(@href,'/d2l/lms/quizzing/admin/modify/quiz_newedit_properties.d2l?qi=')]"));
            System.out.println("viu outline obtained");
                    
            ArrayList<String> quizzes = new ArrayList<>();
                    
            System.out.println(links.size());
                    
            for (WebElement link : links) {
            if (link.getAttribute("href") != null && link.getAttribute("href").contains("byui.brightspace.com/d2l/lms/quizzing/admin/modify")) {
            quizzes.add(link.getAttribute("href"));
            System.out.println("successfully pulled: " + link.getAttribute("href"));
            }
            }
            System.out.println(quizzes.size());
                    
            for (int j = 0; j < quizzes.size(); j++) {
            String quiz = quizzes.get(j);
            boolean isLA = false;
            driver.get(quiz);
            driver.manage().timeouts().pageLoadTimeout(1800, TimeUnit.SECONDS);
                    
            if (!driver.findElements(By.linkText("Expand optional advanced properties")).isEmpty()) {
            driver.findElement(By.linkText("Expand optional advanced properties")).click();
            driver.manage().timeouts().implicitlyWait(1800, TimeUnit.SECONDS);
                    
            }
                    
            wait.until(ExpectedConditions.elementToBeClickable(By.name("disableRightClick")));
            if (driver.findElement(By.name("disableRightClick")).isSelected()) {
            driver.findElement(By.name("disableRightClick")).click();
            driver.findElement(By.id("z_b")).click();
            driver.manage().timeouts().pageLoadTimeout(1800, TimeUnit.SECONDS);
            count++;
            }
                    
            List<WebElement> longAnswer = driver.findElements(By.xpath("//label[contains(.,'LA')]"));
            if (longAnswer.size() > 0) {
            isLA = true;
            }
                    
            quiz = quiz.replace("/quiz_newedit_properties", "/quiz_newedit_assessment");
            driver.get(quiz);
            driver.manage().timeouts().pageLoadTimeout(1800, TimeUnit.SECONDS);
                    
            wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.name("autoExportGrades")));
            if (driver.findElement(By.name("autoExportGrades")).isSelected()
                && isLA == true) {
            driver.findElement(By.name("autoExportGrades")).click();
            count++;
            }
                    
            wait.until(ExpectedConditions.elementToBeClickable(By.name("autoSetGraded")));
            if (driver.findElement(By.name("autoSetGraded")).isSelected()
                && isLA == true) {
            driver.findElement(By.name("autoSetGraded")).click();
            count++;
            }
                    
            wait.until(ExpectedConditions.elementToBeClickable(By.name("autoSetGraded")));
            if (!driver.findElement(By.name("autoSetGraded")).isSelected()
                && isLA == false) {
            driver.findElement(By.name("autoSetGraded")).click();
            count++;
                    
            }
                    
            wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.name("autoExportGrades")));
            if (!driver.findElement(By.name("autoExportGrades")).isSelected()
                && isLA == false) {
            driver.findElement(By.name("autoExportGrades")).click();
            count++;
            }
                    
            wait.until(ExpectedConditions.elementToBeClickable(By.id("z_b")));
            driver.findElement(By.id("z_b")).click();
            driver.manage().timeouts().pageLoadTimeout(1800, TimeUnit.SECONDS);
                    
            System.out.println("count is: " + count);
                    
            /**
             *
             * Submission Views
             *
             */
            /*
                           driver.findElement(By.linkText("Submission Views")).click();
                           driver.manage().timeouts().pageLoadTimeout(1800, TimeUnit.SECONDS);
                                   
                           driver.findElement(By.linkText("Default View")).click();
                           driver.manage().timeouts().pageLoadTimeout(1800, TimeUnit.SECONDS);
                                   
                           if (!driver.findElement(By.name("showQuestions")).isSelected()) {
                           System.out.println("show answers clicked!!!  URL: " + quiz);
                           driver.findElement(By.name("showQuestions")).click();
                           }
                                   
                           if (!driver.findElement(By.id("z_p")).isSelected()) {
                           driver.findElement(By.id("z_p")).click();
                           }
                           if (!driver.findElement(By.name("showCorrectAnswers")).isSelected()) {
                           driver.findElement(By.name("showCorrectAnswers")).click();
                           }
                           if (!driver.findElement(By.name("showQuestionScore")).isSelected()) {
                           driver.findElement(By.name("showQuestionScore")).click();
                           }
                           if (!driver.findElement(By.name("showScore")).isSelected()) {
                           driver.findElement(By.name("showScore")).click();
                           }
                                   
                           driver.findElement(By.id("z_a")).click();
                            */
            //}
            /**
             * End of FOR LOOP stub
             */
        } catch (IOException ex) {
            Logger.getLogger(Test1.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

}

From source file:zz.pseas.ghost.browser.BrowserFactory.java

License:Apache License

public static CookieStore getCookieStore(WebDriver driver) {
    CookieStore store = new BasicCookieStore();
    Set<Cookie> cs = driver.manage().getCookies();
    System.out.println(cs.size());
    for (Cookie c : cs) {
        BasicClientCookie c1 = new BasicClientCookie(c.getName(), c.getValue());
        if (c.getDomain() == null) {
            System.out.println(c.getName() + "->" + c.getValue());
        } else {/*ww w.  j  a v a2 s  .  c o  m*/
            System.out.println(c.getDomain());
        }

        c1.setDomain(c.getDomain() == null ? "my.alipay.com" : c.getDomain());
        c1.setPath(c.getPath());
        c1.setExpiryDate(c.getExpiry());
        store.addCookie(c1);
    }
    System.out.println(store.getCookies().size());
    return store;
}