TESTEVERYTHING

Showing posts with label Cookies. Show all posts
Showing posts with label Cookies. Show all posts

Thursday, 2 August 2012

Set cookies with domain using webdriver

using web driver I have created the script for adding the cookies using domain. Basically here is the things that you must know first open the URL then add the cookies after that again open the URL now it will add.

 ______________________________________________________
package webdriver;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.Select;

public class RuntestCase {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
       
       
        WebDriver driver;


        System.out.println("firefox");

        DesiredCapabilities capability = DesiredCapabilities.firefox();

        String appUrl = "http://beta.abc.com/mlb/sweepstakes/y2012/sd/alaska_form.jsp";

        capability.setBrowserName("firefox");
        capability.setPlatform(org.openqa.selenium.Platform.ANY);
        driver = new FirefoxDriver(capability);

        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
       
        driver.get(appUrl);

        Calendar c = new GregorianCalendar();
        int year = 2014;
        int month = 6;
        int day = 7;
        int hour = 10;
        int minute = 26;
        int second = 47;
        c.set(year, month, day, hour, minute, second);
        Date expiry = c.getTime();
        String name = "betaaccess";
        String value = "true";
        String domain = ".abc.com";
        String path = "/";
        Cookie cookie = new Cookie(name, value, domain, path, expiry, false);
        driver.manage().addCookie(cookie);
        driver.get(appUrl);
               
            }
    }

Which one is right ?

Translate







Tweet