Skip to content

Commit

Permalink
[test] add issue6784-webview
Browse files Browse the repository at this point in the history
Ref #6784
  • Loading branch information
rogerwang committed Dec 30, 2019
1 parent e5dbe51 commit d6408db
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/sanity/issue6784-webview/1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>title of 1.html</title>
<script>window.name="webview1"</script>
</head>
<body>
<h1 id='result'>success</h1>
</body>
</html>
14 changes: 14 additions & 0 deletions test/sanity/issue6784-webview/index.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<webview src="http://localhost:{port}/1.html" partition="persist:trusted"></webview>
</body>
</html>




16 changes: 16 additions & 0 deletions test/sanity/issue6784-webview/package.json.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "wvtest",
"version": "1.0.0",
"license": "MIT",
"description": "",
"main": "http://127.0.0.1:{port}",
"webview": {
"partitions": [
{
"name": "trusted*",
"accessible_resources": ["*"]
}
]
},
"node-remote": "<all_urls>"
}
60 changes: 60 additions & 0 deletions test/sanity/issue6784-webview/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import time
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from nw_util import *

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common import utils

chrome_options = Options()
chrome_options.add_argument("nwapp=" + os.path.dirname(os.path.abspath(__file__)))
chrome_options.add_experimental_option("windowTypes", ["webview"])

testdir = os.path.dirname(os.path.abspath(__file__))
os.chdir(testdir)

port_n = utils.free_port()
port = str(port_n)
server = subprocess.Popen(['python', '../http-server-node.py', port])

tpl = open('index.tpl', 'r')
content = tpl.read().replace('{port}', port)
tpl.close()

html = open('index.html', 'w')
html.write(content)
html.close()

tpl = open('package.json.tpl', 'r')
content = tpl.read().replace('{port}', port)
tpl.close()

html = open('package.json', 'w')
html.write(content)
html.close()

if not wait_net_service("127.0.0.1", port_n, 30):
import platform
if platform.system() == 'Windows':
subprocess.call(['taskkill', '/F', '/T', '/PID', str(server.pid)])
else:
server.terminate()
raise Exception('Timeout when waiting for http server')

driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options, service_log_path="log", service_args=["--verbose"])
driver.implicitly_wait(5)
try:
print driver.current_url
wait_switch_window_name(driver, 'webview1')
result = driver.find_element_by_id('result').get_attribute('innerHTML')
print result
assert('success' in result)
finally:
driver.quit()
import platform
if platform.system() == 'Windows':
subprocess.call(['taskkill', '/F', '/T', '/PID', str(server.pid)])
else:
server.terminate()

0 comments on commit d6408db

Please sign in to comment.