How to use add_cookie method in Selenium Requests

Best Python code snippet using Selenium-Requests_python

test_cookies.py

Source:test_cookies.py Github

copy

Full Screen

...18 "secure": False}19 def tearDown(self):20 self.marionette.delete_all_cookies()21 MarionetteTestCase.tearDown(self)22 def test_add_cookie(self):23 self.marionette.add_cookie(self.COOKIE_A)24 cookie_returned = str(self.marionette.execute_script("return document.cookie"))25 self.assertTrue(self.COOKIE_A["name"] in cookie_returned)26 def test_adding_a_cookie_that_expired_in_the_past(self):27 cookie = self.COOKIE_A.copy()28 cookie["expiry"] = calendar.timegm(time.gmtime()) - (60 * 60 * 24)29 self.marionette.add_cookie(cookie)30 cookies = self.marionette.get_cookies()31 self.assertEquals(0, len(cookies))32 def test_chrome_error(self):33 with self.marionette.using_context("chrome"):34 self.assertRaises(UnsupportedOperationException,35 self.marionette.add_cookie, self.COOKIE_A)36 self.assertRaises(UnsupportedOperationException,37 self.marionette.delete_cookie, self.COOKIE_A)38 self.assertRaises(UnsupportedOperationException,39 self.marionette.delete_all_cookies)40 self.assertRaises(UnsupportedOperationException,41 self.marionette.get_cookies)42 def test_delete_all_cookie(self):43 self.marionette.add_cookie(self.COOKIE_A)44 cookie_returned = str(self.marionette.execute_script("return document.cookie"))45 print(cookie_returned)46 self.assertTrue(self.COOKIE_A["name"] in cookie_returned)47 self.marionette.delete_all_cookies()48 self.assertFalse(self.marionette.get_cookies())49 def test_delete_cookie(self):50 self.marionette.add_cookie(self.COOKIE_A)51 cookie_returned = str(self.marionette.execute_script("return document.cookie"))52 self.assertTrue(self.COOKIE_A["name"] in cookie_returned)53 self.marionette.delete_cookie("foo")54 cookie_returned = str(self.marionette.execute_script("return document.cookie"))55 self.assertFalse(self.COOKIE_A["name"] in cookie_returned)56 def test_should_get_cookie_by_name(self):57 key = "key_{}".format(int(random.random()*10000000))58 self.marionette.execute_script("document.cookie = arguments[0] + '=set';", [key])59 cookie = self.marionette.get_cookie(key)60 self.assertEquals("set", cookie["value"])61 def test_get_all_cookies(self):62 key1 = "key_{}".format(int(random.random()*10000000))63 key2 = "key_{}".format(int(random.random()*10000000))64 cookies = self.marionette.get_cookies()65 count = len(cookies)66 one = {"name" :key1,67 "value": "value"}68 two = {"name":key2,69 "value": "value"}70 self.marionette.add_cookie(one)71 self.marionette.add_cookie(two)72 test_url = self.marionette.absolute_url('test.html')73 self.marionette.navigate(test_url)74 cookies = self.marionette.get_cookies()75 self.assertEquals(count + 2, len(cookies))76 def test_should_not_delete_cookies_with_a_similar_name(self):77 cookieOneName = "fish"78 cookie1 = {"name" :cookieOneName,79 "value":"cod"}80 cookie2 = {"name" :cookieOneName + "x",81 "value": "earth"}82 self.marionette.add_cookie(cookie1)83 self.marionette.add_cookie(cookie2)84 self.marionette.delete_cookie(cookieOneName)85 cookies = self.marionette.get_cookies()86 self.assertFalse(cookie1["name"] == cookies[0]["name"], msg=str(cookies))87 self.assertEquals(cookie2["name"] , cookies[0]["name"], msg=str(cookies))88 def test_we_get_required_elements_when_available(self):89 self.marionette.add_cookie(self.COOKIE_A)90 cookies = self.marionette.get_cookies()91 self.assertIn("name", cookies[0], 'name not available')92 self.assertIn("value", cookies[0], 'value not available')...

Full Screen

Full Screen

test_keyword_arguments_cookie.py

Source:test_keyword_arguments_cookie.py Github

copy

Full Screen

...9 self.default_cookie = {'name': 'name', 'value': 'value'}10 def tearDown(self):11 unstub()12 def test_add_cookie_default(self):13 self.cookie.add_cookie('name', 'value')14 verify(self.browser).add_cookie(self.default_cookie)15 def test_add_cookie_secure_true(self):16 self.cookie.add_cookie('name', 'value', path='None', domain='None',17 secure='True')18 cookie = self.default_cookie19 cookie['secure'] = 'True'20 verify(self.browser).add_cookie(cookie)21 def test_add_cookie_secure_false(self):22 self.cookie.add_cookie('name', 'value', path='None', domain='None',23 secure='None')24 verify(self.browser).add_cookie(self.default_cookie)25 def test_add_cookie_domain_true(self):26 self.cookie.add_cookie('name', 'value', path='None', domain='MyDomain',27 secure=None)28 cookie = self.default_cookie29 cookie['domain'] = 'MyDomain'30 verify(self.browser).add_cookie(cookie)31 def test_add_cookie_domain_false(self):32 self.cookie.add_cookie('name', 'value', path='None', domain='False',33 secure=None)34 verify(self.browser).add_cookie(self.default_cookie)35 def test_add_cookie_path_true(self):36 self.cookie.add_cookie('name', 'value', path='/foo/bar', domain=None,37 secure=None)38 cookie = self.default_cookie39 cookie['path'] = '/foo/bar'40 verify(self.browser).add_cookie(cookie)41 def test_add_cookie_path_false(self):42 self.cookie.add_cookie('name', 'value', path='None', domain=None,43 secure=None)...

Full Screen

Full Screen

ProfilePage.py

Source:ProfilePage.py Github

copy

Full Screen

2from web.page_object.page.SelectedPage import SelectedPage3class ProfilePage(BasePage):4 def login(self):5 print(self.driver.get_cookies())6 self.driver.add_cookie({"name": "device_id", "value": "XXXXXXX"})7 self.driver.add_cookie({"name": "Hm_lvt_1db88642e346389874251b5a1eded6e3", "value": "XXXXXXX"})8 self.driver.add_cookie({"name": "snbim_minify", "value": "true"})9 self.driver.add_cookie({"name": "bid", "value": "XXXX"})10 self.driver.add_cookie({"name": "utmcsr", "value": "(direct)|utmccn=(direct)|utmcmd=(none)"})11 self.driver.add_cookie({"name": "xq_is_login", "value": "1"})12 self.driver.add_cookie({"name": "u", "value": "XXXXX"})13 self.driver.add_cookie({"name": "Hm_lpvt_1db88642e346389874251b5a1eded6e3", "value": "XX"})14 self.driver.add_cookie({"name": "Hm_lpvt_1db88642e346389874251b5a1eded6e3", "value": "XX"})15 self.driver.add_cookie({"name": "xq_a_token", "value": "XXXXX"})16 self.driver.add_cookie({"name": "xq_a_token.sig", "value": "XXXXX"})17 self.driver.add_cookie({"name": "xq_r_token", "value": "XXXXxxxxx"})18 self.driver.add_cookie({"name": "xq_r_token.sig", "value": "--pmYDj5gI"})19 self.driver.add_cookie({"name": "xqat", "value": "XXXXXX"})20 print(self.driver.get_cookies())21 self.driver.refresh()22 def gotoSelected(self):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selenium Requests automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful