Skip to content

Commit 40ba6a3

Browse files
wanghongjuanrogerwang
authored andcommitted
[test] fix test 6229
- Add test for issue nwjs#6229 - This case is failed on failed version 0.26.0, pass on fixed version 0.27.4
1 parent b613212 commit 40ba6a3

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>issue6229-webview-executeScript</title>
6+
</head>
7+
<body>
8+
<webview partition="trusted" class="browser" style="position: fixed;top: 0;left: 0;right: 0;width: 100%;height: 50%;" src=""></webview>
9+
<div style="position: fixed;bottom: 0;left: 0;right: 0;width: 100%;height: 50%;" class="log">
10+
<p>Current behaviour: logs an empty window object to devtools</p>
11+
<p>Expected behaviour: it should log the window object to devtools</p>
12+
<input type="text" name="" value="Object.keys(window)" /><button onclick="exec(document.querySelector('input').value)">Run</button>
13+
</div>
14+
</body>
15+
</html>
16+
17+
18+
<script type="text/javascript">
19+
let wv = document.querySelector('.browser');
20+
wv.addEventListener('contentload', function () {
21+
wv.showDevTools(true)
22+
});
23+
24+
function exec(val) {
25+
wv.executeScript({code: val, mainWorld: true}, function (res) {
26+
document.querySelector('.log').appendChild(document.createTextNode(res))
27+
});
28+
}
29+
setTimeout(function () {
30+
wv.src = 'file://' + global.__dirname + '/site.html';
31+
}, 750)
32+
</script>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "issue6229-webview-executeScript",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.html",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"webview": {
12+
"partitions": [
13+
{
14+
"name": "trusted",
15+
"accessible_resources": [ "<all_urls>" ]
16+
}
17+
]
18+
}
19+
}
20+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
</head>
6+
</html>
7+
8+
9+
<script type="text/javascript">
10+
window.test = 'DEFAULT';
11+
12+
setInterval(function () {
13+
document.querySelector('h1').textContent = window.test;
14+
}, 250);
15+
</script>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import time
2+
import os
3+
import platform
4+
import sys
5+
6+
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
7+
from nw_util import *
8+
9+
from selenium import webdriver
10+
from selenium.webdriver.chrome.options import Options
11+
12+
chrome_options = Options()
13+
testdir = os.path.dirname(os.path.abspath(__file__))
14+
chrome_options.add_argument("nwapp=" + testdir)
15+
16+
driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options)
17+
driver.implicitly_wait(2)
18+
try:
19+
print driver.current_url
20+
print 'wait for devtools open'
21+
wait_window_handles(driver,2)
22+
handles = driver.window_handles
23+
print handles
24+
driver.switch_to_window(handles[0])
25+
print 'click button to execute code'
26+
driver.find_element_by_tag_name('button').click()
27+
print 'get all keys in window'
28+
result = driver.find_element_by_class_name('log').get_attribute('innerText')
29+
assert('postMessage' in result)
30+
finally:
31+
driver.quit()

0 commit comments

Comments
 (0)