How to use Cookie.Builder class of org.openqa.selenium package

Best Selenium code snippet using org.openqa.selenium.Cookie.Builder

Source:CookieImplementationTest.java Github

copy

Full Screen

...82 @Test83 public void testShouldBeAbleToAddCookie() {84 String key = generateUniqueKey();85 String value = "foo";86 Cookie cookie = new Cookie.Builder(key, value).build();87 assertCookieIsNotPresentWithName(key);88 driver.manage().addCookie(cookie);89 assertCookieHasValue(key, value);90 openAnotherPage();91 assertCookieHasValue(key, value);92 }93 @Test94 public void testGetAllCookies() {95 String key1 = generateUniqueKey();96 String key2 = generateUniqueKey();97 assertCookieIsNotPresentWithName(key1);98 assertCookieIsNotPresentWithName(key2);99 Set<Cookie> cookies = driver.manage().getCookies();100 int countBefore = cookies.size();101 Cookie one = new Cookie.Builder(key1, "value").build();102 Cookie two = new Cookie.Builder(key2, "value").build();103 driver.manage().addCookie(one);104 driver.manage().addCookie(two);105 openAnotherPage();106 cookies = driver.manage().getCookies();107 assertEquals(countBefore + 2, cookies.size());108 assertTrue(cookies.contains(one));109 assertTrue(cookies.contains(two));110 }111 @JavascriptEnabled112 @Test113 public void testDeleteAllCookies() {114 addCookieOnServerSide(new Cookie("foo", "set"));115 assertSomeCookiesArePresent();116 driver.manage().deleteAllCookies();117 assertNoCookiesArePresent();118 openAnotherPage();119 assertNoCookiesArePresent();120 }121 @JavascriptEnabled122 @Test123 public void testDeleteCookieWithName() {124 String key1 = generateUniqueKey();125 String key2 = generateUniqueKey();126 addCookieOnServerSide(new Cookie(key1, "set"));127 addCookieOnServerSide(new Cookie(key2, "set"));128 assertCookieIsPresentWithName(key1);129 assertCookieIsPresentWithName(key2);130 driver.manage().deleteCookieNamed(key1);131 assertCookieIsNotPresentWithName(key1);132 assertCookieIsPresentWithName(key2);133 openAnotherPage();134 assertCookieIsNotPresentWithName(key1);135 assertCookieIsPresentWithName(key2);136 }137 @Test138 public void testShouldNotDeleteCookiesWithASimilarName() {139 String cookieOneName = "fish";140 Cookie cookie1 = new Cookie.Builder(cookieOneName, "cod").build();141 Cookie cookie2 = new Cookie.Builder(cookieOneName + "x", "earth").build();142 WebDriver.Options options = driver.manage();143 assertCookieIsNotPresentWithName(cookie1.getName());144 options.addCookie(cookie1);145 options.addCookie(cookie2);146 assertCookieIsPresentWithName(cookie1.getName());147 options.deleteCookieNamed(cookieOneName);148 Set<Cookie> cookies = options.getCookies();149 assertFalse(cookies.toString(), cookies.contains(cookie1));150 assertTrue(cookies.toString(), cookies.contains(cookie2));151 }152 @Ignore(OPERA)153 @Test154 public void testAddCookiesWithDifferentPathsThatAreRelatedToOurs() {155 driver.get(domainHelper.getUrlForFirstValidHostname("/common/animals"));156 Cookie cookie1 = new Cookie.Builder("fish", "cod").path("/common/animals").build();157 Cookie cookie2 = new Cookie.Builder("planet", "earth").path("/common/").build();158 WebDriver.Options options = driver.manage();159 options.addCookie(cookie1);160 options.addCookie(cookie2);161 driver.get(domainHelper.getUrlForFirstValidHostname("/common/animals"));162 assertCookieIsPresentWithName(cookie1.getName());163 assertCookieIsPresentWithName(cookie2.getName());164 driver.get(domainHelper.getUrlForFirstValidHostname("/common/simplePage.html"));165 assertCookieIsNotPresentWithName(cookie1.getName());166 }167 @Ignore({CHROME, OPERA})168 @Test169 public void testCannotGetCookiesWithPathDifferingOnlyInCase() {170 String cookieName = "fish";171 Cookie cookie = new Cookie.Builder(cookieName, "cod").path("/Common/animals").build();172 driver.manage().addCookie(cookie);173 driver.get(domainHelper.getUrlForFirstValidHostname("/common/animals"));174 assertNull(driver.manage().getCookieNamed(cookieName));175 }176 @Test177 public void testShouldNotGetCookieOnDifferentDomain() {178 assumeTrue(domainHelper.checkHasValidAlternateHostname());179 String cookieName = "fish";180 driver.manage().addCookie(new Cookie.Builder(cookieName, "cod").build());181 assertCookieIsPresentWithName(cookieName);182 driver.get(domainHelper.getUrlForSecondValidHostname("simpleTest.html"));183 assertCookieIsNotPresentWithName(cookieName);184 }185 @Ignore(value = {ANDROID, CHROME, HTMLUNIT, IE, IPHONE, OPERA},186 reason = "Untested browsers.")187 @Test188 public void testShouldBeAbleToAddToADomainWhichIsRelatedToTheCurrentDomain() {189 String cookieName = "name";190 assertCookieIsNotPresentWithName(cookieName);191 String shorter = domainHelper.getHostName().replaceFirst(".*?\\.", ".");192 Cookie cookie = new Cookie.Builder(cookieName, "value").domain(shorter).build();193 driver.manage().addCookie(cookie);194 assertCookieIsPresentWithName(cookieName);195 }196 @Ignore(value = {ALL})197 @Test198 public void testsShouldNotGetCookiesRelatedToCurrentDomainWithoutLeadingPeriod() {199 String cookieName = "name";200 assertCookieIsNotPresentWithName(cookieName);201 String shorter = domainHelper.getHostName().replaceFirst(".*?\\.", "");202 Cookie cookie = new Cookie.Builder(cookieName, "value").domain(shorter).build();203 driver.manage().addCookie(cookie);204 assertCookieIsNotPresentWithName(cookieName);205 }206 @Ignore({REMOTE, IE})207 @Test208 public void testShouldBeAbleToIncludeLeadingPeriodInDomainName() throws Exception {209 String cookieName = "name";210 assertCookieIsNotPresentWithName(cookieName);211 String shorter = domainHelper.getHostName().replaceFirst(".*?\\.", ".");212 Cookie cookie = new Cookie.Builder("name", "value").domain(shorter).build();213 driver.manage().addCookie(cookie);214 assertCookieIsPresentWithName(cookieName);215 }216 @Ignore(IE)217 @Test218 public void testShouldBeAbleToSetDomainToTheCurrentDomain() throws Exception {219 URI url = new URI(driver.getCurrentUrl());220 String host = url.getHost() + ":" + url.getPort();221 Cookie cookie = new Cookie.Builder("fish", "cod").domain(host).build();222 driver.manage().addCookie(cookie);223 driver.get(domainHelper.getUrlForFirstValidHostname("javascriptPage.html"));224 Set<Cookie> cookies = driver.manage().getCookies();225 assertTrue(cookies.contains(cookie));226 }227 @Test228 public void testShouldWalkThePathToDeleteACookie() {229 Cookie cookie1 = new Cookie.Builder("fish", "cod").build();230 driver.manage().addCookie(cookie1);231 driver.get(domainHelper.getUrlForFirstValidHostname("child/childPage.html"));232 Cookie cookie2 = new Cookie("rodent", "hamster", "/common/child");233 driver.manage().addCookie(cookie2);234 driver.get(domainHelper.getUrlForFirstValidHostname("child/grandchild/grandchildPage.html"));235 Cookie cookie3 = new Cookie("dog", "dalmation", "/common/child/grandchild/");236 driver.manage().addCookie(cookie3);237 driver.get(domainHelper.getUrlForFirstValidHostname("child/grandchild/grandchildPage.html"));238 driver.manage().deleteCookieNamed("rodent");239 assertNull(driver.manage().getCookies().toString(), driver.manage().getCookieNamed("rodent"));240 Set<Cookie> cookies = driver.manage().getCookies();241 assertEquals(2, cookies.size());242 assertTrue(cookies.contains(cookie1));243 assertTrue(cookies.contains(cookie3));244 driver.manage().deleteAllCookies();245 driver.get(domainHelper.getUrlForFirstValidHostname("child/grandchild/grandchildPage.html"));246 assertNoCookiesArePresent();247 }248 @Ignore(IE)249 @Test250 public void testShouldIgnoreThePortNumberOfTheHostWhenSettingTheCookie() throws Exception {251 URI uri = new URI(driver.getCurrentUrl());252 String host = String.format("%s:%d", uri.getHost(), uri.getPort());253 String cookieName = "name";254 assertCookieIsNotPresentWithName(cookieName);255 Cookie cookie = new Cookie.Builder(cookieName, "value").domain(host).build();256 driver.manage().addCookie(cookie);257 assertCookieIsPresentWithName(cookieName);258 }259 @Ignore(OPERA)260 @Test261 public void testCookieEqualityAfterSetAndGet() {262 driver.get(domainHelper.getUrlForFirstValidHostname("animals"));263 driver.manage().deleteAllCookies();264 Cookie addedCookie =265 new Cookie.Builder("fish", "cod")266 .path("/common/animals")267 .expiresOn(someTimeInTheFuture())268 .build();269 driver.manage().addCookie(addedCookie);270 Set<Cookie> cookies = driver.manage().getCookies();271 Cookie retrievedCookie = null;272 for (Cookie temp : cookies) {273 if (addedCookie.equals(temp)) {274 retrievedCookie = temp;275 break;276 }277 }278 assertNotNull("Cookie was null", retrievedCookie);279 // Cookie.equals only compares name, domain and path280 assertEquals(addedCookie, retrievedCookie);281 }282 @Ignore(value = {ANDROID, IE, OPERA}, reason =283 "Selenium, which use JavaScript to retrieve cookies, cannot return expiry info; " +284 "Other suppressed browsers have not been tested.")285 @Test286 public void testRetainsCookieExpiry() {287 Cookie addedCookie =288 new Cookie.Builder("fish", "cod")289 .path("/common/animals")290 .expiresOn(someTimeInTheFuture())291 .build();292 driver.manage().addCookie(addedCookie);293 Cookie retrieved = driver.manage().getCookieNamed("fish");294 assertNotNull(retrieved);295 assertEquals(addedCookie.getExpiry(), retrieved.getExpiry());296 }297 @Ignore(value = {ANDROID, IE, OPERA, OPERA_MOBILE, PHANTOMJS, SAFARI})298 @Test299 public void testRetainsCookieSecure() {300 driver.get(domainHelper.getSecureUrlForFirstValidHostname("animals"));301 Cookie addedCookie =302 new Cookie.Builder("fish", "cod")303 .path("/common/animals")304 .isSecure(true)305 .build();306 driver.manage().addCookie(addedCookie);307 driver.navigate().refresh();308 Cookie retrieved = driver.manage().getCookieNamed("fish");309 assertNotNull(retrieved);310 assertTrue(retrieved.isSecure());311 }312 @Ignore(value = {ANDROID, CHROME, FIREFOX, HTMLUNIT, IE, OPERA, OPERA_MOBILE, PHANTOMJS, SAFARI})313 @Test314 public void testRetainsHttpOnlyFlag() {315 Cookie addedCookie =316 new Cookie.Builder("fish", "cod")317 .path("/common/animals")318 .isHttpOnly(true)319 .build();320 addCookieOnServerSide(addedCookie);321 Cookie retrieved = driver.manage().getCookieNamed("fish");322 assertNotNull(retrieved);323 assertTrue(retrieved.isHttpOnly());324 }325 @Ignore(ANDROID)326 @Test327 public void testSettingACookieThatExpiredInThePast() {328 long expires = System.currentTimeMillis() - 1000;329 Cookie cookie = new Cookie.Builder("expired", "yes").expiresOn(new Date(expires)).build();330 driver.manage().addCookie(cookie);331 cookie = driver.manage().getCookieNamed("fish");332 assertNull(333 "Cookie expired before it was set, so nothing should be returned: " + cookie, cookie);334 }335 @Test336 public void testCanSetCookieWithoutOptionalFieldsSet() {337 String key = generateUniqueKey();338 String value = "foo";339 Cookie cookie = new Cookie(key, value);340 assertCookieIsNotPresentWithName(key);341 driver.manage().addCookie(cookie);342 assertCookieHasValue(key, value);343 }344 @Test345 public void testDeleteNotExistedCookie() {346 String key = generateUniqueKey();347 assertCookieIsNotPresentWithName(key);348 driver.manage().deleteCookieNamed(key);349 }350 @Ignore(value = {ANDROID, CHROME, FIREFOX, IE, OPERA, OPERA_MOBILE, PHANTOMJS, SAFARI})351 @Test352 public void testShouldDeleteOneOfTheCookiesWithTheSameName() {353 driver.get(domainHelper.getUrlForFirstValidHostname("/common/animals"));354 Cookie cookie1 = new Cookie.Builder("fish", "cod")355 .domain(domainHelper.getHostName()).path("/common/animals").build();356 Cookie cookie2 = new Cookie.Builder("fish", "tune")357 .domain(domainHelper.getHostName()).path("/common/").build();358 WebDriver.Options options = driver.manage();359 options.addCookie(cookie1);360 options.addCookie(cookie2);361 assertEquals(driver.manage().getCookies().size(), 2);362 driver.manage().deleteCookie(cookie1);363 assertEquals(driver.manage().getCookies().size(), 1);364 Cookie retrieved = driver.manage().getCookieNamed("fish");365 assertNotNull("Cookie was null", retrieved);366 assertEquals(cookie2, retrieved);367 }368 private String generateUniqueKey() {369 return String.format("key_%d", random.nextInt());370 }...

Full Screen

Full Screen

Source:WebDriverService.java Github

copy

Full Screen

1package com.services;2import org.openqa.selenium.Cookie;3import org.openqa.selenium.JavascriptExecutor;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.chrome.ChromeDriver;7import org.openqa.selenium.chrome.ChromeOptions;8import org.openqa.selenium.firefox.FirefoxDriver;9import org.openqa.selenium.firefox.FirefoxOptions;10import org.openqa.selenium.firefox.FirefoxProfile;11import org.openqa.selenium.firefox.internal.ProfilesIni;12import org.openqa.selenium.interactions.Actions;13import org.openqa.selenium.support.ui.ExpectedConditions;14import org.openqa.selenium.support.ui.WebDriverWait;15import org.springframework.beans.factory.annotation.Value;16import org.springframework.stereotype.Service;17import java.io.*;18import java.text.ParseException;19import java.text.SimpleDateFormat;20import java.util.Date;21import java.util.Set;22import java.util.concurrent.TimeUnit;23@Service24public class WebDriverService {25 private static final String COOKIE_FILE = "src/test/resources/cookies/cookies.txt";26 private static final String SEPERATOR = ";";27 private WebDriver driver;28 private WebDriverWait wait;29 private Actions actions;30 @Value("${firefox.driver.location}")31 String firefoxDriverLocation;32 @Value("${chrome.driver.location}")33 String chromeDriverLocation;34 @Value("${firefox.profile.name}")35 String firefoxProfileName;36 @Value("${chrome.profile.location}")37 String chromeProfileLocation;38 public WebDriver getDriver() {39 return driver;40 }41 public JavascriptExecutor getJSExecutor() {42 return (JavascriptExecutor) driver;43 }44 public WebDriverWait getWait() {45 return wait;46 }47 public Actions getActions() {48 return actions;49 }50 public void initDriver(String driverType) {51 if (driverType.equals("chrome")) {52 System.setProperty("webdriver.chrome.driver", chromeDriverLocation);53 ChromeOptions options = new ChromeOptions();54 options.addArguments("user-data-dir=" + chromeProfileLocation);55 driver = new ChromeDriver(options);56 }57 if (driverType.equals("firefox")) {58 System.setProperty("webdriver.gecko.driver", firefoxDriverLocation);59 FirefoxProfile firefoxProfile = new FirefoxProfile();60 FirefoxOptions firefoxOptions = new FirefoxOptions();61 ProfilesIni profilesIni = new ProfilesIni();62 firefoxOptions.setProfile(profilesIni.getProfile(firefoxProfileName));63 driver = new FirefoxDriver(firefoxOptions);64 }65 }66 public void copyCookiesFromDriver() {67 Set<Cookie> cookies = driver.manage().getCookies();68 BufferedWriter bufferedWriter = null;69 try {70 bufferedWriter = new BufferedWriter(new FileWriter(COOKIE_FILE));71 for (Cookie cookie : cookies) {72 StringBuilder cookieBuilder = new StringBuilder();73 cookieBuilder.append(cookie.getName()).append(SEPERATOR);74 cookieBuilder.append(cookie.getValue()).append(SEPERATOR);75 cookieBuilder.append(cookie.getDomain()).append(SEPERATOR);76 cookieBuilder.append(cookie.getPath()).append(SEPERATOR);77 if (cookie.getExpiry() != null)78 cookieBuilder.append(cookie.getExpiry().toString()).append(SEPERATOR);79 else80 cookieBuilder.append(SEPERATOR);81 cookieBuilder.append(cookie.isSecure()).append(SEPERATOR);82 cookieBuilder.append(cookie.isHttpOnly());83 bufferedWriter.write(cookieBuilder.toString());84 }85 bufferedWriter.close();86 } catch (IOException e) {87 //logging88 }89 }90 public void copyCookiesToDriver() {91 try {92 BufferedReader bufferedReader = new BufferedReader(new FileReader(COOKIE_FILE));93 String line;94 while ((line = bufferedReader.readLine()) != null) {95 String[] split = line.split(SEPERATOR);96 if (split.length != 7)97 return;98 Date date = null;99 if (split[4] != null)100 date = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss z").parse(split[4]);101 Cookie cookie = new Cookie(split[0], split[1], split[2], split[3], date, Boolean.parseBoolean(split[5]), Boolean.parseBoolean(split[6]));102 driver.manage().addCookie(cookie);103 }104 bufferedReader.close();105 } catch (FileNotFoundException e) {106 //logging107 } catch (IOException e) {108 //logging109 } catch (ParseException e) {110 //logging111 }112 }113 public void initExplicitWait(Long sec) {114 if (driver != null) {115 wait = new WebDriverWait(driver, sec);116 }117 }118 public void initActions() {119 if (driver != null) {120 actions = new Actions(driver);121 }122 }123 public void explicitWaitUntilElementClickable(WebElement element) {124 wait.until(ExpectedConditions.elementToBeClickable(element));125 }126 public void explicitWaitUntilElementVisible(WebElement element) {127 wait.until(ExpectedConditions.visibilityOf(element));128 }129 public void implicitWait(Long time) {130 try {131 Thread.sleep(time * 1000);132 } catch (InterruptedException e) {133 //logging134 }135 //Implicit wait does not seems to working with some firefox profile.136 // driver.manage().timeouts().implicitlyWait(time, TimeUnit.SECONDS);137 }138 public void closeDriver() {139 if (driver != null) {140 driver.close();141 }142 }143}...

Full Screen

Full Screen

Source:RestAssuredToSeleniumTests.java Github

copy

Full Screen

...10import static org.hamcrest.MatcherAssert.assertThat;11public class RestAssuredToSeleniumTests {12 @Test13 public void convertBasicCookieTest(){14 Cookie restAssuredCookie = new Cookie.Builder("Cookie name", "Cookie value").build();15 CookieAdapter cookieAdapter = new CookieAdapter();16 org.openqa.selenium.Cookie adaptedCookie = cookieAdapter.convertToSelenium(restAssuredCookie);17 Approvals.verify(adaptedCookie.toString());18 }19 @Test20 public void convertComplexCookieTest(){21 Calendar currentDate = Calendar.getInstance();22 currentDate.set(2018, 01, 01);23 currentDate.set(Calendar.HOUR, 0);24 currentDate.set(Calendar.MINUTE, 0);25 currentDate.set(Calendar.SECOND, 0);26 currentDate.set(Calendar.HOUR_OF_DAY, 0);27 Cookie restAssuredCookie = new Cookie.Builder("Cookie name", "Cookie value")28 .setComment("Cookie comment")29 .setDomain("www.mwtestconsultancy.co.uk")30 .setExpiryDate(currentDate.getTime())31 .setHttpOnly(true)32 .setPath("/test")33 .setSecured(false)34 .setVersion(1)35 .build();36 CookieAdapter cookieAdapter = new CookieAdapter();37 org.openqa.selenium.Cookie adaptedCookie = cookieAdapter.convertToSelenium(restAssuredCookie);38 Approvals.verify(adaptedCookie);39 }40 @Test41 public void convertMaxAgeCookieTest(){42 Calendar currentDate = Calendar.getInstance();43 currentDate.setTimeZone(TimeZone.getTimeZone("GMT"));44 currentDate.add(Calendar.SECOND, 86400);45 Cookie restAssuredCookie = new Cookie.Builder("Cookie name", "Cookie value")46 .setMaxAge(86400)47 .build();48 CookieAdapter cookieAdapter = new CookieAdapter();49 org.openqa.selenium.Cookie adaptedCookie = cookieAdapter.convertToSelenium(restAssuredCookie);50 assertThat(adaptedCookie.getExpiry().toString(), is(currentDate.getTime().toString()));51 }52 @Test53 public void convertLiveCookieTest(){54 Response response = given()55 .get("http://the-internet.herokuapp.com/");56 CookieAdapter cookieAdapter = new CookieAdapter();57 org.openqa.selenium.Cookie convertedCookie = cookieAdapter.convertToSelenium(response.getDetailedCookie("rack.session"));58 Approvals.verify(convertedCookie.getClass());59 }...

Full Screen

Full Screen

Source:BrowserActions.java Github

copy

Full Screen

...63 }64 }65 public static void cookieBuilder(WebDriver driver, CookieBuilderType cookieBuilderType, String name, String value,66 String domain) {67 Cookie cookie = new Cookie.Builder(name, value).domain(domain).build();68 switch (cookieBuilderType) {69 case ADD:70 driver.manage().addCookie(cookie);71 break;72 case DELETE:73 driver.manage().deleteCookie(cookie);74 break;75 }76 }77}...

Full Screen

Full Screen

Source:Username.java Github

copy

Full Screen

...6import org.openqa.selenium.WebDriver;7import org.openqa.selenium.chrome.ChromeDriver;8import org.openqa.selenium.firefox.FirefoxDriver;9import org.openqa.selenium.Cookie;10import org.openqa.selenium.Cookie.Builder;1112public class Username {1314 public static void main(String[] args) throws IOException, Exception {15 // TODO Auto-generated method stub16 //System.setProperty("webdriver.gecko.driver", "geckodriver.exe");17 System.setProperty("webdriver.chrome.driver", "chromedriver.exe");18 //WebDriver driver = new FirefoxDriver();19 WebDriver driver = new ChromeDriver();20 driver.manage().window().maximize();21 22 driver.get("http://www.gmail.com");23 Cookie cookie1 = new Cookie("ACCOUNT_CHOOSER", "AFx_qI5DW8GPvwowQ62Nq5ZaUIh18NHxHcHR5NzwYryIyWnHnxo4TG3alxT6LYbux-0ZJDCjcDPD4WYzCD-g_PePla_p7kiDOKo9BG3JtOL3PlRB3apWoGsizZ4_Ct7oJI9OphWkKmTv");24 driver.manage().addCookie(cookie1);25 Thread.sleep(2000);26 driver.get("http://www.gmail.com");27 Cookie ck = new Cookie.Builder("SID", "uwTmWoy80DDkKPb7VwDCFr187n2DrG0WP_BiL0-1iXK5VQEHH--Usf6I6hiea9fwfLvIcA.").domain("google.com").build();28 driver.manage().addCookie(ck);29 //Cookie ck1 = new Cookie.Builder("SID", "uwTmWoy80DDkKPb7VwDCFr187n2DrG0WP_BiL0-1iXK5VQEHH--Usf6I6hiea9fwfLvIcA.").domain("google.co.in").build();30 //driver.manage().addCookie(ck1);31 //driver.manage().addCookie(new Cookie("SID", "uwTmWoy80DDkKPb7VwDCFr187n2DrG0WP_BiL0-1iXK5VQEHH--Usf6I6hiea9fwfLvIcA.", "google.co.in", "/", null));32 33 Thread.sleep(2000);34 driver.get("https://mail.google.com");35 36 37 Set<org.openqa.selenium.Cookie> cookiesList1 = driver.manage().getCookies();38 for(org.openqa.selenium.Cookie getcookies :cookiesList1) {39 System.out.println(getcookies);40 System.out.println("");41 }42 43 Thread.sleep(2000);44 driver.get("https://www.facebook.com");45 Cookie ck4 = new Cookie.Builder("c_user", "1332739633").domain("facebook.com").build();46 //Cookie ck4 = new Cookie("c_user", "1332739633");47 driver.manage().addCookie(ck4);48 System.out.println("FACEBOOK");49 Set<org.openqa.selenium.Cookie> cookiesList2 = driver.manage().getCookies();50 for(org.openqa.selenium.Cookie getcookies :cookiesList2) {51 System.out.println(getcookies);52 System.out.println("");53 }54 55 } ...

Full Screen

Full Screen

Source:Wait.java Github

copy

Full Screen

1package functionality;2import builders.CookieBuilder;3import org.openqa.selenium.By;4import org.openqa.selenium.Cookie;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.WebElement;7import org.openqa.selenium.support.ui.ExpectedConditions;8import org.openqa.selenium.support.ui.WebDriverWait;9import pageObjectModels.Driver;10import pageObjectModels.HomePage;11import pageObjectModels.LogInPage;12import java.util.concurrent.TimeUnit;13public class Wait {14 public static void main(String[] args) {15 System.setProperty("webdriver.chrome.driver", "chromedriver.exe");16 WebDriver driver = Driver.driver();17 driver.get("https://player.pl/seriale-online/moda-na-sukces-odcinki,2775/odcinek-7350,S14E7350,170089");18 Cookie gad = new CookieBuilder("GAD","KlQrd8VG8UOVGGsGG8Y8kI8gWKsfn-6BMaQGmSXb-mAsEax1GGMS",".tvn.adocean.pl","/").cookieBuild();19 driver.manage().addCookie(gad);20 Cookie rodo = new CookieBuilder("rodoWindowPolicy","true",".player.pl","/").cookieBuild();21 driver.manage().addCookie(rodo);22 driver.navigate().refresh();23 driver.manage().window().maximize();24 WebDriverWait wait = new WebDriverWait(driver,10);25 WebElement loginBtn = wait.until(ExpectedConditions.elementToBeClickable(By.className("btn-login")));26 loginBtn.click();27 WebElement loginByMail = wait.until(ExpectedConditions.elementToBeClickable(By.id("login_by_email")));28 loginByMail.click();29 WebElement sendingMail = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"root\"]/div/main/div/div/div[2]/div/div/div/div[1]/div/div/form/div[1]/div/input")));30 sendingMail.sendKeys("");31 WebElement password = wait.until(ExpectedConditions.elementToBeClickable(By.id("password")));32 password.sendKeys("");33 WebElement btngoin = driver.findElement(By.id("sign_in"));34 btngoin.click();35 WebElement user = wait.until(ExpectedConditions.elementToBeClickable(By.className("missing-avatar")));36 user.click();37 WebElement closeBtn = wait.until(ExpectedConditions.elementToBeClickable(By.className("close")));38 closeBtn.click();39 WebElement play = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".btnaas")));40 play.click();41 }42}...

Full Screen

Full Screen

Source:AddCookie.java Github

copy

Full Screen

...3import java.util.Date;4import java.util.Map;5import java.util.concurrent.TimeUnit;6import org.openqa.selenium.Cookie;7import org.openqa.selenium.Cookie.Builder;8import org.openqa.selenium.WebDriver;9import org.openqa.selenium.WebDriver.Options;10import org.openqa.selenium.remote.server.JsonParametersAware;11import org.openqa.selenium.remote.server.Session;12public class AddCookie13 extends WebDriverHandler<Void>14 implements JsonParametersAware15{16 private volatile Map<String, Object> rawCookie;17 18 public AddCookie(Session session)19 {20 super(session);21 }22 23 public Void call() throws Exception24 {25 Cookie cookie = createCookie();26 27 getDriver().manage().addCookie(cookie);28 29 return null;30 }31 32 public void setJsonParameters(Map<String, Object> allParameters) throws Exception33 {34 if (allParameters == null) {35 return;36 }37 rawCookie = Maps.newHashMap((Map)allParameters.get("cookie"));38 }39 40 protected Cookie createCookie() {41 if (rawCookie == null) {42 return null;43 }44 45 String name = (String)rawCookie.get("name");46 String value = (String)rawCookie.get("value");47 String path = (String)rawCookie.get("path");48 String domain = (String)rawCookie.get("domain");49 boolean secure = getBooleanFromRaw("secure");50 boolean httpOnly = getBooleanFromRaw("httpOnly");51 52 Number expiryNum = (Number)rawCookie.get("expiry");53 54 Date expiry = expiryNum == null ? null : new Date(TimeUnit.SECONDS.toMillis(expiryNum.longValue()));55 56 return new Cookie.Builder(name, value)57 .path(path)58 .domain(domain)59 .isSecure(secure)60 .expiresOn(expiry)61 .isHttpOnly(httpOnly)62 .build();63 }64 65 private boolean getBooleanFromRaw(String key) {66 if (rawCookie.containsKey(key)) {67 Object value = rawCookie.get(key);68 if ((value instanceof Boolean)) {69 return ((Boolean)value).booleanValue();70 }...

Full Screen

Full Screen

Source:CookieTest.java Github

copy

Full Screen

...28 @Test29 public void cookieTestSecondExample(){30 driver.manage().deleteAllCookies();31 //Cookie aCookie = driver.manage().getCookieNamed("seleniumSimplifiedSearchNumVisits");32 Cookie.Builder newCookie = new Cookie.Builder("seleniumSimplifiedSearchNumVisits","42");33 newCookie.domain("compendiumdev.co.uk");34 newCookie.path("/selenium");35 driver.manage().addCookie(newCookie.build());36 driver.navigate().refresh();37 assertThat(driver.manage().getCookieNamed("seleniumSimplifiedSearchNumVisits").getValue(), is("43"));38 }39 @Test40 public void cookieTestThirdExample(){41 Cookie aCookie = driver.manage().getCookieNamed("seleniumSimplifiedSearchNumVisits");42 Cookie.Builder newCookie = new Cookie.Builder(aCookie.getName(),"43");43 newCookie.domain(aCookie.getDomain());44 newCookie.path(aCookie.getPath());45 driver.manage().deleteCookie(aCookie);46 driver.manage().addCookie(newCookie.build());47 driver.navigate().refresh();48 assertThat(driver.manage().getCookieNamed("seleniumSimplifiedSearchNumVisits").getValue(), is("44"));49 }50 @After51 public void closeDriver(){52 driver.close();53 }54}...

Full Screen

Full Screen

Cookie.Builder

Using AI Code Generation

copy

Full Screen

1Cookie.Builder cookieBuilder = new Cookie.Builder("CookieName", "CookieValue");2cookieBuilder.domain("somedomain.com");3cookieBuilder.isHttpOnly(true);4cookieBuilder.isSecure(true);5cookieBuilder.path("/");6cookieBuilder.expiresOn(new Date(new Date().getTime() + 1000));7Cookie cookie = cookieBuilder.build();8driver.manage().addCookie(cookie);9driver.navigate().refresh();10Cookie cookie = new Cookie("CookieName", "CookieValue", "somedomain.com", "/", new Date(new Date().getTime() + 1000), true, true);11driver.manage().addCookie(cookie);12driver.navigate().refresh();13Cookie cookie = new Cookie("CookieName", "CookieValue", "somedomain.com", "/", new Date(new Date().getTime() + 1000), true, true);14driver.manage().addCookie(cookie);15driver.navigate().refresh();16Cookie cookie = new Cookie("CookieName", "CookieValue", "somedomain.com", "/", new Date(new Date().getTime() + 1000), true, true);17driver.manage().addCookie(cookie);18driver.navigate().refresh();19Cookie cookie = new Cookie("CookieName", "CookieValue", "somedomain.com", "/", new Date(new Date().getTime() + 1000), true, true);20driver.manage().addCookie(cookie);21driver.navigate().refresh();22Cookie cookie = new Cookie("CookieName", "CookieValue", "somedomain.com", "/", new Date(new Date().getTime() + 1000), true, true);23driver.manage().addCookie(cookie);24driver.navigate().refresh();25Cookie cookie = new Cookie("CookieName", "CookieValue", "somedomain.com", "/", new Date(new Date().getTime() + 1000

Full Screen

Full Screen

Cookie.Builder

Using AI Code Generation

copy

Full Screen

1Cookie.Builder builder = new Cookie.Builder("name", "value");2builder.domain("domain");3builder.isHttpOnly(true);4builder.isSecure(true);5builder.path("path");6builder.expiresOn(new Date(2017, 12, 31));7Cookie cookie = builder.build();8driver.manage().addCookie(cookie);9Cookie cookie = new Cookie("name", "value", "domain", "path", new Date(2017, 12, 31), true, true);10driver.manage().addCookie(cookie);11Cookie cookie = new Cookie("name", "value", "domain", "path", new Date(2017, 12, 31), true, true);12driver.manage().addCookie(cookie);13Cookie.Builder builder = new Cookie.Builder("name", "value");14builder.domain("domain");15builder.isHttpOnly(true);16builder.isSecure(true);17builder.path("path");18builder.expiresOn(new Date(2017, 12, 31));19Cookie cookie = builder.build();20driver.manage().addCookie(cookie);21Cookie cookie = new Cookie("name", "value", "domain", "path", new Date(2017, 12, 31), true, true);22driver.manage().addCookie(cookie);23Cookie cookie = new Cookie("name", "value", "domain", "path", new Date(2017, 12, 31), true, true);24driver.manage().addCookie(cookie);25Cookie.Builder builder = new Cookie.Builder("name", "value");26builder.domain("domain");27builder.isHttpOnly(true);28builder.isSecure(true);29builder.path("path");30builder.expiresOn(new Date(2017, 12, 31));31Cookie cookie = builder.build();32driver.manage().addCookie(cookie);33Cookie cookie = new Cookie("name", "value", "domain", "path", new Date(2017, 12, 31), true, true);34driver.manage().addCookie(cookie);35Cookie cookie = new Cookie("name", "value",

Full Screen

Full Screen

Cookie.Builder

Using AI Code Generation

copy

Full Screen

1Cookie cookie = new Cookie.Builder("CookieName", "CookieValue")2.domain("www.example.com")3.isHttpOnly(true)4.isSecure(true)5.path("/path")6.expiresOn(Date.from(Instant.now().plus(2, ChronoUnit.HOURS)))7.build();8driver.manage().addCookie(cookie);9Cookie cookie = driver.manage().getCookieNamed("CookieName");10driver.manage().deleteCookie(cookie);11driver.manage().deleteAllCookies();12Set<Cookie> cookies = driver.manage().getCookies();

Full Screen

Full Screen
copy
1Time 1: 953ms, Time 2: 741ms2Time 1: 655ms, Time 2: 743ms3Time 1: 656ms, Time 2: 634ms4Time 1: 637ms, Time 2: 629ms5Time 1: 633ms, Time 2: 625ms6
Full Screen
copy
1public class Bottle {2 public int amountOfWaterMl;3 public int capacityMl;4}5
Full Screen
copy
1int x = 1000 - 5002
Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in Cookie.Builder

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful