How to manage cookie of website in selenium?
package wdProgram;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class CookieMakeMyTrip {
WebDriver driver;
@BeforeTest
public void openBrowser() {
System.setProperty("webdriver.chrome.driver",
"D:\\Software\\Testing-Tools\\Selenium\\WebDriver\\Drivers\\IEChromeFirefox\\19092018\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@Test
public void testHandleCookie() throws InterruptedException {
driver.get("http://localhost/uth/gadgetsgallery/catalog");
System.out.println("---------------Cookies before Login---------------");
Set<Cookie> cookies = driver.manage().getCookies();
for(Cookie c:cookies) {
System.out.println("Domain Name:->"+c.getDomain());
System.out.println("Cookie Path:->"+c.getPath());
System.out.println("Cookie Name:->"+c.getName());
System.out.println("Cookie Value:->"+c.getValue());
}
driver.manage().deleteAllCookies();
Thread.sleep(2000);
driver.navigate().refresh();
}
}
Comments
Post a Comment