Example usage for org.openqa.selenium Cookie.Builder path

List of usage examples for org.openqa.selenium Cookie.Builder path

Introduction

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

Prototype

String path

To view the source code for org.openqa.selenium Cookie.Builder path.

Click Source Link

Usage

From source file:com.sebuilder.interpreter.steptype.AddCookie.java

License:Apache License

@Override
public boolean run(TestRun ctx) {
    Cookie.Builder cb = new Cookie.Builder(ctx.string("name"), ctx.string("value"));
    for (String opt : ctx.string("options").split(",")) {
        String[] kv = opt.split("=", 2);
        if (kv.length == 1) {
            continue;
        }//w  w w. j  a v a2s  .  c  om
        if (kv[0].trim().equals("path")) {
            cb.path(kv[1].trim());
        }
        if (kv[0].trim().equals("max_age")) {
            cb.expiresOn(new Date(new Date().getTime() + Long.parseLong(kv[1].trim()) * 1000l));
        }
        ctx.driver().manage().addCookie(cb.build());
    }
    ctx.driver().navigate().refresh();
    return true;
}

From source file:org.fitting.selenium.fixture.CookieFixture.java

License:Apache License

/**
 * Adds a cookie with the given data./*from   w w  w.  java 2 s .  c o  m*/
 *
 * @param driver The web driver.
 * @param name   The name of the cookie.
 * @param value  The value of the cookie.
 * @param path   The path to set the cookie.
 * @param domain The domain.
 */
private void addCookie(final WebDriver driver, final String name, final String value, final String path,
        final String domain) {
    handleCookie(domain, new CookieCallback() {
        @Override
        public void execute() {
            final Cookie.Builder builder = new Cookie.Builder(name, value);
            if (isNotEmpty(path)) {
                builder.path(path);
            }
            if (isNotEmpty(domain)) {
                builder.domain(getStrippedDomain(domain));
            }

            driver.manage().addCookie(builder.build());
        }
    });
}