Skip to content

CORS related tests not possible with Selenium + Python + Chrome/Firefox #6486

@asudhak

Description

@asudhak

Meta -

OS:
OSX

Selenium Version:
1.22 Python

Browser:
Chrome

Browser Version:
69.0.3497.100

Expected Behavior -

  • Login to domain1.com
  • cookies for domain1 are set
  • Open page domain2.com in a new tab
  • domain2 contains a CORS request to domain1
  • domian1 sets correct CORS headers 'Access-Control-Allow-Origin' and 'Access-Control-Allow-Credentials' from domain2
  • domain 2 successfully sets cookies and the CORS request is succesful

This behavior works as expected when manually performing the above steps.

Actual Behavior -

  • Login to domain1.com
  • cookies for domain1 are set
  • Open page domain2.com in a new tab
  • domain2 contains a CORS request to domain1
  • CORS request fails because the cookies for domain1 is not available in the context of domain2 when using selenium

Steps to reproduce -

Its not possible to create a SSCCE for this, so i'm providing a code snippet of what i'm trying to achieve.

` options = webdriver.ChromeOptions()
print url

    browser = webdriver.Chrome(executable_path="./chromedriver")
    
    browser.get("http://127.0.0.1:8080/")
    print browser.title
    browser.find_element_by_name('username').send_keys("admin")
    browser.find_element_by_name("password").send_keys("hunter2")
    browser.find_element_by_tag_name("button").click()
    print browser.get_cookies()
    #shows cookies correctly

    print 'loading cors page: ' + url
    browser.execute_script("window.open('%s');" %url)
    #chrome web console shows that the request failed because it failed to set the cookies`

Metadata

Metadata

Assignees

No one assigned

    Labels

    J-awaiting answerQuestion asked of user; a reply moves it to triage again

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions