How To Extract Domain Cookie In Selenium WebDriver Test

You must know what Is cookies earlier learning how to extract or deal cookies In selenium WebDriver. Cookies are modest text files created past times website when y'all access It to scream upwards to a greater extent than or less information for y'all to utilization It In future. Cookies contains domain advert for which It Is created, Cookie name
and Its value. It too contains validity duration of cookie. As per testing indicate of view, sometimes y'all remove to extract cookies. Bellow given event volition exhibit y'all how to extract in addition to impress cookies In selenium WebDriver test.

WebDriver has cookie flat which contains many dissimilar functions using which nosotros tin bathroom acquire the cookies in addition to Its dissimilar parameters. Few of the functions I accept used In bellow given event like

  • getDomain() - To acquire domain advert of cookie.
  • getName() - To acquire advert of cookie.
  • getValue() - To acquire value of cookie.
  • getExpiry() - To acquire hold upwards past times appointment of cookie.
Run below given event In your eclipse IDE. It volition retrieve to a higher house details of cookie for google domain. 

package Testing_Pack;  import java.util.Set; import java.util.concurrent.TimeUnit; import org.openqa.selenium.Cookie; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test;  world flat extractCookies {  WebDriver driver;    @BeforeTest  world void setup() throws Exception {   driver = novel FirefoxDriver();   driver.manage().window().maximize();   driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);   driver.get("http://www.google.com");  }    @Test  world void extrctCookie(){     //Get in addition to extract all cookies of google domain in addition to impress cookie parameters.    Set<Cookie> totalCookies = driver.manage().getCookies();   System.out.println("Total Number Of cookies : " +totalCookies.size());      for (Cookie currentCookie : totalCookies) {       System.out.println(String.format("%s -> %s -> %s -> %s", "Domain Name : "+currentCookie.getDomain(), "Cookie Name : "+currentCookie.getName(), "Cookie Value : "+currentCookie.getValue(), "Cookie Expiry : "+currentCookie.getExpiry()));   }    } }

At the terminate of execution, You volition acquire cookie exceptional In console. You tin bathroom alter domain advert In to a higher house event to acquire cookie exceptional In selenium WebDriver test. Next post volition exhibit y'all how to add together novel cookie.
More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM

http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post