Skip to content

Instantly share code, notes, and snippets.

@toumorokoshi
Created July 9, 2014 23:09
Show Gist options
  • Save toumorokoshi/de04b83a8cd29db0e99d to your computer and use it in GitHub Desktop.
Save toumorokoshi/de04b83a8cd29db0e99d to your computer and use it in GitHub Desktop.
Selenium bad cookie example for old IE browsers
from selenium import webdriver
import requests
import multiprocessing
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
REMOTE_URL = "http://USERNAME:CODE@ondemand.saucelabs.com:4444/wd/hub"
OS = ['XP', '7', '8', '8.1']
IE = ['6', '7', '8', '9', '10', '11']
URLS = [
'http://www.google.com',
'http://www.zillow.com',
'http://www.yahoo.com',
'http://www.amazon.com',
'http://www.saucelabs.com',
'http://www.github.com',
'http://www.microsoft.com'
]
def main():
pool = multiprocessing.Pool(processes=10) # spawn a bunch of worker threads
pool.map(test_cookies, URLS) #pass each worker thread a function with a given input
def test_cookies(website): #the function that is being worked on
output = 'Testing {0}...\n'.format(website)
for os in OS: #this could be multiprocessed, but fractal threading is generally a bad idea
for ie in IE:
try:
desired_capabilities = DesiredCapabilities.INTERNETEXPLORER
desired_capabilities['platform'] = "Windows " + os
desired_capabilities['version'] = ie
driver = webdriver.Remote(
command_executor=REMOTE_URL,
desired_capabilities=desired_capabilities
)
driver.get(website)
dummy_cookie = {
'name': 'yusuke',
'value': 'yusuke',
'path': '/',
'secure': False
}
try:
driver.add_cookie(dummy_cookie)
output += ("PASSED with Windows " + os + " and IE " + ie + "\n")
except Exception:
output += ("FAILED with Windows " + os + " and IE " + ie + "\n")
driver
driver.quit()
except Exception:
pass
print output
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment