Skip to content

Instantly share code, notes, and snippets.

@brian-mann
Last active September 2, 2016 04:28
Show Gist options
  • Save brian-mann/fdda0bf0db64039631edf372977194e2 to your computer and use it in GitHub Desktop.
Save brian-mann/fdda0bf0db64039631edf372977194e2 to your computer and use it in GitHub Desktop.
cross domain iframes
<html>
<body>
<h2>iframe</h2>
<script type="text/javascript">
setTimeout(function(){
window._e2e_sessionURL = "http://some/url"
}, 1000)
</script>
</body>
</html>
describe "iframes", ->
it "works", ->
cy
.visit("http://localhost:8000/hash.html")
.readFile("iframe.html")
.then {timeout: 10000}, (html) ->
$iframe = Cypress.$("<iframe />")
$iframe.appendTo(document.body)
win = $iframe.get(0).contentWindow
doc = $iframe.get(0).contentDocument
doc.open()
doc.write(html)
doc.close()
new Cypress.Promise (resolve) ->
check = ->
if url = win._e2e_sessionURL
resolve(url)
else
## poll for the window's property
## every 100ms
setTimeout(check, 100)
check()
.then (url) ->
## url is now "http://some/url"
debugger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment