Selenium - Gadzira, Gadziridza uye Bvisa maKuki

Anenge ese mawebhusaiti anoshandisa makuki mune imwe nzira kana imwe. Cookies inzira yekurangarira vashandisi uye kudyidzana kwavo nesaiti iyi nekuchengetera ruzivo mufaira rekuki sekiyi-kukosha mapara.

Paunenge uchiyedza webhusaiti ine Selenium WebDriver, dzimwe nguva zvinofanirwa kubata makuki, sekugadzira makuki matsva, kugadzirisa macookie aripo neruzivo rutsva kana kudzima makuki.

Mune ino dzidziso yeWebDriver, isu tinotarisa pakubata makuki muWebDriver. Java kodhi kodhi mienzaniso yekugadzira, kugadzirisa uye kudzima makuki uchishandisa Selenium WebDriver.

Kuti tishandise chero nzira dzekubata makuki muWebDriver, isu tinotanga tada kuendesa Cookie kirasi. Kuti tiite izvozvo, tinoshandisa

import org.openqa.selenium.Cookie;

Dzosera maKuki ese

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

Dzosera cookie inonzi

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

Dzosera kukosha kwekuki

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

Wedzera Cookie

//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)); }

Wedzera seti yemakuki

//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(); }

Delete chaiyo Cookie

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

Delete maKuki ese

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