How to use clear_all_cookies method in SeleniumBase

Best Python code snippet using SeleniumBase

add.py

Source:add.py Github

copy

Full Screen

...17 "name": "hello",18 "value": "world",19 }20 session.url = url("/common/blank.html")21 clear_all_cookies(session)22 response = add_cookie(session, new_cookie)23 value = assert_success(response)24 assert value is None25def test_no_browsing_context(session, closed_window):26 new_cookie = {27 "name": "hello",28 "value": "world",29 }30 response = add_cookie(session, new_cookie)31 assert_error(response, "no such window")32def test_add_domain_cookie(session, url, server_config):33 new_cookie = {34 "name": "hello",35 "value": "world",36 "domain": server_config["browser_host"],37 "path": "/",38 "httpOnly": False,39 "secure": False40 }41 session.url = url("/common/blank.html")42 clear_all_cookies(session)43 result = add_cookie(session, new_cookie)44 assert_success(result)45 cookie = session.cookies("hello")46 assert "domain" in cookie47 assert isinstance(cookie["domain"], text_type)48 assert "name" in cookie49 assert isinstance(cookie["name"], text_type)50 assert "value" in cookie51 assert isinstance(cookie["value"], text_type)52 assert cookie["name"] == "hello"53 assert cookie["value"] == "world"54 assert cookie["domain"] == server_config["browser_host"] or \55 cookie["domain"] == ".%s" % server_config["browser_host"]56def test_add_cookie_for_ip(session, url, server_config, configuration):57 new_cookie = {58 "name": "hello",59 "value": "world",60 "domain": "127.0.0.1",61 "path": "/",62 "httpOnly": False,63 "secure": False64 }65 session.url = "http://127.0.0.1:%s/common/blank.html" % (server_config["ports"]["http"][0])66 clear_all_cookies(session)67 result = add_cookie(session, new_cookie)68 assert_success(result)69 cookie = session.cookies("hello")70 assert "name" in cookie71 assert isinstance(cookie["name"], text_type)72 assert "value" in cookie73 assert isinstance(cookie["value"], text_type)74 assert "domain" in cookie75 assert isinstance(cookie["domain"], text_type)76 assert cookie["name"] == "hello"77 assert cookie["value"] == "world"78 assert cookie["domain"] == "127.0.0.1"79def test_add_non_session_cookie(session, url):80 a_day_from_now = int(81 (datetime.utcnow() + timedelta(days=1) - datetime.utcfromtimestamp(0)).total_seconds())82 new_cookie = {83 "name": "hello",84 "value": "world",85 "expiry": a_day_from_now86 }87 session.url = url("/common/blank.html")88 clear_all_cookies(session)89 result = add_cookie(session, new_cookie)90 assert_success(result)91 cookie = session.cookies("hello")92 assert "name" in cookie93 assert isinstance(cookie["name"], text_type)94 assert "value" in cookie95 assert isinstance(cookie["value"], text_type)96 assert "expiry" in cookie97 assert isinstance(cookie["expiry"], int)98 assert cookie["name"] == "hello"99 assert cookie["value"] == "world"100 assert cookie["expiry"] == a_day_from_now101def test_add_session_cookie(session, url):102 new_cookie = {103 "name": "hello",104 "value": "world"105 }106 session.url = url("/common/blank.html")107 clear_all_cookies(session)108 result = add_cookie(session, new_cookie)109 assert_success(result)110 cookie = session.cookies("hello")111 assert "name" in cookie112 assert isinstance(cookie["name"], text_type)113 assert "value" in cookie114 assert isinstance(cookie["value"], text_type)115 if "expiry" in cookie:116 assert cookie.get("expiry") is None117 assert cookie["name"] == "hello"118 assert cookie["value"] == "world"119def test_add_session_cookie_with_leading_dot_character_in_domain(session, url, server_config):120 new_cookie = {121 "name": "hello",122 "value": "world",123 "domain": ".%s" % server_config["browser_host"]124 }125 session.url = url("/common/blank.html")126 clear_all_cookies(session)127 result = add_cookie(session, new_cookie)128 assert_success(result)129 cookie = session.cookies("hello")130 assert "name" in cookie131 assert isinstance(cookie["name"], text_type)132 assert "value" in cookie133 assert isinstance(cookie["value"], text_type)134 assert "domain" in cookie135 assert isinstance(cookie["domain"], text_type)136 assert cookie["name"] == "hello"137 assert cookie["value"] == "world"138 assert cookie["domain"] == server_config["browser_host"] or \139 cookie["domain"] == ".%s" % server_config["browser_host"]140@pytest.mark.parametrize("same_site", ["None", "Lax", "Strict"])141def test_add_cookie_with_valid_samesite_flag(session, url, same_site):142 new_cookie = {143 "name": "hello",144 "value": "world",145 "sameSite": same_site146 }147 session.url = url("/common/blank.html")148 clear_all_cookies(session)149 result = add_cookie(session, new_cookie)150 assert_success(result)151 cookie = session.cookies("hello")152 assert "name" in cookie153 assert isinstance(cookie["name"], text_type)154 assert "value" in cookie155 assert isinstance(cookie["value"], text_type)156 assert "sameSite" in cookie157 assert isinstance(cookie["sameSite"], text_type)158 assert cookie["name"] == "hello"159 assert cookie["value"] == "world"160 assert cookie["sameSite"] == same_site161def test_add_cookie_with_invalid_samesite_flag(session, url):162 new_cookie = {163 "name": "hello",164 "value": "world",165 "sameSite": "invalid"166 }167 session.url = url("/common/blank.html")168 clear_all_cookies(session)169 response = add_cookie(session, new_cookie)170 assert_error(response, "invalid argument")171@pytest.mark.parametrize("same_site", [False, 12, dict()])172def test_add_cookie_with_invalid_samesite_type(session, url, same_site):173 new_cookie = {174 "name": "hello",175 "value": "world",176 "sameSite": same_site177 }178 session.url = url("/common/blank.html")179 clear_all_cookies(session)180 response = add_cookie(session, new_cookie)...

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 SeleniumBase 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