Selenium-Yenza, Hlaziya kwaye ucime iiKuki

Phantse zonke iiwebhusayithi zisebenzisa ii-cookies ngendlela enye. Iicookies ziyindlela yokukhumbula abasebenzisi kunye nokunxibelelana kwabo nesiza ngokugcina ulwazi kwifayile yecook njengokubaluleka kwexabiso lesibini.

Xa kuvavanywa iwebhusayithi ngeSelenium WebDriver, ngamanye amaxesha kuyimfuneko ukuphatha ii-cookies, ezinje ngokudala ii-cookies ezintsha, ukuhlaziya ii-cookies esele zikhona ngolwazi olutsha okanye ukucima iicookies.

Kule tutorial yeWebDriver, sijonga ukuphatha iicookies kwiWebDriver. Imizekelo yekhowudi yeJava yendlela yokwenza, ukuhlaziya kunye nokucima ii-cookies usebenzisa iSelenium WebDriver.


Ukusebenzisa nayiphi na indlela yokuphatha ikuki kwiWebDriver, kufuneka kuqala singenise iklasi yeCookie. Ukwenza oko, sisebenzisa

import org.openqa.selenium.Cookie;

Ukufumana zonke iiKuki

//This method gets all the cookies public Set getAllCookies() {
return driver.manage().getCookies(); }

Fumana icookie enamagama

//This method gets a specified cookie public Cookie getCookieNamed(String name) {
return driver.manage().getCookieNamed(name); }

Buyisa ixabiso lecookie

//This method gets the value of a specified cookie public String getValueOfCookieNamed(String name) {
return driver.manage().getCookieNamed(name).getValue(); }

Yongeza ikuki

//This method adds or creates a cookie public void addCookie(String name, String value, String domain, String path, Date expiry) {
driver.manage().addCookie(
new Cookie(name, value, domain, path, expiry)); }

Yongeza iseti yecookies

//This method adds set of cookies for a domain public void addCookiesToBrowser(Set cookies, String domain) {
for (Cookie c : cookies) {
if (c != null) {

if (c.getDomain().contains(domain)){


driver.manage().addCookie(


new Cookie(name, value, domain, path, expiry));

}
}
}
driver.navigate().refresh(); }

Cima ikuki ethile

//This method deletes a specific cookie public void deleteCookieNamed(String name) {
driver.manage().deleteCookieNamed(name); }

Cima zonke iiKuki

//This method deletes all cookies public void deleteAllCookies() {
driver.manage().deleteAllCookies(); }