Skip to content

Instantly share code, notes, and snippets.

@MicahLC
Created July 13, 2018 19:39
Show Gist options
  • Save MicahLC/ea6050953e460f3c6eadd11c509c7939 to your computer and use it in GitHub Desktop.
Save MicahLC/ea6050953e460f3c6eadd11c509c7939 to your computer and use it in GitHub Desktop.
Test for reproducing bug where Android can't delete cookie starting with session.
package com.example;
import java.util.Date;
import java.util.GregorianCalendar;
import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class CookieTest {
WebDriver driver;
WebDriverWait wait;
@BeforeMethod
private void setup() {
// initialize driver here
wait = new WebDriverWait(driver, 10);
}
@AfterMethod
private void teardown() {
if (driver != null) {
driver.quit();
driver = null;
}
wait = null;
}
private Cookie cookieSetup(String cookieName) {
driver.get("https://google.com");
wait.until(ExpectedConditions.presenceOfElementLocated(By.name("q")));
Date expiry = new GregorianCalendar(2019, 6, 6).getTime();
Cookie cookie = new Cookie(cookieName, "value", "", expiry);
driver.manage().addCookie(cookie);
return wait.until(d -> driver.manage().getCookieNamed(cookieName));
}
@Test
public void testSessionCookieShort() {
String cookieName = System.getProperty("cookie", "session");
Cookie cookie = cookieSetup(cookieName);
// Android fails here
driver.manage().deleteCookie(cookie);
wait.until(d -> driver.manage().getCookieNamed(cookieName) == null);
}
@Test
public void testSessionCookieDeleteAllShort() {
String cookieName = System.getProperty("cookie", "session");
cookieSetup(cookieName);
// This doesn't fail on Android
driver.manage().deleteAllCookies();
wait.until(d -> driver.manage().getCookieNamed(cookieName) == null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment