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

Blogs

Check out the latest blogs from LambdaTest on this topic:

Nightwatch.js Tutorial For Test Automation – Complete Guide With Examples

Being an open-source framework allowed Selenium to be compatible with multiple test automation frameworks for different programming languages and if we talk about Automation testing with Selenium and JavaScript, there is a particular framework that never fails to take the spotlight and that is the Nightwatch.js. This is why I decided to come up with Nightwatch.js tutorial for beginners.

How To Execute JavaScript In Selenium PHP?

There are cases where test scenarios may fail unexpectedly with Selenium commands (e.g., click operation on the button web element does not result in a click even though the button is enabled). Such issues are more pertinent when creating an XHR request or when attempting to access another frame. For overcoming such issues, you can execute JavaScript in Selenium through the JavaScriptExecutor interface.

Nightwatch Vs Protractor: Which Testing Framework Is Right For You?

Do you know the test automation market is all set to hit $35 billion by 2026? And when it comes to cross browser testing, JavaScript leads from the front? Javascript is probably the best alternative for Selenium automation, considering its protocol transformation to the W3C standard. In order to make the most of it, the first step is to choose the best test automation frameworks. Among all the JavaScript testing frameworks, two frameworks are most popular- Nightwatch and Protractor.

The Top 52 Selenium Open Source Projects On GitHub

Selenium, a project hosted by the Apache Software Foundation, is an umbrella open-source project comprising a variety of tools and libraries for test automation. Selenium automation framework enables QA engineers to perform automated web application testing using popular programming languages like Python, Java, JavaScript, C#, Ruby, and PHP.

Complete Guide To Selenium Testing with GitHub Actions

CI/CD pipelines are here to stay and contribute tremendously to continuous integration and delivery across all global projects. This article will be a guide to configure, set up builds and tests with “GitHub Actions”, primarily using Selenium WebDriver. This article shall also cover some of the most generic GitHub Actions examples, and user flows.

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