Skip to content

Commit f0457d0

Browse files
committed
[test] fix race condition in issue5781-X-Frame-Options
1 parent 58d3df6 commit f0457d0

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

test/sanity/issue5781-X-Frame-Options/index.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<html>
22
<body>
3-
<iframe src="http://localhost:{port}" nwfaketop ></iframe>
3+
<iframe src="http://localhost:{port}" nwfaketop id="iframe_a"></iframe>
44
<script>
55
document.write('<h1 id="res1">Node is ' + (typeof nw === 'undefined' ? 'DISABLED': 'ENABLED') + '</h1>');
66
</script>

test/sanity/issue5781-X-Frame-Options/test.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,29 @@
2626
html.write(content)
2727
html.close()
2828

29-
driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options)
29+
driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options, service_log_path="log", service_args=["--verbose"])
3030
driver.implicitly_wait(5)
3131
try:
3232
print driver.current_url
3333
print 'loading http server in iframe element'
34-
wait_for_element_tag(driver, "iframe")
35-
assert(driver.find_element_by_tag_name("iframe") is not None)
36-
driver.switch_to_frame(driver.find_element_by_tag_name("iframe"))
37-
res2 = wait_for_element_id(driver, 'res2')
38-
assert( "Node is DISABLED" in res2)
34+
wait_for_element_id(driver, "iframe_a")
35+
driver.switch_to_frame("iframe_a")
36+
ret = ''
37+
timeout = 10
38+
while timeout > 0:
39+
try:
40+
ret = driver.find_element_by_id('res2').get_attribute('innerHTML')
41+
break
42+
except selenium.common.exceptions.NoSuchElementException:
43+
driver.switch_to_default_content()
44+
driver.switch_to_frame("iframe_a")
45+
except selenium.common.exceptions.WebDriverException:
46+
pass
47+
time.sleep(1)
48+
timeout = timeout - 1
49+
if timeout <= 0:
50+
raise Exception('Timeout when waiting for element res2')
51+
assert( "Node is DISABLED" in ret)
3952
print 'page iframe is loaded'
4053
finally:
4154
server.terminate()

0 commit comments

Comments
 (0)