-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref #6784
- Loading branch information
Showing
4 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |