nl.praegus.fitnesse.slim.fixtures.playwright.CookieManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of toolchain-playwright-fixture Show documentation
Show all versions of toolchain-playwright-fixture Show documentation
A FitNesse fixture for writing browser tests using the Playwright Java API
package nl.praegus.fitnesse.slim.fixtures.playwright;
import com.microsoft.playwright.BrowserContext;
import com.microsoft.playwright.options.Cookie;
import com.microsoft.playwright.options.SameSiteAttribute;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class CookieManager {
public void setCookie(Map cookieMap, BrowserContext browserContext) {
List cookies = new ArrayList<>();
var cookie = new Cookie(cookieMap.get("name"), cookieMap.get("value"));
if (cookieMap.get("domain") != null) {
cookie.setDomain(cookieMap.get("domain"))
.setPath(cookieMap.getOrDefault("path", "/"));
} else {
cookie.setUrl(cookieMap.get("url"));
}
cookie.setExpires(timestampToEpoch(cookieMap.getOrDefault("expires", "2080-11-15 21:12")))
.setSecure(Boolean.parseBoolean(cookieMap.getOrDefault("secure", "false")))
.setHttpOnly(Boolean.parseBoolean(cookieMap.getOrDefault("httpOnly", "false")))
.setSameSite(SameSiteAttribute.valueOf(cookieMap.getOrDefault("sameSite", "NONE")));
cookies.add(cookie);
browserContext.addCookies(cookies);
}
public void setCookies(List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy